using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace AlicizaX.UI { [DisallowMultipleComponent] public sealed class RecyclerNavigationBridge : Selectable, ISelectHandler, IMoveHandler, ISubmitHandler { [SerializeField] private MoveDirection defaultEntryDirection = MoveDirection.Down; private RecyclerView recyclerView; protected override void Awake() { base.Awake(); transition = Transition.None; Navigation navigationConfig = navigation; navigationConfig.mode = Navigation.Mode.None; navigation = navigationConfig; #if !UX_NAVIGATION interactable = false; enabled = false; return; #endif recyclerView = GetComponent(); } public override void OnSelect(BaseEventData eventData) { base.OnSelect(eventData); TryEnter(defaultEntryDirection); } public override void OnMove(AxisEventData eventData) { if (!TryEnter(eventData.moveDir)) { base.OnMove(eventData); } } public void OnSubmit(BaseEventData eventData) { TryEnter(defaultEntryDirection); } private bool TryEnter(MoveDirection direction) { #if UX_NAVIGATION recyclerView ??= GetComponent(); return recyclerView != null && recyclerView.TryFocusEntry(direction); #else return false; #endif } } }