Files
Colosseum/Assets/_Game/Scripts/UI/StatBar.cs
dal4segno 0c7c7b0c12 feat: 플레이어 탱킹 및 지원 스킬 1차 구현
- 도발, 방어 태세, 철벽 스킬과 위협 생성 배율 시스템을 추가

- 치유, 광역 치유, 보호막 스킬과 관련 이상상태/이펙트 자산을 구성

- 보호막 흡수 로직과 체력 HUD 보너스 표시를 PlayerNetworkController, PlayerHUD, StatBar에 반영

- 플레이어 프리팹 슬롯과 디버그 메뉴를 확장해 탱킹·지원 스킬 검증 경로를 추가

- Unity 컴파일과 런타임 테스트에서 도발, 치유, 광역 치유, 보호막 발동 및 보호막 수치 적용을 확인
2026-03-24 19:17:16 +09:00

135 lines
4.0 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace Colosseum.UI
{
/// <summary>
/// 체력/마나 바 UI 컴포넌트
/// Slider 또는 Image.Fill 방식 지원
/// </summary>
public class StatBar : MonoBehaviour
{
[Header("References - Slider 방식")]
[SerializeField] private Slider slider;
[Header("References - Fill Image 방식")]
[SerializeField] private Image fillImage;
[Header("References - 텍스트")]
[SerializeField] private TMP_Text valueText;
[Header("Colors")]
[SerializeField] private Color fullColor = Color.green;
[SerializeField] private Color lowColor = Color.red;
[SerializeField] private float lowThreshold = 0.3f;
[SerializeField] private bool useColorTransition = true;
[Header("Animation")]
[SerializeField] private bool smoothTransition = true;
[SerializeField] private float lerpSpeed = 5f;
private float currentValue;
private float maxValue;
private float displayValue;
private float bonusValue;
/// <summary>
/// 바 값 설정
/// </summary>
public void SetValue(float current, float max)
{
SetValue(current, max, 0f);
}
/// <summary>
/// 바 값과 보너스 수치를 함께 설정합니다.
/// </summary>
public void SetValue(float current, float max, float bonus)
{
currentValue = current;
maxValue = max;
bonusValue = Mathf.Max(0f, bonus);
if (!smoothTransition)
{
displayValue = currentValue;
}
// 항상 즉시 시각적 업데이트 수행
UpdateVisuals();
}
private void Update()
{
if (smoothTransition && !Mathf.Approximately(displayValue, currentValue))
{
displayValue = Mathf.Lerp(displayValue, currentValue, lerpSpeed * Time.deltaTime);
if (Mathf.Abs(displayValue - currentValue) < 0.01f)
displayValue = currentValue;
UpdateVisuals();
}
}
private void UpdateVisuals()
{
if (maxValue <= 0f)
{
Debug.LogWarning($"[StatBar:{gameObject.name}] UpdateVisuals: maxValue is {maxValue}, skipping");
return;
}
float ratio = Mathf.Clamp01(displayValue / maxValue);
// Slider 방식
if (slider != null)
{
slider.value = ratio;
// Slider 내부 Fill 이미지 색상 변경
if (useColorTransition && slider.fillRect != null)
{
var fillImg = slider.fillRect.GetComponent<Image>();
if (fillImg != null)
{
fillImg.color = ratio <= lowThreshold ? lowColor : fullColor;
}
}
}
// Image.Fill 방식
else if (fillImage != null)
{
fillImage.fillAmount = ratio;
if (useColorTransition)
{
fillImage.color = ratio <= lowThreshold ? lowColor : fullColor;
}
}
// 텍스트
if (valueText != null)
{
if (bonusValue > 0f)
{
valueText.text = $"{Mathf.CeilToInt(displayValue)} / {Mathf.CeilToInt(maxValue)} (+{Mathf.CeilToInt(bonusValue)})";
}
else
{
valueText.text = $"{Mathf.CeilToInt(displayValue)} / {Mathf.CeilToInt(maxValue)}";
}
}
}
private void OnValidate()
{
if (slider == null)
slider = GetComponentInChildren<Slider>();
if (fillImage == null && slider == null)
fillImage = GetComponentInChildren<Image>();
}
}
}