육지도착

This commit is contained in:
2026-06-22 16:58:32 +09:00
parent f7a71e11d6
commit 74afff5be8
23 changed files with 1500 additions and 54 deletions

View File

@@ -0,0 +1,77 @@
using UnityEngine;
using UnityEngine.UI;
using TMPro;
public class RaftHealthUI : MonoBehaviour
{
[Header("References")]
[SerializeField] private RaftHealth raftHealth;
[SerializeField] private Image hpFillImage;
[SerializeField] private TMP_Text hpText;
[Header("Text")]
[SerializeField] private string hpPrefix = "HP";
[Header("Options")]
[SerializeField] private bool autoFindHealth = true;
[SerializeField] private bool hideWhenNoHealth = false;
[Header("Debug")]
[SerializeField] private bool showDebugLog = true;
private void Awake()
{
if (autoFindHealth && raftHealth == null)
{
raftHealth = FindFirstObjectByType<RaftHealth>();
}
}
private void OnEnable()
{
if (raftHealth != null)
{
raftHealth.onHealthChanged.AddListener(UpdateHealthUI);
UpdateHealthUI(raftHealth.CurrentHealth, raftHealth.MaxHealth);
}
else
{
if (hideWhenNoHealth)
gameObject.SetActive(false);
if (showDebugLog)
Debug.LogWarning("[RaftHealthUI] RaftHealth가 연결되지 않았습니다.", this);
}
}
private void OnDisable()
{
if (raftHealth != null)
{
raftHealth.onHealthChanged.RemoveListener(UpdateHealthUI);
}
}
public void UpdateHealthUI(int currentHealth, int maxHealth)
{
if (maxHealth <= 0)
maxHealth = 1;
float ratio = Mathf.Clamp01((float)currentHealth / maxHealth);
if (hpFillImage != null)
{
hpFillImage.fillAmount = ratio;
}
if (hpText != null)
{
hpText.text = $"{currentHealth} / {maxHealth}";
}
if (showDebugLog)
{
Debug.Log($"[RaftHealthUI] 체력 UI 갱신: {currentHealth}/{maxHealth}");
}
}
}