Compare commits

..

No commits in common. "6f897a7af730cdd3a47e02496e69e8609b79b8ce" and "00a7eff5f84c992b08a52ff2c0a955e13e7a7587" have entirely different histories.

3 changed files with 23 additions and 87 deletions

View File

@ -33,12 +33,10 @@ namespace UnityEngine.UI
{
Holder = holder;
HierarchyDepth = GetHierarchyDepth(holder.transform);
ParentHolder = FindParentHolder(holder);
BlocksLowerScopes = ParentHolder == null;
BlocksLowerScopes = FindParentHolder(holder) == null;
}
public readonly UIHolderObjectBase Holder;
public readonly UIHolderObjectBase ParentHolder;
public readonly int HierarchyDepth;
public readonly bool BlocksLowerScopes;
public readonly Dictionary<string, List<HotkeyRegistration>> RegistrationsByAction = new(StringComparer.Ordinal);
@ -426,30 +424,28 @@ namespace UnityEngine.UI
[MethodImpl(MethodImplOptions.AggressiveInlining)]
private static void Dispatch(string actionId, EHotkeyPressType pressType)
{
HotkeyScope leafScope = GetTopLeafScope();
if (leafScope == null)
HotkeyScope[] leafScopes = GetLeafScopes();
if (leafScopes.Length == 0)
{
return;
}
TryDispatchToScopeChain(leafScope, actionId, pressType);
TryDispatchToScopeChain(leafScopes[0], actionId, pressType);
}
private static bool TryDispatchToScopeChain(HotkeyScope leafScope, string actionId, EHotkeyPressType pressType)
{
HotkeyScope current = leafScope;
while (current != null)
UIHolderObjectBase currentHolder = leafScope.Holder;
while (currentHolder != null)
{
if (TryGetLatestRegistration(current, actionId, pressType, out var registration))
if (_scopes.TryGetValue(currentHolder, out var scope)
&& TryGetLatestRegistration(scope, actionId, pressType, out var registration))
{
registration.Trigger?.HotkeyActionTrigger();
return true;
}
UIHolderObjectBase parentHolder = current.ParentHolder;
current = parentHolder != null && _scopes.TryGetValue(parentHolder, out var parentScope)
? parentScope
: null;
currentHolder = FindParentHolder(currentHolder);
}
return false;
@ -474,7 +470,7 @@ namespace UnityEngine.UI
return false;
}
private static HotkeyScope GetTopLeafScope()
private static HotkeyScope[] GetLeafScopes()
{
_leafScopes.Clear();
_ancestorHolders.Clear();
@ -490,18 +486,11 @@ namespace UnityEngine.UI
continue;
}
UIHolderObjectBase parentHolder = scope.ParentHolder;
UIHolderObjectBase parentHolder = FindParentHolder(scope.Holder);
while (parentHolder != null)
{
_ancestorHolders.Add(parentHolder);
if (_scopes.TryGetValue(parentHolder, out var parentScope))
{
parentHolder = parentScope.ParentHolder;
}
else
{
break;
}
parentHolder = FindParentHolder(parentHolder);
}
}
@ -517,13 +506,8 @@ namespace UnityEngine.UI
}
}
if (_leafScopes.Count == 0)
{
return null;
}
_leafScopes.Sort(CompareScopePriority);
return _leafScopes[0];
return _leafScopes.ToArray();
}
private static bool IsScopeActive(HotkeyScope scope)

View File

@ -23,9 +23,6 @@ namespace UnityEngine.UI
private ulong _activationSerial;
private bool _missingEventSystemLogged;
private bool _topScopeDirty = true;
private bool _suppressionDirty = true;
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
private static void Bootstrap()
{
@ -104,8 +101,6 @@ namespace UnityEngine.UI
}
_scopes.Add(scope);
_topScopeDirty = true;
_suppressionDirty = true;
}
internal void UnregisterScope(UXNavigationScope scope)
@ -122,17 +117,7 @@ namespace UnityEngine.UI
scope.IsAvailable = false;
scope.SetNavigationSuppressed(false);
int idx = _scopes.IndexOf(scope);
if (idx >= 0)
{
int last = _scopes.Count - 1;
_scopes[idx] = _scopes[last];
_scopes.RemoveAt(last);
}
_topScopeDirty = true;
_suppressionDirty = true;
_scopes.Remove(scope);
}
internal void MarkDiscoveryDirty()
@ -153,22 +138,13 @@ namespace UnityEngine.UI
DiscoverScopes();
}
if (_topScopeDirty)
{
UXNavigationScope newTopScope = FindTopScope();
_topScopeDirty = false;
if (!ReferenceEquals(_topScope, newTopScope))
{
_topScope = newTopScope;
_suppressionDirty = true;
}
}
if (_suppressionDirty)
{
ApplyScopeSuppression();
_suppressionDirty = false;
}
if (UXInputModeService.CurrentMode == UXInputMode.Gamepad)
{
@ -261,9 +237,6 @@ namespace UnityEngine.UI
{
_scopes[i]?.InvalidateSelectableCache();
}
_topScopeDirty = true;
_suppressionDirty = true;
}
}
@ -302,8 +275,6 @@ namespace UnityEngine.UI
{
scope.ActivationSerial = ++_activationSerial;
}
_suppressionDirty = true;
}
if (!available)
@ -333,13 +304,11 @@ namespace UnityEngine.UI
return false;
}
return !scope.IsNavigationSkipped
return !IsNavigationSkipped(scope.transform)
&& scope.HasAvailableSelectable()
&& TryGetInteractiveLayerRoot(scope.transform, out _);
}
// 保留静态方法用于 DiscoverScopes 中对 LayerRoot / Holder 节点的检测
// 这些节点无 UXNavigationScope调用频次低仅在 dirty 时),无需缓存
private static bool IsNavigationSkipped(Transform current)
{
return current != null && current.GetComponentInParent<UXNavigationSkip>(true) != null;

View File

@ -33,9 +33,6 @@ namespace UnityEngine.UI
private bool _navigationSuppressed;
private int _cachedHierarchyDepth = -1;
private bool _cachedIsSkipped;
private bool _isSkippedCacheValid;
internal ulong ActivationSerial { get; set; }
internal bool IsAvailable { get; set; }
internal bool WasAvailable { get; set; }
@ -50,19 +47,6 @@ namespace UnityEngine.UI
public bool RequireSelectionWhenGamepad => _requireSelectionWhenGamepad;
public bool BlockLowerScopes => _blockLowerScopes;
internal bool IsNavigationSkipped
{
get
{
if (!_isSkippedCacheValid)
{
_cachedIsSkipped = GetComponentInParent<UXNavigationSkip>(true) != null;
_isSkippedCacheValid = true;
}
return _cachedIsSkipped;
}
}
internal Canvas Canvas
{
get
@ -124,7 +108,6 @@ namespace UnityEngine.UI
_cachedCanvas = null;
_cachedHolder = null;
_cachedHierarchyDepth = -1;
_isSkippedCacheValid = false;
}
#if UNITY_EDITOR
@ -236,12 +219,12 @@ namespace UnityEngine.UI
internal void SetNavigationSuppressed(bool suppressed)
{
RefreshSelectableCache();
if (_navigationSuppressed == suppressed)
{
return;
}
RefreshSelectableCache();
_navigationSuppressed = suppressed;
for (int i = 0; i < _cachedSelectables.Count; i++)
{
@ -298,11 +281,11 @@ namespace UnityEngine.UI
}
_removeBuffer.Clear();
foreach (Selectable key in _baselineNavigation.Keys)
foreach (var pair in _baselineNavigation)
{
if (!_cachedSelectableSet.Contains(key))
if (!_cachedSelectableSet.Contains(pair.Key))
{
_removeBuffer.Add(key);
_removeBuffer.Add(pair.Key);
}
}