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 ShopButtonManager : MonoBehaviour, IPointerClickHandler, IPointerEnterHandler, IPointerExitHandler, ISelectHandler, IDeselectHandler, ISubmitHandler { // Content public State state = State.Default; public Sprite buttonIcon; public string buttonTitle = "Button"; public string titleLocalizationKey; public string buttonDescription = "Description"; public string descriptionLocalizationKey; public Sprite priceIcon; public string priceText = "123"; public BackgroundFilter backgroundFilter; // Resources [SerializeField] private Animator animator; public ButtonManager purchaseButton; public ButtonManager purchasedButton; public GameObject purchasedIndicator; public ModalWindowManager purchaseModal; public Image iconObj; public Image priceIconObj; public TextMeshProUGUI titleObj; public TextMeshProUGUI descriptionObj; public TextMeshProUGUI priceObj; public Image filterObj; public List filters = new List(); // Settings public bool isInteractable = true; public bool enableIcon = false; public bool enableTitle = true; public bool enableDescription = true; public bool enablePrice = true; public bool enableFilter = true; public bool useModalWindow = true; public bool useCustomContent = false; 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; // Events public UnityEvent onPurchaseClick = new UnityEvent(); public UnityEvent onPurchase = new UnityEvent(); public UnityEvent onClick = 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; Button targetButton; #if UNITY_EDITOR public int latestTabIndex = 0; #endif public enum State { Default, Purchased } public enum BackgroundFilter { Aqua, Dawn, Dusk, Emerald, Kylo, Memory, Mice, Pinky, Retro, Rock, Sunset, Violet, Warm, Random } void Awake() { cachedStateLength = HeatUIInternalTools.GetAnimatorClipLength(animator, "ShopButton_Highlighted") + 0.1f; InitializePurchaseEvents(); } void OnEnable() { if (!isInitialized) { Initialize(); } if (!bypassUpdateOnEnable) { UpdateUI(); } if (Application.isPlaying && useUINavigation) { AddUINavigation(); } else if (Application.isPlaying && !useUINavigation && targetButton == null) { targetButton = gameObject.AddComponent