mirror of
https://github.com/GrahamKracker/UnityExplorer.git
synced 2025-01-09 18:48:46 +08:00
Prevent some niche exceptions with EventSystem
This commit is contained in:
parent
383c6f19e8
commit
9f0f7f9b57
@ -11,6 +11,7 @@ using UnityExplorer.UI.CSConsole;
|
||||
using UnityExplorer.Core.Input;
|
||||
using UnityExplorer.UI.Panels;
|
||||
using UnityExplorer.UI.Widgets.AutoComplete;
|
||||
using System.Reflection;
|
||||
|
||||
namespace UnityExplorer.UI.CSConsole
|
||||
{
|
||||
@ -328,15 +329,28 @@ namespace UnityExplorer.UI.CSConsole
|
||||
RuntimeProvider.Instance.StartCoroutine(SetAutocompleteCaretCoro(caretPosition));
|
||||
}
|
||||
|
||||
internal static PropertyInfo SelectionGuardProperty => selectionGuardPropInfo ?? GetSelectionGuardPropInfo();
|
||||
|
||||
private static PropertyInfo GetSelectionGuardPropInfo()
|
||||
{
|
||||
selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_SelectionGuard");
|
||||
if (selectionGuardPropInfo == null)
|
||||
selectionGuardPropInfo = typeof(EventSystem).GetProperty("m_selectionGuard");
|
||||
return selectionGuardPropInfo;
|
||||
}
|
||||
|
||||
private static PropertyInfo selectionGuardPropInfo;
|
||||
|
||||
private static IEnumerator SetAutocompleteCaretCoro(int caretPosition)
|
||||
{
|
||||
var color = Input.Component.selectionColor;
|
||||
color.a = 0f;
|
||||
Input.Component.selectionColor = color;
|
||||
EventSystem.current.SetSelectedGameObject(null, null);
|
||||
try { EventSystem.current.SetSelectedGameObject(null, null); } catch { }
|
||||
yield return null;
|
||||
|
||||
EventSystem.current.SetSelectedGameObject(Input.UIRoot, null);
|
||||
try { SelectionGuardProperty.SetValue(EventSystem.current, false, null); } catch { }
|
||||
try { EventSystem.current.SetSelectedGameObject(Input.UIRoot, null); } catch { }
|
||||
Input.Component.Select();
|
||||
yield return null;
|
||||
|
||||
|
@ -16,8 +16,11 @@ namespace UnityExplorer.UI
|
||||
{
|
||||
if (inputsPendingUpdate.Any())
|
||||
{
|
||||
foreach (var entry in inputsPendingUpdate)
|
||||
var array = inputsPendingUpdate.ToArray();
|
||||
|
||||
for (int i = array.Length - 1; i >= 0; i--)
|
||||
{
|
||||
var entry = array[i];
|
||||
LayoutRebuilder.MarkLayoutForRebuild(entry.Rect);
|
||||
entry.OnValueChanged?.Invoke(entry.Component.text);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user