using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; using TMPro; namespace Michsky.UI.Heat { [ExecuteInEditMode] [DisallowMultipleComponent] [RequireComponent(typeof(Animator))] public class BoxButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler { // Content public Sprite buttonBackground; public Sprite buttonIcon; public string buttonTitle = "Button"; public string titleLocalizationKey; public string buttonDescription = "Description"; public string descriptionLocalizationKey; public BackgroundFilter backgroundFilter; // Resources [SerializeField] private Animator animator; public Image backgroundObj; public Image iconObj; public TextMeshProUGUI titleObj; public TextMeshProUGUI descriptionObj; public Image filterObj; public List filters = new List(); // Settings public bool isInteractable = true; public bool enableBackground = true; public bool enableIcon = false; public bool enableTitle = true; public bool enableDescription = true; public bool enableFilter = true; public bool useCustomContent = false; public bool checkForDoubleClick = true; public bool useLocalization = true; public bool bypassUpdateOnEnable = false; 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; public bool useSounds = true; [Range(0.1f, 1)] public float doubleClickPeriod = 0.25f; // Events public UnityEvent onClick = new UnityEvent(); public UnityEvent onDoubleClick = new UnityEvent(); public UnityEvent onHover = new UnityEvent(); public UnityEvent onLeave = new UnityEvent(); public UnityEvent onSelect = new UnityEvent(); public UnityEvent onDeselect = new UnityEvent(); // Helpers bool isInitialized = false; float cachedStateLength = 0.5f; bool waitingForDoubleClickInput; Button targetButton; LocalizedObject localizedObject; #if UNITY_EDITOR public int latestTabIndex = 0; #endif public enum BackgroundFilter { Aqua, Dawn, Dusk, Emerald, Kylo, Memory, Mice, Pinky, Retro, Rock, Sunset, Violet, Warm, Random } void Awake() { cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(animator, "BoxButton_Highlighted") + 0.1f; } void OnEnable() { if (!isInitialized) { Initialize(); } if (!bypassUpdateOnEnable) { UpdateUI(); } if (Application.isPlaying && useUINavigation) { AddUINavigation(); } else if (Application.isPlaying && !useUINavigation && targetButton == null) { targetButton = gameObject.AddComponent