diff --git a/Runtime/InputGlyph/Core/InputDeviceWatcher.cs b/Runtime/InputGlyph/Core/InputDeviceWatcher.cs index d5911aa..8c7487d 100644 --- a/Runtime/InputGlyph/Core/InputDeviceWatcher.cs +++ b/Runtime/InputGlyph/Core/InputDeviceWatcher.cs @@ -1,8 +1,5 @@ using System; using System.Collections.Generic; -#if UNITY_EDITOR -using UnityEditor; -#endif using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.InputSystem.Controls; @@ -127,17 +124,17 @@ public static class InputDeviceWatcher InputSystem.onDeviceChange += OnDeviceChange; #if UNITY_EDITOR - EditorApplication.playModeStateChanged += OnPlayModeStateChanged; + UnityEditor.EditorApplication.playModeStateChanged += OnPlayModeStateChanged; #endif } #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(); - EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; + UnityEditor.EditorApplication.playModeStateChanged -= OnPlayModeStateChanged; } } #endif diff --git a/Runtime/RecyclerView/Adapter/ItemRender.cs b/Runtime/RecyclerView/Adapter/ItemRender.cs index bf77b1d..0ad9996 100644 --- a/Runtime/RecyclerView/Adapter/ItemRender.cs +++ b/Runtime/RecyclerView/Adapter/ItemRender.cs @@ -464,7 +464,11 @@ namespace AlicizaX.UI /// 成功移动焦点时返回 ;否则返回 private bool MoveFocus(MoveDirection direction) { +#if UX_NAVIGATION return RecyclerView != null && RecyclerView.NavigationController.TryMove(Holder, direction, NavigationOptions); +#else + return false; +#endif } /// diff --git a/Runtime/RecyclerView/Interaction/ItemInteractionProxy.cs b/Runtime/RecyclerView/Interaction/ItemInteractionProxy.cs index e519a7f..98235cc 100644 --- a/Runtime/RecyclerView/Interaction/ItemInteractionProxy.cs +++ b/Runtime/RecyclerView/Interaction/ItemInteractionProxy.cs @@ -9,14 +9,19 @@ namespace AlicizaX.UI IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, +#if UX_NAVIGATION ISelectHandler, IDeselectHandler, IMoveHandler, +#endif IBeginDragHandler, IDragHandler, - IEndDragHandler, + IEndDragHandler +#if UX_NAVIGATION + , ISubmitHandler, ICancelHandler +#endif { private IItemInteractionHost host; private ItemInteractionFlags flags; @@ -100,26 +105,32 @@ namespace AlicizaX.UI public void OnSelect(BaseEventData eventData) { +#if UX_NAVIGATION if ((flags & ItemInteractionFlags.Select) != 0) { host?.HandleSelect(eventData); } +#endif } public void OnDeselect(BaseEventData eventData) { +#if UX_NAVIGATION if ((flags & ItemInteractionFlags.Deselect) != 0) { host?.HandleDeselect(eventData); } +#endif } public void OnMove(AxisEventData eventData) { +#if UX_NAVIGATION if ((flags & ItemInteractionFlags.Move) != 0) { host?.HandleMove(eventData); } +#endif } public void OnBeginDrag(PointerEventData eventData) @@ -157,18 +168,22 @@ namespace AlicizaX.UI public void OnSubmit(BaseEventData eventData) { +#if UX_NAVIGATION if ((flags & ItemInteractionFlags.Submit) != 0) { host?.HandleSubmit(eventData); } +#endif } public void OnCancel(BaseEventData eventData) { +#if UX_NAVIGATION if ((flags & ItemInteractionFlags.Cancel) != 0) { host?.HandleCancel(eventData); } +#endif } private void EnsureFocusAnchor() @@ -179,11 +194,18 @@ namespace AlicizaX.UI } focusAnchor = GetComponent(); +#if !UX_NAVIGATION + if (focusAnchor is RecyclerItemSelectable) + { + focusAnchor = null; + } +#endif if (focusAnchor != null) { return; } +#if UX_NAVIGATION ownedSelectable = GetComponent(); if (ownedSelectable == null) { @@ -191,6 +213,7 @@ namespace AlicizaX.UI } focusAnchor = ownedSelectable; +#endif } private bool TryGetFocusableSelectable(out Selectable selectable) @@ -211,6 +234,12 @@ namespace AlicizaX.UI continue; } +#if !UX_NAVIGATION + if (candidate is RecyclerItemSelectable) + { + continue; + } +#endif if (IsSelectableFocusable(candidate)) { selectable = candidate; @@ -231,6 +260,9 @@ namespace AlicizaX.UI private static bool RequiresSelection(ItemInteractionFlags interactionFlags) { +#if !UX_NAVIGATION + return false; +#else const ItemInteractionFlags selectionFlags = ItemInteractionFlags.Select | ItemInteractionFlags.Deselect | @@ -239,6 +271,7 @@ namespace AlicizaX.UI ItemInteractionFlags.Cancel; return (interactionFlags & selectionFlags) != 0; +#endif } [System.Diagnostics.Conditional("INPUTSYSTEM_SUPPORT")] diff --git a/Runtime/RecyclerView/Interaction/RecyclerItemSelectable.cs b/Runtime/RecyclerView/Interaction/RecyclerItemSelectable.cs index 7ef7d49..944f3dc 100644 --- a/Runtime/RecyclerView/Interaction/RecyclerItemSelectable.cs +++ b/Runtime/RecyclerView/Interaction/RecyclerItemSelectable.cs @@ -12,6 +12,10 @@ namespace AlicizaX.UI Navigation disabledNavigation = navigation; disabledNavigation.mode = Navigation.Mode.None; navigation = disabledNavigation; +#if !UX_NAVIGATION + interactable = false; + enabled = false; +#endif } public override void OnMove(AxisEventData eventData) diff --git a/Runtime/RecyclerView/Navigation/RecyclerNavigationBridge.cs b/Runtime/RecyclerView/Navigation/RecyclerNavigationBridge.cs index ae8a02e..edf65ee 100644 --- a/Runtime/RecyclerView/Navigation/RecyclerNavigationBridge.cs +++ b/Runtime/RecyclerView/Navigation/RecyclerNavigationBridge.cs @@ -18,6 +18,11 @@ namespace AlicizaX.UI Navigation navigationConfig = navigation; navigationConfig.mode = Navigation.Mode.None; navigation = navigationConfig; +#if !UX_NAVIGATION + interactable = false; + enabled = false; + return; +#endif recyclerView = GetComponent(); } @@ -42,8 +47,12 @@ namespace AlicizaX.UI private bool TryEnter(MoveDirection direction) { +#if UX_NAVIGATION recyclerView ??= GetComponent(); return recyclerView != null && recyclerView.TryFocusEntry(direction); +#else + return false; +#endif } } } diff --git a/Runtime/RecyclerView/Navigation/RecyclerNavigationController.cs b/Runtime/RecyclerView/Navigation/RecyclerNavigationController.cs index fb83ca7..9d29318 100644 --- a/Runtime/RecyclerView/Navigation/RecyclerNavigationController.cs +++ b/Runtime/RecyclerView/Navigation/RecyclerNavigationController.cs @@ -14,6 +14,9 @@ namespace AlicizaX.UI public bool TryMove(ViewHolder currentHolder, MoveDirection direction, RecyclerNavigationOptions options) { +#if !UX_NAVIGATION + return false; +#else if (recyclerView == null || recyclerView.RecyclerViewAdapter == null || currentHolder == null) @@ -67,6 +70,7 @@ namespace AlicizaX.UI recyclerView.TryFocusIndex(originalIndex, false, alignment); return false; +#endif } private int GetStep(MoveDirection direction) diff --git a/Runtime/RecyclerView/RecyclerView.cs b/Runtime/RecyclerView/RecyclerView.cs index f65812d..71592a1 100644 --- a/Runtime/RecyclerView/RecyclerView.cs +++ b/Runtime/RecyclerView/RecyclerView.cs @@ -487,10 +487,12 @@ namespace AlicizaX.UI /// private void EnsureNavigationBridge() { +#if UX_NAVIGATION if (GetComponent() == null) { gameObject.AddComponent(); } +#endif } /// diff --git a/Runtime/UXComponent/Button/UXButton.cs b/Runtime/UXComponent/Button/UXButton.cs index 9d17d0d..dc99195 100644 --- a/Runtime/UXComponent/Button/UXButton.cs +++ b/Runtime/UXComponent/Button/UXButton.cs @@ -34,6 +34,13 @@ namespace UnityEngine.UI PlayAudio(clickAudioClip); } + public override void OnSelect(BaseEventData eventData) + { + base.OnSelect(eventData); + if (eventData is PointerEventData) + return; + PlayAudio(hoverAudioClip); + } public virtual void OnSubmit(BaseEventData eventData) { diff --git a/Runtime/UXComponent/Group/UXToggle.cs b/Runtime/UXComponent/Group/UXToggle.cs index 15c42c2..268118b 100644 --- a/Runtime/UXComponent/Group/UXToggle.cs +++ b/Runtime/UXComponent/Group/UXToggle.cs @@ -227,6 +227,14 @@ namespace UnityEngine.UI PlayAudio(clickAudioClip); } + public override void OnSelect(BaseEventData eventData) + { + base.OnSelect(eventData); + if (eventData is PointerEventData) + return; + PlayAudio(hoverAudioClip); + } + public virtual void OnSubmit(BaseEventData eventData) { InternalToggle();