RiftMayhem/Assets/Scripts/UI/ResourceOrbUI.cs
Pedro Gomes 8917c36ad8 Character Stat revamp (wip)
- working max health, properly setting health component values and showing scales on UI
- working armor & magic resistance, properly mitigating incoming damage based on damage type
2024-08-13 22:36:01 +01:00

88 lines
2.4 KiB
C#

using Photon.Pun;
using System.Collections;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class ResourceOrbUI : MonoBehaviour
{
[Header("Components:")]
[Header("Health:")]
[SerializeField] private Image healthFill;
[SerializeField] private TMP_Text health_TMP;
[Header("Mana:")]
[SerializeField] private Image manaFill;
[SerializeField] private TMP_Text mana_TMP;
[Header("Listeners:")]
[SerializeField] private GameEventListener_PhotonView onPlayerSpawned;
Health health;
Mana mana;
private void Awake()
{
onPlayerSpawned.Response.AddListener(DependancyInjection);
}
// Start is called before the first frame update
void Start()
{
}
private void DependancyInjection(PhotonView spawnedPlayer)
{
if (!spawnedPlayer.IsMine) return;
health = ((RiftPlayer)spawnedPlayer.Owner.TagObject).GetComponent<Health>();
mana = ((RiftPlayer)spawnedPlayer.Owner.TagObject).GetComponent<Mana>();
health.onResourceChanged.AddListener(UpdateCurrentHealth);
health.onMaxHealthChanged.AddListener(UpdateMaxHealth);
mana.onResourceChanged.AddListener(UpdateCurrentMana);
mana.onMaxManaChanged.AddListener(UpdateMaxMana);
UpdateCurrentHealth(health.GetCurrentValue());
UpdateMaxHealth(health.GetMaxValue());
UpdateCurrentMana(mana.GetCurrentValue());
UpdateMaxMana(mana.GetMaxValue());
}
public void UpdateCurrentHealth(float value)
{
healthFill.fillAmount = value / health.GetMaxValue();
UpdateHealthTMP();
}
public void UpdateMaxHealth(float value)
{
healthFill.fillAmount = health.GetCurrentValue() / value;
UpdateHealthTMP();
}
public void UpdateHealthTMP()
{
health_TMP.text = $"{health.GetCurrentValue().ToString("F1")}/{health.GetMaxValue().ToString("F1")}";
}
public void UpdateCurrentMana(float value)
{
manaFill.fillAmount = value / mana.GetMaxValue();
UpdateManaTMP();
}
public void UpdateMaxMana(float value)
{
manaFill.fillAmount = mana.GetCurrentValue() / value;
UpdateManaTMP();
}
public void UpdateManaTMP()
{
mana_TMP.text = $"{mana.GetCurrentValue().ToString("F1")}/{mana.GetMaxValue().ToString("F1")}";
}
}