Practice_Unity/Assets/Scripts/UI/ExpBar.cs
SEAN cbd35babca 작업
1. ExpBar를 UIBar 로 변경해서 UIButton과 같이 여러곳에서 공용으로 사용할 수 있게 변경
2. EventBus 를 만들어서 Button같이 자기 스스로 동작을 시작할 수 있는 오브젝트들 말고 수동적인 오브젝트들이 값을 받는 방식을 관리하게 설정
  - PlayerController, UIManager, UIBar, EventBus를 연결함
3. Events 아래에 Player의 이벤트에 연관된 코드를 PlayerEvents 로 만들어서 관리함
  - 경험치 전달 양식이 여기 존재
  - 체력바나 마나바 같은 양식도 여기서 만들 예정
2025-10-20 16:54:45 +09:00

35 lines
993 B
C#

using System;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ExpBar : MonoBehaviour
{
private Image _valueBar;
private TMPro.TextMeshProUGUI _levelText;
private void Awake()
{
_valueBar = transform.Find("Stack/ImageStack/ValueBar").GetComponent<Image>();
_levelText = transform.Find("Stack/Lv_Icon/Lv_BackGround/Lv_Text").GetComponent<TextMeshProUGUI>();
RectTransform fillRect = _valueBar.rectTransform;
fillRect.anchorMax = new Vector2(0, 1);
_levelText.text = 1.ToString();
}
public void UpdateValue(int level, float currentExp, float maxExp)
{
if (_valueBar == null) return;
float expRatio = 0f;
if (maxExp > 0) expRatio = currentExp / maxExp;
RectTransform fillRect = _valueBar.rectTransform;
fillRect.anchorMax = new Vector2(expRatio, 1);
if (_levelText != null)
_levelText.text = level.ToString();
}
}