45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using NaughtyAttributes;
|
|
public class VerticalButtonNavigation : MonoBehaviour
|
|
{
|
|
[SerializeField] private bool isCharacterSelectionButton = false;
|
|
[SerializeField, ShowIf(nameof(isCharacterSelectionButton))] private Selectable playButton;
|
|
|
|
private Selectable selectable;
|
|
private Navigation selectableNav;
|
|
|
|
private void Awake()
|
|
{
|
|
selectable = GetComponent<Selectable>();
|
|
selectableNav = selectable.navigation;
|
|
|
|
SetNavigation();
|
|
}
|
|
|
|
private void SetNavigation()
|
|
{
|
|
selectableNav.mode = Navigation.Mode.Explicit;
|
|
|
|
int index = transform.GetSiblingIndex();
|
|
int lastIndex = transform.parent.childCount - 1;
|
|
|
|
if (index != 0)
|
|
{
|
|
selectableNav.selectOnUp = transform.parent.GetChild(index - 1).GetComponent<Selectable>();
|
|
}
|
|
if(index != lastIndex)
|
|
{
|
|
selectableNav.selectOnDown = transform.parent.GetChild(index + 1).GetComponent<Selectable>();
|
|
}
|
|
|
|
selectableNav.selectOnLeft = null;
|
|
selectableNav.selectOnRight = isCharacterSelectionButton ? playButton : null;
|
|
|
|
selectable.navigation = selectableNav;
|
|
|
|
}
|
|
}
|