mirror of
https://github.com/sinai-dev/UnityExplorer.git
synced 2025-06-16 22:27:45 +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.Core.Input;
|
||||||
using UnityExplorer.UI.Panels;
|
using UnityExplorer.UI.Panels;
|
||||||
using UnityExplorer.UI.Widgets.AutoComplete;
|
using UnityExplorer.UI.Widgets.AutoComplete;
|
||||||
|
using System.Reflection;
|
||||||
|
|
||||||
namespace UnityExplorer.UI.CSConsole
|
namespace UnityExplorer.UI.CSConsole
|
||||||
{
|
{
|
||||||
@ -328,15 +329,28 @@ namespace UnityExplorer.UI.CSConsole
|
|||||||
RuntimeProvider.Instance.StartCoroutine(SetAutocompleteCaretCoro(caretPosition));
|
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)
|
private static IEnumerator SetAutocompleteCaretCoro(int caretPosition)
|
||||||
{
|
{
|
||||||
var color = Input.Component.selectionColor;
|
var color = Input.Component.selectionColor;
|
||||||
color.a = 0f;
|
color.a = 0f;
|
||||||
Input.Component.selectionColor = color;
|
Input.Component.selectionColor = color;
|
||||||
EventSystem.current.SetSelectedGameObject(null, null);
|
try { EventSystem.current.SetSelectedGameObject(null, null); } catch { }
|
||||||
yield return null;
|
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();
|
Input.Component.Select();
|
||||||
yield return null;
|
yield return null;
|
||||||
|
|
||||||
|
@ -16,8 +16,11 @@ namespace UnityExplorer.UI
|
|||||||
{
|
{
|
||||||
if (inputsPendingUpdate.Any())
|
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);
|
LayoutRebuilder.MarkLayoutForRebuild(entry.Rect);
|
||||||
entry.OnValueChanged?.Invoke(entry.Component.text);
|
entry.OnValueChanged?.Invoke(entry.Component.text);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user