mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2024-12-23 01:59:40 +08:00
Fix CSConsole not re-selecting properly after Escape is pressed
This commit is contained in:
parent
03661cdd0b
commit
b9a3ab7439
@ -18,6 +18,7 @@ using UniverseLib.UI;
|
||||
using UniverseLib;
|
||||
using UniverseLib.UI.Models;
|
||||
using UniverseLib.Utility;
|
||||
using HarmonyLib;
|
||||
|
||||
namespace UnityExplorer.CSConsole
|
||||
{
|
||||
@ -383,30 +384,59 @@ namespace UnityExplorer.CSConsole
|
||||
RuntimeHelper.StartCoroutine(SetCaretCoroutine(caretPosition));
|
||||
}
|
||||
|
||||
internal static PropertyInfo SelectionGuardProperty => selectionGuardPropInfo ?? GetSelectionGuardPropInfo();
|
||||
internal static MemberInfo selectionGuardMemberInfo;
|
||||
|
||||
private static PropertyInfo GetSelectionGuardPropInfo()
|
||||
internal static MemberInfo GetSelectionGuardMemberInfo()
|
||||
{
|
||||
selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_SelectionGuard");
|
||||
if (selectionGuardPropInfo == null)
|
||||
selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_selectionGuard");
|
||||
return selectionGuardPropInfo;
|
||||
if (selectionGuardMemberInfo != null)
|
||||
return selectionGuardMemberInfo;
|
||||
|
||||
if (AccessTools.Property(typeof(EventSystem), "m_SelectionGuard") is PropertyInfo pi_m_SelectionGuard)
|
||||
return selectionGuardMemberInfo = pi_m_SelectionGuard;
|
||||
|
||||
if (AccessTools.Property(typeof(EventSystem), "m_selectionGuard") is PropertyInfo pi_m_selectionGuard)
|
||||
return selectionGuardMemberInfo = pi_m_selectionGuard;
|
||||
|
||||
if (AccessTools.Field(typeof(EventSystem), "m_SelectionGuard") is FieldInfo fi_m_SelectionGuard)
|
||||
return selectionGuardMemberInfo = fi_m_SelectionGuard;
|
||||
|
||||
return selectionGuardMemberInfo = AccessTools.Field(typeof(EventSystem), "m_selectionGuard");
|
||||
}
|
||||
|
||||
private static PropertyInfo selectionGuardPropInfo;
|
||||
internal static void SetSelectionGuard(EventSystem instance, bool value)
|
||||
{
|
||||
var member = GetSelectionGuardMemberInfo();
|
||||
if (member == null)
|
||||
return;
|
||||
if (member is PropertyInfo pi)
|
||||
{
|
||||
pi.SetValue(instance, value, null);
|
||||
return;
|
||||
}
|
||||
var fi = member as FieldInfo;
|
||||
fi.SetValue(instance, value);
|
||||
}
|
||||
|
||||
private static IEnumerator SetCaretCoroutine(int caretPosition)
|
||||
{
|
||||
var color = Input.Component.selectionColor;
|
||||
color.a = 0f;
|
||||
Input.Component.selectionColor = color;
|
||||
try { EventSystem.current.SetSelectedGameObject(null, null); } catch { }
|
||||
yield return null;
|
||||
|
||||
try { SelectionGuardProperty.SetValue(EventSystem.current, false, null); } catch { }
|
||||
try { EventSystem.current.SetSelectedGameObject(Input.UIRoot, null); } catch { }
|
||||
try { CursorUnlocker.CurrentEventSystem.m_CurrentSelected = null; }
|
||||
catch (Exception ex) { ExplorerCore.Log($"Failed removing selected object: {ex}"); }
|
||||
|
||||
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
|
||||
|
||||
try { SetSelectionGuard(CursorUnlocker.CurrentEventSystem, false); }
|
||||
catch (Exception ex) { ExplorerCore.Log($"Failed setting selection guard: {ex}"); }
|
||||
|
||||
try { CursorUnlocker.CurrentEventSystem.SetSelectedGameObject(Input.GameObject, null); }
|
||||
catch (Exception ex) { ExplorerCore.Log($"Failed setting selected gameobject: {ex}"); }
|
||||
|
||||
yield return null; // ~~~~~~~ YIELD FRAME ~~~~~~~~~
|
||||
|
||||
Input.Component.Select();
|
||||
yield return null;
|
||||
|
||||
Input.Component.caretPosition = caretPosition;
|
||||
Input.Component.selectionFocusPosition = caretPosition;
|
||||
|
@ -175,13 +175,13 @@
|
||||
<Private>False</Private>
|
||||
</Reference>
|
||||
<Reference Include="UniverseLib.Mono">
|
||||
<HintPath>packages\UniverseLib.1.2.4\lib\net35\UniverseLib.Mono.dll</HintPath>
|
||||
<HintPath>packages\UniverseLib.1.2.5\lib\net35\UniverseLib.Mono.dll</HintPath>
|
||||
</Reference>
|
||||
</ItemGroup>
|
||||
<!-- Il2Cpp refs -->
|
||||
<ItemGroup Condition="'$(IsCpp)'=='true'">
|
||||
<Reference Include="UniverseLib.IL2CPP">
|
||||
<HintPath>packages\UniverseLib.1.2.4\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
||||
<HintPath>packages\UniverseLib.1.2.5\lib\net472\UniverseLib.IL2CPP.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="UnhollowerBaseLib, Version=0.4.22.0, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>packages\Il2CppAssemblyUnhollower.BaseLib.0.4.22\lib\net472\UnhollowerBaseLib.dll</HintPath>
|
||||
|
@ -6,6 +6,6 @@
|
||||
<package id="ILRepack.Lib.MSBuild.Task" version="2.0.18.2" targetFramework="net35" />
|
||||
<package id="Mono.Cecil" version="0.10.4" targetFramework="net35" />
|
||||
<package id="Samboy063.Tomlet" version="3.1.3" targetFramework="net472" />
|
||||
<package id="UniverseLib" version="1.2.4" targetFramework="net35" />
|
||||
<package id="UniverseLib" version="1.2.5" targetFramework="net35" />
|
||||
<package id="UniverseLib.Analyzers" version="1.0.3" targetFramework="net35" developmentDependency="true" />
|
||||
</packages>
|
Loading…
Reference in New Issue
Block a user