using BrewMonster.UI; using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using Unity.VisualScripting; using UnityEngine; using UnityEngine.UI; namespace BrewMonster.Assets.PerfectWorld.Scripts.UI.GamePlay { public class AUIImagePicture : MonoBehaviour { CECShortcut pSC; [Header("AUIImagePicture")] [SerializeField] Button skillbutton; [SerializeField] protected Image skillImage; [SerializeField] GameObject borderImage; [SerializeField] int cooldownTime; [SerializeField] AUIClockIcon m_ClockCounter; private Color m_color = Color.white; private bool m_bUpdateRenderTarget; private bool m_bForceDynamicRender; private AUIDialog m_pParent; private void Awake() { if (skillbutton == null) { Debug.LogError("Skill Button is not assigned in AUIImagePicture"); } skillbutton.onClick.AddListener(Execute); m_pParent = GetComponentInParent(); } public void SetDataPtr(CECShortcut pvData, string strName) { pSC = pvData; } public void Execute() { if (pSC != null) { pSC.Execute(); StartCoroutine(CooldownRoutine()); } else { EventBus.Publish(new OpenSkillUIEvent()); } } public void SetImage(Sprite sprite) { if(skillImage == null) { Debug.LogError("Skill Image is not assigned in AUIImagePicture"); return; } skillImage.sprite = sprite; if(borderImage != null) borderImage.SetActive(true); } private IEnumerator CooldownRoutine() { // Disable interaction skillbutton.interactable = false; // Set gray skillImage.color = Color.gray; // Wait yield return new WaitForSeconds(cooldownTime); // Restore skillImage.color = Color.white; skillbutton.interactable = true; } public AUIClockIcon GetClockIcon() => m_ClockCounter; public void SetColor(Color color) { if (m_color != color) UpdateRenderTargert(); m_color = color; } private void UpdateRenderTargert() { if (!NeedDynamicRender()) m_pParent.UpdateRenderTarget(); } private bool NeedDynamicRender() { return m_bUpdateRenderTarget || m_bForceDynamicRender; } } public struct OpenSkillUIEvent { } }