using System; using System.Collections; using System.Collections.Generic; using System.Linq; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; using static Convention.ProjectContextLabelAttribute; namespace Convention.WindowsUI { public class ModernUIDropdown : WindowUIModule, IActionInvoke, ITitle { // Resources [Resources, OnlyNotNullMode] public GameObject triggerObject; [Resources, OnlyNotNullMode] public Transform itemParent; [Resources, OnlyNotNullMode] public GameObject itemPrefab; [Resources, OnlyNotNullMode] public GameObject scrollbar; private VerticalLayoutGroup itemList; private Transform currentListParent; [Resources, WhenAttribute.Is(nameof(isListItem), true)] public Transform listParent; private Animator dropdownAnimator; [Resources, OnlyNotNullMode] public TextMeshProUGUI m_Title; private Button m_RawButton; // Settings [Setting] public bool enableTrigger = true; [Setting] public bool enableScrollbar = true; [Setting] public bool setHighPriorty = true; [Setting] public bool outOnPointerExit = false; [Setting] public bool isListItem = false; [Setting] public AnimationType animationType = AnimationType.FADING; [Setting] public UnityEvent OnSelect = new(); [Setting] public bool isMutiSelect = false; // Items [Content] public List dropdownItems = new(); // Other variables bool isOn; [Content] public int siblingIndex = 0; private bool m_interactable = true; public bool interactable { get => m_interactable; set { if (m_interactable != value) { m_interactable = value; RefreshImmediate(); } } } public string title { get => m_Title.text; set => m_Title.text = value; } public enum AnimationType { None, FADING, SLIDING, STYLISH } [System.Serializable] public class Item { public string itemName = "Dropdown Item"; [HideInInspector] private Toggle m_ToggleItem; public Toggle ToggleItem { get => m_ToggleItem; set { if (m_ToggleItem != value) { m_ToggleItem = value; if (m_ToggleItem != null) m_ToggleItem.isOn = lazy_isOn; lazy_isOn = false; } } } public UnityEvent toggleEvents = new(); private bool lazy_isOn = false; public bool isOn { get => ToggleItem == null ? lazy_isOn : ToggleItem.isOn; set { if (ToggleItem == null) lazy_isOn = value; else ToggleItem.SetIsOnWithoutNotify(value); } } } private void Reset() { triggerObject = transform.Find("Trigger").gameObject; } [Resources] public RectTransform ResizeBroadcastRect; public IEnumerator ResizeBroadcast() { if (ResizeBroadcastRect == null) yield break; for (int i = 0; i < 60; i++) { RectTransformExtension.AdjustSizeToContainsChilds(ResizeBroadcastRect); yield return null; } } private void Start() { m_RawButton = GetComponent