fix: 아이콘이 정상적으로 출력되지 않는 오류 수정
This commit is contained in:
49
Gameton-06/Assets/Gameton/Scripts/Skill/PotionButtonItem.cs
Normal file
49
Gameton-06/Assets/Gameton/Scripts/Skill/PotionButtonItem.cs
Normal file
@@ -0,0 +1,49 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class PotionButtonItem : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private TextMeshProUGUI coolTimeText;
|
||||
[SerializeField] private Image coolTimeDimd;
|
||||
|
||||
private float currentCoolDown = 0f;
|
||||
private float potionCoolDown = 5f;
|
||||
|
||||
public void SetCurrentCoolDown()
|
||||
{
|
||||
currentCoolDown = potionCoolDown; // 쿨타임 시작
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (currentCoolDown == 0f)
|
||||
return;
|
||||
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
if (coolTimeText == null || coolTimeDimd == null)
|
||||
{
|
||||
return; // UI가 삭제되었으면 업데이트 중단
|
||||
}
|
||||
|
||||
currentCoolDown -= Time.deltaTime;
|
||||
currentCoolDown = Mathf.Max(0, currentCoolDown);
|
||||
|
||||
coolTimeText.gameObject.SetActive(currentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
|
||||
if (coolTimeText.IsActive())
|
||||
{
|
||||
coolTimeText.text = $"{currentCoolDown: 0}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = currentCoolDown / potionCoolDown; // 1 → 0 으로 감소
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d4025d96cfa84304caf95db6a4f49d0c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
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 업데이트
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f9d99c36ec531604e82c8aeebd6afa80
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
44
Gameton-06/Assets/Gameton/Scripts/Skill/SkillSettingSlot.cs
Normal file
44
Gameton-06/Assets/Gameton/Scripts/Skill/SkillSettingSlot.cs
Normal file
@@ -0,0 +1,44 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class SkillSettingSlot : MonoBehaviour
|
||||
{
|
||||
public GameObject skillImage;
|
||||
public GameObject lockerImage;
|
||||
public GameObject selectedState;
|
||||
|
||||
private int slotIndex;
|
||||
|
||||
public void Initalize(string skillId, int index)
|
||||
{
|
||||
slotIndex = index;
|
||||
// 스킬 이미지 세팅하기
|
||||
if (skillId != null) // 스킬 슬롯에 스킬이 지정된 경우
|
||||
{
|
||||
// out 으로 받을 변수 초기화
|
||||
Sprite loadedSkillImage = null;
|
||||
Assert.IsTrue(AssetManager.Singleton.LoadSkillIcon(skillId, out loadedSkillImage));
|
||||
skillImage.SetActive(true);
|
||||
skillImage.GetComponent<Image>().sprite = loadedSkillImage;
|
||||
}
|
||||
|
||||
lockerImage.SetActive(false);
|
||||
}
|
||||
|
||||
public int SelectedSlot()
|
||||
{
|
||||
selectedState.SetActive(true);
|
||||
return slotIndex;
|
||||
}
|
||||
|
||||
public void UnselectedSlot()
|
||||
{
|
||||
selectedState.SetActive(false);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9cc7099481cd73d40a0c87d18da714c4
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user