ClientServer/Client/Assets/Scripts/UI/VerticalButtonNavigation.cs
TG9six 03a642d635 first push
first push
2025-09-06 17:17:39 +04:00

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;
}
}