using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.UI; using UnityEngine.Events; using UnityEngine.EventSystems; using TMPro; namespace Michsky.UI.Heat { public class Dropdown : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler { // Resources public GameObject triggerObject; public TextMeshProUGUI headerText; public Image headerImage; public Transform itemParent; [SerializeField] private GameObject itemPreset; public Scrollbar scrollbar; public VerticalLayoutGroup itemList; [SerializeField] private CanvasGroup highlightCG; public CanvasGroup contentCG; [SerializeField] private CanvasGroup listCG; [SerializeField] private RectTransform listRect; // Settings public bool isInteractable = true; public bool enableIcon = true; public bool enableTrigger = true; public bool enableScrollbar = true; [SerializeField] private bool startAtBottom = false; public bool setHighPriority = true; public bool updateOnEnable = true; public bool outOnPointerExit = false; public bool invokeOnEnable = false; public bool initOnEnable = true; public bool useSounds = true; [Range(1, 15)] public float fadingMultiplier = 8; [Range(1, 50)] public int itemPaddingTop = 8; [Range(1, 50)] public int itemPaddingBottom = 8; [Range(1, 50)] public int itemPaddingLeft = 8; [Range(1, 50)] public int itemPaddingRight = 25; [Range(1, 50)] public int itemSpacing = 8; public int selectedItemIndex = 0; // UI Navigation public bool useUINavigation = false; public Navigation.Mode navigationMode = Navigation.Mode.Automatic; public GameObject selectOnUp; public GameObject selectOnDown; public GameObject selectOnLeft; public GameObject selectOnRight; public bool wrapAround = false; // Animation public PanelDirection panelDirection; [Range(25, 1000)] public float panelSize = 200; [Range(0.5f, 10)] public float curveSpeed = 2; public AnimationCurve animationCurve = new AnimationCurve(new Keyframe(0.0f, 0.0f), new Keyframe(1.0f, 1.0f)); // Saving public bool saveSelected = false; public string saveKey = "My Dropdown"; // Item list [SerializeField] public List items = new List(); // Events [System.Serializable] public class DropdownEvent : UnityEvent { } public DropdownEvent onValueChanged; // Helpers [HideInInspector] public bool isOn; [HideInInspector] public int index = 0; [HideInInspector] public int siblingIndex = 0; EventTrigger triggerEvent; Button targetButton; public enum PanelDirection { Bottom, Top } [System.Serializable] public class Item { public string itemName = "Dropdown Item"; public string localizationKey; public Sprite itemIcon; [HideInInspector] public int itemIndex; [HideInInspector] public bool isInvisible = false; [HideInInspector] public ButtonManager itemButton; public UnityEvent onItemSelection = new UnityEvent(); } void Awake() { if (initOnEnable) { Initialize(); } if (useUINavigation) { AddUINavigation(); } if (enableTrigger && triggerObject != null) { // triggerButton = gameObject.GetComponent