增加Navigation Skip

This commit is contained in:
陈思海 2026-03-20 19:40:12 +08:00
parent a3afd178bd
commit f6cb7dde18
4 changed files with 53 additions and 3 deletions

View File

@ -211,7 +211,7 @@ namespace UnityEngine.UI
foreach (Transform layerRoot in _interactiveLayerRoots)
{
if (layerRoot == null)
if (layerRoot == null || IsNavigationSkipped(layerRoot))
{
continue;
}
@ -220,7 +220,9 @@ namespace UnityEngine.UI
for (int i = 0; i < holders.Length; i++)
{
UIHolderObjectBase holder = holders[i];
if (holder == null || holder.GetComponent<UXNavigationScope>() != null)
if (holder == null
|| holder.GetComponent<UXNavigationScope>() != null
|| IsNavigationSkipped(holder.transform))
{
continue;
}
@ -287,7 +289,14 @@ namespace UnityEngine.UI
return false;
}
return TryGetInteractiveLayerRoot(scope.transform, out _);
return !IsNavigationSkipped(scope.transform)
&& scope.HasAvailableSelectable()
&& TryGetInteractiveLayerRoot(scope.transform, out _);
}
private static bool IsNavigationSkipped(Transform current)
{
return current != null && current.GetComponentInParent<UXNavigationSkip>(true) != null;
}
private bool TryGetInteractiveLayerRoot(Transform current, out Transform layerRoot)

View File

@ -160,6 +160,26 @@ namespace UnityEngine.UI
return null;
}
internal bool HasAvailableSelectable()
{
RefreshSelectableCache();
if (IsSelectableValid(_defaultSelectable))
{
return true;
}
for (int i = 0; i < _cachedSelectables.Count; i++)
{
if (IsSelectableValid(_cachedSelectables[i]))
{
return true;
}
}
return false;
}
internal void RecordSelection(GameObject selectedObject)
{
if (!_rememberLastSelection || selectedObject == null)

View File

@ -0,0 +1,10 @@
#if INPUTSYSTEM_SUPPORT
namespace UnityEngine.UI
{
[DisallowMultipleComponent]
[AddComponentMenu("UI/UX Navigation Skip")]
public sealed class UXNavigationSkip : MonoBehaviour
{
}
}
#endif

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 4d9f2572962f46368405e4b5abf32d2a
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: