2026-03-31 15:18:50 +08:00
|
|
|
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;
|
2026-04-13 15:45:34 +08:00
|
|
|
#if !UX_NAVIGATION
|
|
|
|
|
interactable = false;
|
|
|
|
|
enabled = false;
|
|
|
|
|
return;
|
|
|
|
|
#endif
|
2026-03-31 15:18:50 +08:00
|
|
|
recyclerView = GetComponent<RecyclerView>();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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)
|
|
|
|
|
{
|
2026-04-13 15:45:34 +08:00
|
|
|
#if UX_NAVIGATION
|
2026-03-31 15:18:50 +08:00
|
|
|
recyclerView ??= GetComponent<RecyclerView>();
|
|
|
|
|
return recyclerView != null && recyclerView.TryFocusEntry(direction);
|
2026-04-13 15:45:34 +08:00
|
|
|
#else
|
|
|
|
|
return false;
|
|
|
|
|
#endif
|
2026-03-31 15:18:50 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|