using System; using System.Collections; using UnityEngine; using UnityEngine.EventSystems; using UnityEngine.UI; namespace LapinerTools.uMyGUI { public class uMyGUI_Dropdown : MonoBehaviour { [SerializeField] private Button m_button; [SerializeField] private Text m_text; [SerializeField] private RectTransform m_entriesRoot; [SerializeField] private RectTransform m_entriesBG; [SerializeField] private Scrollbar m_entriesScrollbar; [SerializeField] private Button m_entryButton; [SerializeField] private int m_entrySpacing = 5; [SerializeField] private string m_staticText = string.Empty; [SerializeField] private string m_nothingSelectedText = string.Empty; [SerializeField] protected bool m_improveNavigationFocus = true; [SerializeField] private string[] m_entries = new string[0]; [SerializeField] private int m_selectedIndex = -1; public string[] Entries { get { return m_entries; } set { m_entries = value; HideEntries(); } } public int SelectedIndex { get { return m_selectedIndex; } set { m_selectedIndex = Mathf.Clamp(value, -1, m_entries.Length - 1); } } public event Action OnSelected; public void Select(int p_selectedIndex) { int num = Mathf.Clamp(p_selectedIndex, -1, m_entries.Length - 1); bool flag = num != m_selectedIndex; m_selectedIndex = num; UpdateText(); if (flag && this.OnSelected != null) { this.OnSelected(m_selectedIndex); } } private void Start() { if (m_text != null) { UpdateText(); } else { Debug.LogError("uMyGUI_Dropdown: m_text must be set in the inspector!"); } if (m_button != null) { m_button.onClick.AddListener(OnClick); } else { Debug.LogError("uMyGUI_Dropdown: m_button must be set in the inspector!"); } if (m_entriesRoot != null && m_entriesBG != null) { HideEntries(); } else { Debug.LogError("uMyGUI_Dropdown: m_entriesRoot and m_entriesBG must be set in the inspector!"); } } private void LateUpdate() { if (!m_improveNavigationFocus) { return; } EventSystem current = EventSystem.current; if (!(current != null) || (!(current.currentSelectedGameObject == null) && current.currentSelectedGameObject.activeInHierarchy)) { return; } if (current.lastSelectedGameObject != null && current.lastSelectedGameObject.activeInHierarchy) { current.SetSelectedGameObject(current.lastSelectedGameObject); } else if (m_entriesRoot != null) { if (m_entriesRoot.gameObject.activeSelf && m_entriesRoot.childCount > 0 && m_entriesRoot.GetChild(0).GetComponentInChildren