fix: 아이콘이 정상적으로 출력되지 않는 오류 수정
This commit is contained in:
67
Gameton-06/Assets/Gameton/Scripts/Skill/SkillButtonItem.cs
Normal file
67
Gameton-06/Assets/Gameton/Scripts/Skill/SkillButtonItem.cs
Normal file
@@ -0,0 +1,67 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class SkillButtonItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI coolTimeText;
|
||||
[SerializeField] private Image coolTimeDimd;
|
||||
[SerializeField] private GameObject skillIcon;
|
||||
[SerializeField] private GameObject lockImage;
|
||||
|
||||
public SkillBase skillBase;
|
||||
|
||||
|
||||
public void Initalize(SkillBase skillData)
|
||||
{
|
||||
if (skillData != null)
|
||||
{
|
||||
skillData.OnSkillExecuted -= OnSkillExecuted;
|
||||
// skillData.OnCooldownCompleted -= OnCooldownCompleted;
|
||||
}
|
||||
|
||||
skillBase = skillData;
|
||||
skillData.OnSkillExecuted += OnSkillExecuted;
|
||||
// skillData.OnCooldownCompleted += OnCooldownCompleted;
|
||||
|
||||
skillIcon.SetActive(true);
|
||||
|
||||
// out 으로 받을 변수 초기화
|
||||
Sprite loadedSkillImage = null;
|
||||
Assert.IsTrue(AssetManager.Singleton.LoadSkillIcon(skillBase.SkillData.id, out loadedSkillImage));
|
||||
skillIcon.GetComponent<Image>().sprite = loadedSkillImage;
|
||||
lockImage.SetActive(false);
|
||||
}
|
||||
|
||||
private void OnSkillExecuted()
|
||||
{
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
if (coolTimeText == null || coolTimeDimd == null)
|
||||
{
|
||||
return; // UI가 삭제되었으면 업데이트 중단
|
||||
}
|
||||
|
||||
coolTimeText.gameObject.SetActive(skillBase.CurrentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
|
||||
if (coolTimeText.IsActive())
|
||||
{
|
||||
coolTimeText.text = $"{skillBase.CurrentCoolDown: 0}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = skillBase.CurrentCoolDown / skillBase.SkillCoolDown; // 1 → 0 으로 감소
|
||||
}
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
UpdateCooldownUI(); // UI 업데이트
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user