Update UXHotkeyRegisterManager.cs
This commit is contained in:
parent
00a7eff5f8
commit
52eaadb67d
@ -33,10 +33,12 @@ namespace UnityEngine.UI
|
||||
{
|
||||
Holder = holder;
|
||||
HierarchyDepth = GetHierarchyDepth(holder.transform);
|
||||
BlocksLowerScopes = FindParentHolder(holder) == null;
|
||||
ParentHolder = FindParentHolder(holder);
|
||||
BlocksLowerScopes = ParentHolder == 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);
|
||||
@ -424,28 +426,30 @@ namespace UnityEngine.UI
|
||||
[MethodImpl(MethodImplOptions.AggressiveInlining)]
|
||||
private static void Dispatch(string actionId, EHotkeyPressType pressType)
|
||||
{
|
||||
HotkeyScope[] leafScopes = GetLeafScopes();
|
||||
if (leafScopes.Length == 0)
|
||||
HotkeyScope leafScope = GetTopLeafScope();
|
||||
if (leafScope == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
TryDispatchToScopeChain(leafScopes[0], actionId, pressType);
|
||||
TryDispatchToScopeChain(leafScope, actionId, pressType);
|
||||
}
|
||||
|
||||
private static bool TryDispatchToScopeChain(HotkeyScope leafScope, string actionId, EHotkeyPressType pressType)
|
||||
{
|
||||
UIHolderObjectBase currentHolder = leafScope.Holder;
|
||||
while (currentHolder != null)
|
||||
HotkeyScope current = leafScope;
|
||||
while (current != null)
|
||||
{
|
||||
if (_scopes.TryGetValue(currentHolder, out var scope)
|
||||
&& TryGetLatestRegistration(scope, actionId, pressType, out var registration))
|
||||
if (TryGetLatestRegistration(current, actionId, pressType, out var registration))
|
||||
{
|
||||
registration.Trigger?.HotkeyActionTrigger();
|
||||
return true;
|
||||
}
|
||||
|
||||
currentHolder = FindParentHolder(currentHolder);
|
||||
UIHolderObjectBase parentHolder = current.ParentHolder;
|
||||
current = parentHolder != null && _scopes.TryGetValue(parentHolder, out var parentScope)
|
||||
? parentScope
|
||||
: null;
|
||||
}
|
||||
|
||||
return false;
|
||||
@ -470,7 +474,7 @@ namespace UnityEngine.UI
|
||||
return false;
|
||||
}
|
||||
|
||||
private static HotkeyScope[] GetLeafScopes()
|
||||
private static HotkeyScope GetTopLeafScope()
|
||||
{
|
||||
_leafScopes.Clear();
|
||||
_ancestorHolders.Clear();
|
||||
@ -486,11 +490,18 @@ namespace UnityEngine.UI
|
||||
continue;
|
||||
}
|
||||
|
||||
UIHolderObjectBase parentHolder = FindParentHolder(scope.Holder);
|
||||
UIHolderObjectBase parentHolder = scope.ParentHolder;
|
||||
while (parentHolder != null)
|
||||
{
|
||||
_ancestorHolders.Add(parentHolder);
|
||||
parentHolder = FindParentHolder(parentHolder);
|
||||
if (_scopes.TryGetValue(parentHolder, out var parentScope))
|
||||
{
|
||||
parentHolder = parentScope.ParentHolder;
|
||||
}
|
||||
else
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -506,8 +517,13 @@ namespace UnityEngine.UI
|
||||
}
|
||||
}
|
||||
|
||||
if (_leafScopes.Count == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
_leafScopes.Sort(CompareScopePriority);
|
||||
return _leafScopes.ToArray();
|
||||
return _leafScopes[0];
|
||||
}
|
||||
|
||||
private static bool IsScopeActive(HotkeyScope scope)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user