This commit is contained in:
陈思海 2026-04-13 15:45:34 +08:00
parent 43e6a6ba83
commit ab0bc3bcf9
9 changed files with 76 additions and 8 deletions

View File

@ -1,8 +1,5 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
#if UNITY_EDITOR
using UnityEditor;
#endif
using UnityEngine; using UnityEngine;
using UnityEngine.InputSystem; using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls; using UnityEngine.InputSystem.Controls;
@ -127,17 +124,17 @@ public static class InputDeviceWatcher
InputSystem.onDeviceChange += OnDeviceChange; InputSystem.onDeviceChange += OnDeviceChange;
#if UNITY_EDITOR #if UNITY_EDITOR
EditorApplication.playModeStateChanged += OnPlayModeStateChanged; UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged;
#endif #endif
} }
#if UNITY_EDITOR #if UNITY_EDITOR
private static void OnPlayModeStateChanged(PlayModeStateChange state) private static void OnPlayModeStateChanged(UnityEditor.PlayModeStateChange state)
{ {
if (state == PlayModeStateChange.ExitingPlayMode) if (state == UnityEditor.PlayModeStateChange.ExitingPlayMode)
{ {
Dispose(); Dispose();
EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; UnityEditor.EditorApplication.playModeStateChanged -= OnPlayModeStateChanged;
} }
} }
#endif #endif

View File

@ -464,7 +464,11 @@ namespace AlicizaX.UI
/// <returns>成功移动焦点时返回 <see langword="true"/>;否则返回 <see langword="false"/>。</returns> /// <returns>成功移动焦点时返回 <see langword="true"/>;否则返回 <see langword="false"/>。</returns>
private bool MoveFocus(MoveDirection direction) private bool MoveFocus(MoveDirection direction)
{ {
#if UX_NAVIGATION
return RecyclerView != null && RecyclerView.NavigationController.TryMove(Holder, direction, NavigationOptions); return RecyclerView != null && RecyclerView.NavigationController.TryMove(Holder, direction, NavigationOptions);
#else
return false;
#endif
} }
/// <summary> /// <summary>

View File

@ -9,14 +9,19 @@ namespace AlicizaX.UI
IPointerClickHandler, IPointerClickHandler,
IPointerEnterHandler, IPointerEnterHandler,
IPointerExitHandler, IPointerExitHandler,
#if UX_NAVIGATION
ISelectHandler, ISelectHandler,
IDeselectHandler, IDeselectHandler,
IMoveHandler, IMoveHandler,
#endif
IBeginDragHandler, IBeginDragHandler,
IDragHandler, IDragHandler,
IEndDragHandler, IEndDragHandler
#if UX_NAVIGATION
,
ISubmitHandler, ISubmitHandler,
ICancelHandler ICancelHandler
#endif
{ {
private IItemInteractionHost host; private IItemInteractionHost host;
private ItemInteractionFlags flags; private ItemInteractionFlags flags;
@ -100,26 +105,32 @@ namespace AlicizaX.UI
public void OnSelect(BaseEventData eventData) public void OnSelect(BaseEventData eventData)
{ {
#if UX_NAVIGATION
if ((flags & ItemInteractionFlags.Select) != 0) if ((flags & ItemInteractionFlags.Select) != 0)
{ {
host?.HandleSelect(eventData); host?.HandleSelect(eventData);
} }
#endif
} }
public void OnDeselect(BaseEventData eventData) public void OnDeselect(BaseEventData eventData)
{ {
#if UX_NAVIGATION
if ((flags & ItemInteractionFlags.Deselect) != 0) if ((flags & ItemInteractionFlags.Deselect) != 0)
{ {
host?.HandleDeselect(eventData); host?.HandleDeselect(eventData);
} }
#endif
} }
public void OnMove(AxisEventData eventData) public void OnMove(AxisEventData eventData)
{ {
#if UX_NAVIGATION
if ((flags & ItemInteractionFlags.Move) != 0) if ((flags & ItemInteractionFlags.Move) != 0)
{ {
host?.HandleMove(eventData); host?.HandleMove(eventData);
} }
#endif
} }
public void OnBeginDrag(PointerEventData eventData) public void OnBeginDrag(PointerEventData eventData)
@ -157,18 +168,22 @@ namespace AlicizaX.UI
public void OnSubmit(BaseEventData eventData) public void OnSubmit(BaseEventData eventData)
{ {
#if UX_NAVIGATION
if ((flags & ItemInteractionFlags.Submit) != 0) if ((flags & ItemInteractionFlags.Submit) != 0)
{ {
host?.HandleSubmit(eventData); host?.HandleSubmit(eventData);
} }
#endif
} }
public void OnCancel(BaseEventData eventData) public void OnCancel(BaseEventData eventData)
{ {
#if UX_NAVIGATION
if ((flags & ItemInteractionFlags.Cancel) != 0) if ((flags & ItemInteractionFlags.Cancel) != 0)
{ {
host?.HandleCancel(eventData); host?.HandleCancel(eventData);
} }
#endif
} }
private void EnsureFocusAnchor() private void EnsureFocusAnchor()
@ -179,11 +194,18 @@ namespace AlicizaX.UI
} }
focusAnchor = GetComponent<Selectable>(); focusAnchor = GetComponent<Selectable>();
#if !UX_NAVIGATION
if (focusAnchor is RecyclerItemSelectable)
{
focusAnchor = null;
}
#endif
if (focusAnchor != null) if (focusAnchor != null)
{ {
return; return;
} }
#if UX_NAVIGATION
ownedSelectable = GetComponent<RecyclerItemSelectable>(); ownedSelectable = GetComponent<RecyclerItemSelectable>();
if (ownedSelectable == null) if (ownedSelectable == null)
{ {
@ -191,6 +213,7 @@ namespace AlicizaX.UI
} }
focusAnchor = ownedSelectable; focusAnchor = ownedSelectable;
#endif
} }
private bool TryGetFocusableSelectable(out Selectable selectable) private bool TryGetFocusableSelectable(out Selectable selectable)
@ -211,6 +234,12 @@ namespace AlicizaX.UI
continue; continue;
} }
#if !UX_NAVIGATION
if (candidate is RecyclerItemSelectable)
{
continue;
}
#endif
if (IsSelectableFocusable(candidate)) if (IsSelectableFocusable(candidate))
{ {
selectable = candidate; selectable = candidate;
@ -231,6 +260,9 @@ namespace AlicizaX.UI
private static bool RequiresSelection(ItemInteractionFlags interactionFlags) private static bool RequiresSelection(ItemInteractionFlags interactionFlags)
{ {
#if !UX_NAVIGATION
return false;
#else
const ItemInteractionFlags selectionFlags = const ItemInteractionFlags selectionFlags =
ItemInteractionFlags.Select | ItemInteractionFlags.Select |
ItemInteractionFlags.Deselect | ItemInteractionFlags.Deselect |
@ -239,6 +271,7 @@ namespace AlicizaX.UI
ItemInteractionFlags.Cancel; ItemInteractionFlags.Cancel;
return (interactionFlags & selectionFlags) != 0; return (interactionFlags & selectionFlags) != 0;
#endif
} }
[System.Diagnostics.Conditional("INPUTSYSTEM_SUPPORT")] [System.Diagnostics.Conditional("INPUTSYSTEM_SUPPORT")]

View File

@ -12,6 +12,10 @@ namespace AlicizaX.UI
Navigation disabledNavigation = navigation; Navigation disabledNavigation = navigation;
disabledNavigation.mode = Navigation.Mode.None; disabledNavigation.mode = Navigation.Mode.None;
navigation = disabledNavigation; navigation = disabledNavigation;
#if !UX_NAVIGATION
interactable = false;
enabled = false;
#endif
} }
public override void OnMove(AxisEventData eventData) public override void OnMove(AxisEventData eventData)

View File

@ -18,6 +18,11 @@ namespace AlicizaX.UI
Navigation navigationConfig = navigation; Navigation navigationConfig = navigation;
navigationConfig.mode = Navigation.Mode.None; navigationConfig.mode = Navigation.Mode.None;
navigation = navigationConfig; navigation = navigationConfig;
#if !UX_NAVIGATION
interactable = false;
enabled = false;
return;
#endif
recyclerView = GetComponent<RecyclerView>(); recyclerView = GetComponent<RecyclerView>();
} }
@ -42,8 +47,12 @@ namespace AlicizaX.UI
private bool TryEnter(MoveDirection direction) private bool TryEnter(MoveDirection direction)
{ {
#if UX_NAVIGATION
recyclerView ??= GetComponent<RecyclerView>(); recyclerView ??= GetComponent<RecyclerView>();
return recyclerView != null && recyclerView.TryFocusEntry(direction); return recyclerView != null && recyclerView.TryFocusEntry(direction);
#else
return false;
#endif
} }
} }
} }

View File

@ -14,6 +14,9 @@ namespace AlicizaX.UI
public bool TryMove(ViewHolder currentHolder, MoveDirection direction, RecyclerNavigationOptions options) public bool TryMove(ViewHolder currentHolder, MoveDirection direction, RecyclerNavigationOptions options)
{ {
#if !UX_NAVIGATION
return false;
#else
if (recyclerView == null || if (recyclerView == null ||
recyclerView.RecyclerViewAdapter == null || recyclerView.RecyclerViewAdapter == null ||
currentHolder == null) currentHolder == null)
@ -67,6 +70,7 @@ namespace AlicizaX.UI
recyclerView.TryFocusIndex(originalIndex, false, alignment); recyclerView.TryFocusIndex(originalIndex, false, alignment);
return false; return false;
#endif
} }
private int GetStep(MoveDirection direction) private int GetStep(MoveDirection direction)

View File

@ -487,10 +487,12 @@ namespace AlicizaX.UI
/// </summary> /// </summary>
private void EnsureNavigationBridge() private void EnsureNavigationBridge()
{ {
#if UX_NAVIGATION
if (GetComponent<RecyclerNavigationBridge>() == null) if (GetComponent<RecyclerNavigationBridge>() == null)
{ {
gameObject.AddComponent<RecyclerNavigationBridge>(); gameObject.AddComponent<RecyclerNavigationBridge>();
} }
#endif
} }
/// <summary> /// <summary>

View File

@ -34,6 +34,13 @@ namespace UnityEngine.UI
PlayAudio(clickAudioClip); PlayAudio(clickAudioClip);
} }
public override void OnSelect(BaseEventData eventData)
{
base.OnSelect(eventData);
if (eventData is PointerEventData)
return;
PlayAudio(hoverAudioClip);
}
public virtual void OnSubmit(BaseEventData eventData) public virtual void OnSubmit(BaseEventData eventData)
{ {

View File

@ -227,6 +227,14 @@ namespace UnityEngine.UI
PlayAudio(clickAudioClip); PlayAudio(clickAudioClip);
} }
public override void OnSelect(BaseEventData eventData)
{
base.OnSelect(eventData);
if (eventData is PointerEventData)
return;
PlayAudio(hoverAudioClip);
}
public virtual void OnSubmit(BaseEventData eventData) public virtual void OnSubmit(BaseEventData eventData)
{ {
InternalToggle(); InternalToggle();