DEG-108 [Feat] 던전 체력 UI 컨트롤러 구현
This commit is contained in:
parent
5e61ff03c9
commit
f60a22aa26
@ -49,7 +49,11 @@ public class WeaponController : MonoBehaviour, IObservable<GameObject>
|
|||||||
_playerController = GetComponent<PlayerController>();
|
_playerController = GetComponent<PlayerController>();
|
||||||
if (_playerController == null)
|
if (_playerController == null)
|
||||||
{
|
{
|
||||||
_playerController = GameObject.FindGameObjectWithTag("Player").GetComponent<PlayerController>();
|
var player = GameObject.FindGameObjectWithTag("Player");
|
||||||
|
if (player != null)
|
||||||
|
{
|
||||||
|
_playerController = player.GetComponent<PlayerController>();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
_previousPositions = new Vector3[_triggerZones.Length];
|
_previousPositions = new Vector3[_triggerZones.Length];
|
||||||
@ -106,7 +110,7 @@ public class WeaponController : MonoBehaviour, IObservable<GameObject>
|
|||||||
if (hit.collider.gameObject.CompareTag("Enemy"))
|
if (hit.collider.gameObject.CompareTag("Enemy"))
|
||||||
{
|
{
|
||||||
var enemyController = hit.transform.GetComponent<EnemyController>();
|
var enemyController = hit.transform.GetComponent<EnemyController>();
|
||||||
if (enemyController != null)
|
if (enemyController != null && _playerController != null)
|
||||||
{
|
{
|
||||||
enemyController.TakeDamage(AttackPower * _playerController.attackPower);
|
enemyController.TakeDamage(AttackPower * _playerController.attackPower);
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,8 @@ using UnityEngine;
|
|||||||
|
|
||||||
public class DungeonLogic : MonoBehaviour
|
public class DungeonLogic : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
[SerializeField] private DungeonPanelController _dungeonPanelController;
|
||||||
|
|
||||||
[NonSerialized] public bool isCompleted = false; // 던전 클리어 여부
|
[NonSerialized] public bool isCompleted = false; // 던전 클리어 여부
|
||||||
[NonSerialized] public bool isFailed = false; // 던전 실패 여부
|
[NonSerialized] public bool isFailed = false; // 던전 실패 여부
|
||||||
|
|
||||||
@ -24,19 +26,35 @@ public class DungeonLogic : MonoBehaviour
|
|||||||
// 죽음 이벤트 구독
|
// 죽음 이벤트 구독
|
||||||
if (_player != null)
|
if (_player != null)
|
||||||
{
|
{
|
||||||
|
_player.OnGetHit += OnPlayerGetHit;
|
||||||
_player.OnDeath += OnPlayerDeath;
|
_player.OnDeath += OnPlayerDeath;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_enemy != null)
|
if (_enemy != null)
|
||||||
{
|
{
|
||||||
|
_enemy.OnGetHit += OnEnemyGetHit;
|
||||||
_enemy.OnDeath += OnEnemyDeath;
|
_enemy.OnDeath += OnEnemyDeath;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 플레이어 사망 처리
|
private void OnPlayerGetHit(CharacterBase player)
|
||||||
private void OnPlayerDeath(CharacterBase player)
|
{
|
||||||
|
var result = _dungeonPanelController.SetPlayerHealth();
|
||||||
|
if (!result) // 하트 모두 소모
|
||||||
|
{
|
||||||
|
player.Die();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnEnemyGetHit(CharacterBase enemy)
|
||||||
|
{
|
||||||
|
Debug.Log("Enemy HP: " + enemy.currentHP);
|
||||||
|
_dungeonPanelController.SetBossHealthBar(enemy.currentHP);
|
||||||
|
}
|
||||||
|
|
||||||
|
// 플레이어 사망 처리
|
||||||
|
private void OnPlayerDeath()
|
||||||
{
|
{
|
||||||
Debug.Log("player name:" + player.characterName);
|
|
||||||
if (!isFailed) // 중복 실행 방지
|
if (!isFailed) // 중복 실행 방지
|
||||||
{
|
{
|
||||||
FailDungeon();
|
FailDungeon();
|
||||||
@ -44,9 +62,8 @@ public class DungeonLogic : MonoBehaviour
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 적 사망 처리
|
// 적 사망 처리
|
||||||
private void OnEnemyDeath(CharacterBase enemy)
|
private void OnEnemyDeath()
|
||||||
{
|
{
|
||||||
Debug.Log("enemy name:" + enemy.characterName);
|
|
||||||
if (!isCompleted) // 중복 실행 방지
|
if (!isCompleted) // 중복 실행 방지
|
||||||
{
|
{
|
||||||
CompleteDungeon();
|
CompleteDungeon();
|
||||||
@ -62,7 +79,7 @@ public class DungeonLogic : MonoBehaviour
|
|||||||
isCompleted = true;
|
isCompleted = true;
|
||||||
OnDungeonSuccess?.Invoke();
|
OnDungeonSuccess?.Invoke();
|
||||||
|
|
||||||
// 성공 UI 표시 ?? 강화 표기
|
_player.SetState(PlayerState.Win);
|
||||||
// TODO: 강화 시스템으로 넘어가고 일상 맵으로 이동
|
// TODO: 강화 시스템으로 넘어가고 일상 맵으로 이동
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -76,10 +93,8 @@ public class DungeonLogic : MonoBehaviour
|
|||||||
isFailed = true;
|
isFailed = true;
|
||||||
OnDungeonFailure?.Invoke();
|
OnDungeonFailure?.Invoke();
|
||||||
|
|
||||||
// 죽음 애니메이션 + 실패 UI 표시 ?
|
_player.SetState(PlayerState.Dead);
|
||||||
// GameManager.Instance.ChangeToHomeScene();
|
StartCoroutine(DelayedSceneChange()); // 3초 대기 후 전환
|
||||||
|
|
||||||
StartCoroutine(DelayedSceneChange()); // 테스트를 위해 3초 대기 후 전환
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
31
Assets/KSH/DungeonPanelController.cs
Normal file
31
Assets/KSH/DungeonPanelController.cs
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
public class DungeonPanelController : MonoBehaviour
|
||||||
|
{
|
||||||
|
[SerializeField] private Slider _bossHealthBar; // 0~1 value
|
||||||
|
[SerializeField] private Image[] _playerHealthImages; // color 값 white / black 로 조정
|
||||||
|
private int _countHealth = 0;
|
||||||
|
|
||||||
|
public void SetBossHealthBar(float hp) // hp: 0~100
|
||||||
|
{
|
||||||
|
float normalizedHp = hp / 100f; // 0~1 사이 값으로 조정
|
||||||
|
_bossHealthBar.value = normalizedHp;
|
||||||
|
}
|
||||||
|
|
||||||
|
// false 반환 시 사망 처리
|
||||||
|
public bool SetPlayerHealth()
|
||||||
|
{
|
||||||
|
if (_countHealth > _playerHealthImages.Length - 1) // out of index error 방지
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
_playerHealthImages[_countHealth].color = Color.black;
|
||||||
|
_countHealth++;
|
||||||
|
return _countHealth <= _playerHealthImages.Length - 1;
|
||||||
|
}
|
||||||
|
}
|
11
Assets/KSH/DungeonPanelController.cs.meta
Normal file
11
Assets/KSH/DungeonPanelController.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 75caf6a3958eb0745a00749003e12d73
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
BIN
Assets/KSH/DungeonTestScene.unity
(Stored with Git LFS)
BIN
Assets/KSH/DungeonTestScene.unity
(Stored with Git LFS)
Binary file not shown.
@ -1,3 +1,4 @@
|
|||||||
|
using System;
|
||||||
using System.Collections;
|
using System.Collections;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
@ -17,7 +18,8 @@ public abstract class CharacterBase : MonoBehaviour
|
|||||||
[Header("상태 이상")]
|
[Header("상태 이상")]
|
||||||
public List<StatusEffect> statusEffects = new List<StatusEffect>();
|
public List<StatusEffect> statusEffects = new List<StatusEffect>();
|
||||||
|
|
||||||
public event System.Action<CharacterBase> OnDeath; // 사망 이벤트
|
public event Action OnDeath; // 사망 이벤트
|
||||||
|
public event Action<CharacterBase> OnGetHit; // 피격 이벤트
|
||||||
|
|
||||||
protected virtual void Start()
|
protected virtual void Start()
|
||||||
{
|
{
|
||||||
@ -34,13 +36,15 @@ public abstract class CharacterBase : MonoBehaviour
|
|||||||
{
|
{
|
||||||
Die();
|
Die();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
OnGetHit?.Invoke(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
public virtual void Die()
|
public virtual void Die()
|
||||||
{
|
{
|
||||||
Debug.Log($"{characterName}이 사망했습니다.");
|
Debug.Log($"{characterName}이 사망했습니다.");
|
||||||
// TODO: 사망 처리
|
// TODO: 사망 처리
|
||||||
OnDeath?.Invoke(this);
|
OnDeath?.Invoke();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 상태이상 추가 메서드
|
// 상태이상 추가 메서드
|
||||||
|
Loading…
x
Reference in New Issue
Block a user