优化
This commit is contained in:
parent
bc66728a65
commit
6bf99f313c
@ -11,7 +11,6 @@ namespace UnityEngine.UI
|
||||
private static UXNavigationRuntime _instance;
|
||||
private static readonly string CacheLayerName = $"Layer{(int)UILayer.All}-{UILayer.All}";
|
||||
|
||||
private const float DiscoveryInterval = 0.5f;
|
||||
private readonly HashSet<UXNavigationScope> _scopeSet = new();
|
||||
private readonly List<UXNavigationScope> _scopes = new(32);
|
||||
private readonly HashSet<Transform> _interactiveLayerRoots = new();
|
||||
@ -20,7 +19,6 @@ namespace UnityEngine.UI
|
||||
private Transform _uiCanvasRoot;
|
||||
private UXNavigationScope _topScope;
|
||||
private GameObject _lastObservedSelection;
|
||||
private float _nextDiscoveryTime;
|
||||
private bool _discoveryDirty = true;
|
||||
private ulong _activationSerial;
|
||||
private bool _missingEventSystemLogged;
|
||||
@ -103,7 +101,6 @@ namespace UnityEngine.UI
|
||||
}
|
||||
|
||||
_scopes.Add(scope);
|
||||
MarkDiscoveryDirty();
|
||||
}
|
||||
|
||||
internal void UnregisterScope(UXNavigationScope scope)
|
||||
@ -121,7 +118,6 @@ namespace UnityEngine.UI
|
||||
scope.IsAvailable = false;
|
||||
scope.SetNavigationSuppressed(false);
|
||||
_scopes.Remove(scope);
|
||||
MarkDiscoveryDirty();
|
||||
}
|
||||
|
||||
internal void MarkDiscoveryDirty()
|
||||
@ -137,7 +133,7 @@ namespace UnityEngine.UI
|
||||
return;
|
||||
}
|
||||
|
||||
if (_discoveryDirty || Time.unscaledTime >= _nextDiscoveryTime)
|
||||
if (_discoveryDirty)
|
||||
{
|
||||
DiscoverScopes();
|
||||
}
|
||||
@ -176,6 +172,7 @@ namespace UnityEngine.UI
|
||||
}
|
||||
|
||||
_uiCanvasRoot = uiModule.UICanvasRoot;
|
||||
EnsureWatcher(_uiCanvasRoot);
|
||||
CacheInteractiveLayers();
|
||||
DiscoverScopes();
|
||||
}
|
||||
@ -188,6 +185,7 @@ namespace UnityEngine.UI
|
||||
return;
|
||||
}
|
||||
|
||||
EnsureWatcher(_uiCanvasRoot);
|
||||
for (int i = 0; i < _uiCanvasRoot.childCount; i++)
|
||||
{
|
||||
Transform child = _uiCanvasRoot.GetChild(i);
|
||||
@ -197,18 +195,13 @@ namespace UnityEngine.UI
|
||||
}
|
||||
|
||||
_interactiveLayerRoots.Add(child);
|
||||
if (child.GetComponent<UXNavigationLayerWatcher>() == null)
|
||||
{
|
||||
var watcher = child.gameObject.AddComponent<UXNavigationLayerWatcher>();
|
||||
watcher.Initialize(this);
|
||||
}
|
||||
EnsureWatcher(child);
|
||||
}
|
||||
}
|
||||
|
||||
private void DiscoverScopes()
|
||||
{
|
||||
_discoveryDirty = false;
|
||||
_nextDiscoveryTime = Time.unscaledTime + DiscoveryInterval;
|
||||
CacheInteractiveLayers();
|
||||
bool addedScope = false;
|
||||
|
||||
@ -247,6 +240,21 @@ namespace UnityEngine.UI
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureWatcher(Transform target)
|
||||
{
|
||||
if (target == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!target.TryGetComponent(out UXNavigationLayerWatcher watcher))
|
||||
{
|
||||
watcher = target.gameObject.AddComponent<UXNavigationLayerWatcher>();
|
||||
}
|
||||
|
||||
watcher.Initialize(this);
|
||||
}
|
||||
|
||||
private UXNavigationScope FindTopScope()
|
||||
{
|
||||
UXNavigationScope bestScope = null;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user