50 lines
1.4 KiB
C#
50 lines
1.4 KiB
C#
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;
|
|
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)
|
|
{
|
|
recyclerView ??= GetComponent<RecyclerView>();
|
|
return recyclerView != null && recyclerView.TryFocusEntry(direction);
|
|
}
|
|
}
|
|
}
|