Files
test/Assets/PerfectWorld/Scripts/UI/GamePlay/AUIImagePicture.cs
T
2026-01-27 18:04:32 +07:00

79 lines
2.2 KiB
C#

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
{
[Header("AUIImagePicture")]
[SerializeField] CECShortcut pSC;
[SerializeField] Button skillbutton;
[SerializeField] protected Image skillImage;
[SerializeField] GameObject borderImage;
[SerializeField] int cooldownTime;
[SerializeField] AUIClockIcon m_ClockCounter;
private void Awake()
{
if (skillbutton == null)
{
Debug.LogError("Skill Button is not assigned in AUIImagePicture");
}
skillbutton.onClick.AddListener(Execute);
}
public void SetDataPtr(CECShortcut pvData, string strName = null)
{
pSC = pvData;
}
public CECShortcut GetDataPtr() => pSC;
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 struct OpenSkillUIEvent
{
}
}