- AbnormalityData에 UI 표시 여부 플래그를 추가하고 이상상태 목록 UI가 이를 반영하도록 정리 - PlayerHUD가 로컬 플레이어의 이상상태 요약 문자열을 런타임에 자동 생성해 표시하도록 확장 - 디버그 메뉴에 기절, 침묵, 집행자의 낙인 적용과 HUD 요약 로그 기능을 추가 - TMP 한글 폰트를 HUD 요약에 재사용하고 관련 폰트 아틀라스를 갱신 - Unity 리프레시, 빌드, 집행자의 낙인 HUD 출력 로그로 동작 검증
140 lines
4.2 KiB
C#
140 lines
4.2 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 TMP_FontAsset FontAsset => valueText != null ? valueText.font : null;
|
|
|
|
/// <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>();
|
|
}
|
|
}
|
|
}
|