using System.Collections; using UnityEngine; using UnityEngine.Events; using UnityEngine.EventSystems; using UnityEngine.UI; using TMPro; namespace Michsky.UI.Heat { [ExecuteInEditMode] [DisallowMultipleComponent] public class ButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler { // Content public Sprite buttonIcon; public string buttonText = "Button"; [Range(0.1f, 10)] public float iconScale = 1; [Range(1, 200)] public float textSize = 24; // Resources [SerializeField] private CanvasGroup normalCG; [SerializeField] private CanvasGroup highlightCG; [SerializeField] private CanvasGroup disabledCG; public TextMeshProUGUI normalTextObj; public TextMeshProUGUI highlightTextObj; public TextMeshProUGUI disabledTextObj; public Image normalImageObj; public Image highlightImageObj; public Image disabledImageObj; // Auto Size public bool autoFitContent = true; public Padding padding; [Range(0, 100)] public int spacing = 12; [SerializeField] private HorizontalLayoutGroup disabledLayout; [SerializeField] private HorizontalLayoutGroup normalLayout; [SerializeField] private HorizontalLayoutGroup highlightedLayout; public HorizontalLayoutGroup mainLayout; [SerializeField] private ContentSizeFitter mainFitter; [SerializeField] private ContentSizeFitter targetFitter; [SerializeField] private RectTransform targetRect; // Settings public bool isInteractable = true; public bool enableIcon = false; public bool enableText = true; public bool useCustomContent = false; [SerializeField] private bool useCustomTextSize = 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; [Range(1, 15)] public float fadingMultiplier = 8; // 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; Button targetButton; LocalizedObject localizedObject; bool waitingForDoubleClickInput; #if UNITY_EDITOR public int latestTabIndex = 0; #endif [System.Serializable] public class Padding { public int left = 18; public int right = 18; public int top = 15; public int bottom = 15; } void OnEnable() { if (!isInitialized) { Initialize(); } if (!bypassUpdateOnEnable) { UpdateUI(); } if (Application.isPlaying && useUINavigation) { AddUINavigation(); } else if (Application.isPlaying && !useUINavigation && targetButton == null) { targetButton = gameObject.AddComponent