Files
test/Assets/PerfectWorld/Scripts/UI/HUDPlayer.cs
T
NguyenVanDat a786ee236e Merge branch 'develop' into implement_task_UI
# Conflicts:
#	Assets/PerfectWorld/Scripts/Managers/EC_ManPlayer.cs
#	Assets/PerfectWorld/Scripts/Move/CECPlayer.cs
#	Assets/PerfectWorld/Scripts/Network/CSNetwork/C2SCommand/C2SCommandFactory.cs
#	Assets/PerfectWorld/Scripts/Network/CSNetwork/GPDataType.cs
#	Assets/PerfectWorld/Scripts/Network/CSNetwork/GameSession.cs
#	Assets/PerfectWorld/Scripts/Task/CECTaskInterface.cs
#	Assets/Scripts/CECHostPlayer.cs
#	Assets/Scripts/EC_GPDataType.cs
2025-12-16 11:59:08 +07:00

56 lines
1.8 KiB
C#

using System;
using CSNetwork.GPDataType;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace BrewMonster
{
public class HUDPlayer : MonoBehaviour
{
public TextMeshProUGUI healthText;
public TextMeshProUGUI manaText;
public TextMeshProUGUI expText;
public TextMeshProUGUI nameText;
public TextMeshProUGUI levelText;
public Image healthImage;
public Image manaImage;
public Image expImage;
public float neededExp;
private void Awake()
{
EventBus.Subscribe<cmd_self_info_00>(UpdateHostPlayerInfoUI);
EventBus.Subscribe<CECHostPlayer.InfoHostPlayer>(UpdateNameHostPlayer);
EventBus.Subscribe<CECHostPlayer.EXPToUpLevel>(UpdateNeededExp);
}
private void OnDestroy()
{
EventBus.Unsubscribe<cmd_self_info_00>(UpdateHostPlayerInfoUI);
EventBus.Unsubscribe<CECHostPlayer.InfoHostPlayer>(UpdateNameHostPlayer);
EventBus.Unsubscribe<CECHostPlayer.EXPToUpLevel>(UpdateNeededExp);
}
private void UpdateNeededExp(CECHostPlayer.EXPToUpLevel obj)
{
neededExp = obj.NeededExp;
}
private void UpdateNameHostPlayer(CECHostPlayer.InfoHostPlayer obj)
{
nameText.text = obj.NameHostPlayer;
}
private void UpdateHostPlayerInfoUI(cmd_self_info_00 obj)
{
healthText.text = $"{obj.iHP}/{obj.iMaxHP}";
manaText.text = $"{obj.iMP}/{obj.iMaxMP}";
expText.text = $"{((float)obj.iExp/neededExp)*100}%";
levelText.text = $"{obj.sLevel}";
healthImage.fillAmount = (float)obj.iHP / (float)obj.iMaxHP;
manaImage.fillAmount = (float)obj.iMP / (float)obj.iMaxMP;
expImage.fillAmount = (float)obj.iExp / (float)neededExp;
}
}
}