47 lines
1.4 KiB
C#
47 lines
1.4 KiB
C#
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class StatusUI : MonoBehaviour
|
|
{
|
|
public Image backgroundImage;
|
|
public Image stunImage;
|
|
public Text turnsText;
|
|
|
|
private BattleParticipant battleParticipant;
|
|
|
|
public void Init(BattleParticipant battleParticipant) {
|
|
this.battleParticipant = battleParticipant;
|
|
|
|
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusChanged;
|
|
}
|
|
|
|
// Start is called before the first frame update
|
|
void Start()
|
|
{
|
|
UpdateAppearance();
|
|
}
|
|
|
|
public void NotifyBattleStatusChanged(BattleParticipant updatedParticipant) {
|
|
if (updatedParticipant != this.battleParticipant) {
|
|
throw new System.InvalidOperationException(
|
|
"NotifyBattleStatusChanged was notified about a different participant.");
|
|
}
|
|
UpdateAppearance();
|
|
}
|
|
|
|
private void UpdateAppearance() {
|
|
int statusCount = 0;
|
|
if (battleParticipant.HasStatus(BattleStatus.Stun)) {
|
|
statusCount++;
|
|
this.stunImage.enabled = true;
|
|
this.turnsText.enabled = true;
|
|
this.turnsText.text = "" + battleParticipant.GetStatusAmount(BattleStatus.Stun);
|
|
} else {
|
|
this.stunImage.enabled = false;
|
|
this.turnsText.enabled = false;
|
|
}
|
|
this.backgroundImage.enabled = (statusCount > 0);
|
|
}
|
|
}
|