refator : Controller 스킬 버튼 로드 및 스킬 투사체 & ObjectPool 분리
This commit is contained in:
@@ -15,45 +15,45 @@ namespace TON
|
||||
public VariableJoystick joystick;
|
||||
public CharacterBase linkedCharactor { get; set; }
|
||||
|
||||
public Button[] buttons; // UI 버튼 (3개)
|
||||
|
||||
[SerializeField]
|
||||
private SerializableDictionary<int, ControllerUI_SkillButton> skillButtons;
|
||||
private SerializableDictionary<string, SkillBase> skillInstances;
|
||||
private List<SkillData> skillDatas;
|
||||
private List<SkillBase> skillBases;
|
||||
public Transform skillButtonGroup;
|
||||
public ControllerUI_SkillButton skillButtonPrefab;
|
||||
private List<ControllerUI_SkillButton> createdSkillButtons = new List<ControllerUI_SkillButton>();
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
skillButtonPrefab.gameObject.SetActive(false);
|
||||
}
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
int characterLevel = PlayerDataManager.Singleton.player.level;
|
||||
skillInstances = SkillDataManager.Singleton.skillInstances;
|
||||
|
||||
// 내가 사용할 스킬은 스킬 매니저에서 가져오게 변경
|
||||
|
||||
if (skillInstances != null)
|
||||
// 이미 기존에 UI가 생성되어 있다면 삭제
|
||||
if (createdSkillButtons.Count > 0)
|
||||
{
|
||||
int skillSlotCount = SkillDataManager.Singleton.GetActiveSkillCount();
|
||||
List<SkillBase> skillList = SkillDataManager.Singleton.GetActiveSkillInstance();
|
||||
|
||||
// 버튼 설정
|
||||
for (int i = 0; i < buttons.Length; i++)
|
||||
foreach (var button in createdSkillButtons)
|
||||
{
|
||||
if (i < skillSlotCount)
|
||||
{
|
||||
buttons[i].interactable = true; // 사용 가능
|
||||
SkillBase skillData = skillList.Find(skill => skill.SkillData.slotNumber == i + 1);
|
||||
skillButtons[i].Initalize(skillData);
|
||||
}
|
||||
else
|
||||
{
|
||||
buttons[i].interactable = false; // 사용 불가
|
||||
}
|
||||
Destroy(button.gameObject);
|
||||
}
|
||||
createdSkillButtons.Clear();
|
||||
}
|
||||
else
|
||||
|
||||
// 스킬 버튼을 생성
|
||||
List<SkillBase> activatedSkills = SkillDataManager.Singleton.GetActiveSkillInstance();
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
Debug.LogError("스킬 정보 로드 오류 발생");
|
||||
ControllerUI_SkillButton newSkillButton = Instantiate(skillButtonPrefab, skillButtonGroup);
|
||||
newSkillButton.gameObject.SetActive(true);
|
||||
|
||||
if (i < activatedSkills.Count) // 해당 인덱스에 활성화된 스킬이 있을 경우
|
||||
{
|
||||
newSkillButton.Initalize(activatedSkills[i]);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 복제 됐을때 기본 상태가 잠금 상태
|
||||
}
|
||||
|
||||
createdSkillButtons.Add(newSkillButton);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -70,13 +70,7 @@ namespace TON
|
||||
public void OnClickSkillButton(ControllerUI_SkillButton button)
|
||||
{
|
||||
bool skillAttack = linkedCharactor.SkillAttack(button.skillBase.SkillData.id);
|
||||
// skill Attack 이 true 일때 만 쿨타임 흘러가게끔
|
||||
if (skillAttack)
|
||||
{
|
||||
// SkillData skillData = skillDatas.Find(skill => skill.id == button.skillId);
|
||||
button.SetCoolTime();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Assertions;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
@@ -13,51 +14,43 @@ namespace TON
|
||||
[SerializeField] private GameObject skillIcon;
|
||||
[SerializeField] private GameObject lockImage;
|
||||
|
||||
[SerializeField]
|
||||
private SerializableDictionary<string, Sprite> skillSprite = new SerializableDictionary<string, Sprite>();
|
||||
|
||||
public float currentCoolDown;
|
||||
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);
|
||||
skillIcon.GetComponent<Image>().sprite = skillSprite.GetValueOrDefault(skillBase.SkillData.id, null);
|
||||
|
||||
Assert.IsTrue(AssetManager.Singleton.LoadSkillIcon(skillBase.SkillData.id, out Sprite loadedSkillImage));
|
||||
skillIcon.GetComponent<Image>().sprite = loadedSkillImage;
|
||||
lockImage.SetActive(false);
|
||||
}
|
||||
|
||||
public void SetCoolTime()
|
||||
private void OnSkillExecuted()
|
||||
{
|
||||
SkillDataManager.Singleton.SetCoolTime(skillBase.SkillData.id);
|
||||
if (skillBase.CurrentCoolDown <= 0)
|
||||
{
|
||||
// 현재 스킬의 스킬 쿨다운 값을 설정
|
||||
skillBase.SetCurrentCoolDown();
|
||||
currentCoolDown = skillBase.CurrentCoolDown;
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
UpdateCooldownUI();
|
||||
}
|
||||
|
||||
private void UpdateCooldownUI()
|
||||
{
|
||||
coolTimeText.gameObject.SetActive(currentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
coolTimeText.text = $"{Mathf.CeilToInt(currentCoolDown)}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = currentCoolDown / skillBase.SkillData.coolDown; // 1 → 0 으로 감소
|
||||
coolTimeText.gameObject.SetActive(skillBase.CurrentCoolDown > 0); // 남은 쿨타임이 있을 때만 표시
|
||||
coolTimeText.text = $"{skillBase.CurrentCoolDown: 0}s"; // 정수 초단위 표시
|
||||
coolTimeDimd.fillAmount = skillBase.CurrentCoolDown / skillBase.SkillCoolDown; // 1 → 0 으로 감소
|
||||
}
|
||||
|
||||
void Update()
|
||||
{
|
||||
if (currentCoolDown > 0)
|
||||
{
|
||||
SkillDataManager.Singleton.UpdateSkillCoolDown(skillBase.SkillData.id); // 남은 쿨타임 감소
|
||||
UpdateCooldownUI(); // UI 업데이트
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
}
|
||||
UpdateCooldownUI(); // UI 업데이트
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,13 +1,21 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
namespace TON
|
||||
{
|
||||
public class SkillSettingUI_SkillSlot : MonoBehaviour
|
||||
{
|
||||
public GameObject skillImage;
|
||||
public GameObject lockerImage;
|
||||
|
||||
public void Initalize()
|
||||
{
|
||||
// 스킬 이미지 세팅하기
|
||||
// skillImage = GetComponent<GameObject>();
|
||||
}
|
||||
|
||||
public void SelectedSlot()
|
||||
{
|
||||
lockerImage.SetActive(true);
|
||||
|
||||
Reference in New Issue
Block a user