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(); mana = ((RiftPlayer)spawnedPlayer.Owner.TagObject).GetComponent(); health.onResourceChanged.AddListener(UpdateCurrentHealth); health.onMaxHealthChanged.AddListener(UpdateMaxHealth); mana.onResourceChanged.AddListener(UpdateCurrentMana); mana.onMaxManaChanged.AddListener(UpdateMaxMana); } 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")}"; } }