feat: IngameUI의 캐릭터 stat 변경 부분 적용되도록 수정
This commit is contained in:
@@ -28,6 +28,9 @@ namespace TON
|
||||
private VariableJoystick joystick;
|
||||
public Rigidbody2D rb;
|
||||
|
||||
public event System.Action<float, float> OnHPChanged;
|
||||
public event System.Action<float, float> OnSPChanged;
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
@@ -35,7 +38,6 @@ namespace TON
|
||||
joystick = ControllerUI.Instance.joystick;
|
||||
ControllerUI.Instance.linkedCharactor = this;
|
||||
|
||||
|
||||
attackCollider.EnableCollider(false); // 기본 공격 Enable 비활성화
|
||||
|
||||
Initialize();
|
||||
@@ -49,6 +51,9 @@ namespace TON
|
||||
|
||||
currentHP = maxHP = playerData.hp;
|
||||
currentSP = maxSP = playerData.mp;
|
||||
|
||||
OnHPChanged?.Invoke(currentHP, maxHP);
|
||||
OnSPChanged?.Invoke(currentSP, maxSP);
|
||||
}
|
||||
|
||||
|
||||
@@ -170,6 +175,14 @@ namespace TON
|
||||
|
||||
public void SkillAttack(string skillId)
|
||||
{
|
||||
SkillBase skillBase = SkillDataManager.Singleton.GetSkillInstance(skillId);
|
||||
// 스킬을 사용할 수 있는 스킬포인트가 있는지 판단
|
||||
// 스킬 포인트가 부족하다면 스킬을 수행하지 못함
|
||||
if (currentSP < skillBase.SkillData.mpConsumption) return;
|
||||
|
||||
currentSP -= skillBase.SkillData.mpConsumption;
|
||||
OnSPChanged?.Invoke(currentSP, maxSP);
|
||||
|
||||
// 스킬 매니저에서 스킬을 쏠 수 있는지 여부를 판단
|
||||
bool canExecute = SkillDataManager.Singleton.CanExecuteSkill(skillId);
|
||||
if (canExecute)
|
||||
@@ -189,6 +202,8 @@ namespace TON
|
||||
currentHP -= damage;
|
||||
currentHP = Mathf.Clamp(currentHP, 0, maxHP);
|
||||
|
||||
OnHPChanged?.Invoke(currentHP, maxHP);
|
||||
|
||||
// 체력이 0 아래로 떨어지고 현 상태가 IsAlive 일때만 동작하도록 함
|
||||
if (currentHP <= 0f && prevHP > 0)
|
||||
{
|
||||
|
||||
@@ -15,12 +15,5 @@ namespace TON
|
||||
linkedCharactor = GetComponent<CharacterBase>();
|
||||
}
|
||||
|
||||
private void Start()
|
||||
{
|
||||
IngameUI.Instance.SetHP(linkedCharactor.currentHP, linkedCharactor.maxHP);
|
||||
IngameUI.Instance.SetSP(linkedCharactor.currentSP, linkedCharactor.maxSP);
|
||||
IngameUI.Instance.SetPlayerImage(PlayerDataManager.Singleton.player.type);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,10 +42,17 @@ namespace TON
|
||||
}
|
||||
|
||||
// 선택된 캐릭터에 맞는 오브젝트를 생성하거나 적용하는 코드 작성
|
||||
PlayerSpawner.SpawnPlayerCharacter();
|
||||
if (!PlayerSpawner.SpawnPlayerCharacter())
|
||||
{
|
||||
Debug.LogError("Failed to spawn player character!");
|
||||
// 에러 UI를 표시하거나 씬을 다시 로드하는 등의 처리
|
||||
// UIManager.Show<ErrorUI>(UIList.ErrorUI);
|
||||
// 또는 SceneManager.LoadScene("ErrorScene"); 등
|
||||
yield break;
|
||||
}
|
||||
|
||||
SkillDataManager.Singleton.Initalize();
|
||||
StageManager.Singleton.StartStage(stageId);
|
||||
|
||||
UIManager.Show<IngameUI>(UIList.IngameUI);
|
||||
UIManager.Show<OptionUI>(UIList.OptionUI);
|
||||
UIManager.Show<ControllerUI>(UIList.ControllerUI);
|
||||
|
||||
@@ -21,36 +21,43 @@ namespace TON
|
||||
public Image monsterImage;
|
||||
|
||||
|
||||
private float currentHP;
|
||||
private float maxHP;
|
||||
private float currentSP;
|
||||
private float maxSP;
|
||||
private string playerType;
|
||||
|
||||
[SerializeField] private CharacterBase character;
|
||||
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
character = GameObject.FindWithTag("Player").GetComponent<CharacterBase>();
|
||||
playerType = PlayerDataManager.Singleton.player.type;
|
||||
|
||||
if (character != null)
|
||||
{
|
||||
character.OnHPChanged += UpdateHPBar;
|
||||
character.OnSPChanged += UpdateSPBar;
|
||||
}
|
||||
|
||||
// UI가 활성화될 때 저장된 값들로 업데이트
|
||||
RefreshUI();
|
||||
}
|
||||
|
||||
public void SetHP(float current, float max)
|
||||
private void OnDisable()
|
||||
{
|
||||
currentHP = current;
|
||||
maxHP = max;
|
||||
if (gameObject.activeInHierarchy)
|
||||
if (character != null)
|
||||
{
|
||||
hpBar.fillAmount = current / max;
|
||||
character.OnHPChanged -= UpdateHPBar;
|
||||
character.OnSPChanged -= UpdateSPBar;
|
||||
}
|
||||
}
|
||||
|
||||
public void SetSP(float current, float max)
|
||||
private void UpdateHPBar(float current, float max)
|
||||
{
|
||||
currentSP = current;
|
||||
maxSP = max;
|
||||
if (gameObject.activeInHierarchy)
|
||||
{
|
||||
spBar.fillAmount = current / max;
|
||||
}
|
||||
hpBar.fillAmount = current / max;
|
||||
}
|
||||
|
||||
private void UpdateSPBar(float current, float max)
|
||||
{
|
||||
spBar.fillAmount = current / max;
|
||||
}
|
||||
|
||||
public void SetPlayerImage(string type)
|
||||
@@ -64,8 +71,6 @@ namespace TON
|
||||
|
||||
private void RefreshUI()
|
||||
{
|
||||
if (maxHP > 0) SetHP(currentHP, maxHP);
|
||||
if (maxSP > 0) SetSP(currentSP, maxSP);
|
||||
if (!string.IsNullOrEmpty(playerType)) UpdatePlayerImage();
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user