using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; public class SetButtonNavigation : MonoBehaviour { UIGenericButton[] genericButtons; UISettingItemFiller[] listSettingItems; private void Start() { listSettingItems = GetComponentsInChildren(); genericButtons = GetComponentsInChildren(); MultiInputButton buttonToSelectOnDown = default; MultiInputButton buttonToSelectOnUp = default; for (int i = 0; i < listSettingItems.Length; i++) { Navigation newNavigation = new Navigation(); newNavigation.mode = Navigation.Mode.Explicit; newNavigation.selectOnLeft = listSettingItems[i].gameObject.GetComponent().navigation.selectOnLeft; newNavigation.selectOnRight = listSettingItems[i].gameObject.GetComponent().navigation.selectOnRight; if (i + 1 < listSettingItems.Length) { buttonToSelectOnDown = listSettingItems[i + 1].gameObject.GetComponent(); } else if (genericButtons.Length > 0) { buttonToSelectOnDown = genericButtons[0].gameObject.GetComponent(); SetGenericButtonsNavigations(listSettingItems[i].gameObject.GetComponent()); } if (i - 1 >= 0) buttonToSelectOnUp = listSettingItems[i - 1].gameObject.GetComponent(); newNavigation.selectOnDown = buttonToSelectOnDown; newNavigation.selectOnUp = buttonToSelectOnUp; listSettingItems[i].gameObject.GetComponent().navigation = newNavigation; listSettingItems[i].SetNavigation(buttonToSelectOnDown, buttonToSelectOnUp); } } private void OnEnable() { if (listSettingItems == null) { listSettingItems = GetComponentsInChildren(); } if (listSettingItems.Length > 0) if (listSettingItems[0].GetComponent() != null) //select first item listSettingItems[0].GetComponent().Select(); } void SetGenericButtonsNavigations(MultiInputButton itemUp) { for (int i = 0; i < genericButtons.Length; i++) { Navigation newNavigation = new Navigation(); newNavigation.mode = Navigation.Mode.Explicit; if (i + 1 < genericButtons.Length) newNavigation.selectOnRight = genericButtons[i + 1].gameObject.GetComponent(); if (i - 1 > 0) newNavigation.selectOnLeft = genericButtons[i - 1].gameObject.GetComponent(); newNavigation.selectOnUp = itemUp; } } }