Create StatusUI
This commit is contained in:
parent
dd9b360bfc
commit
03ca23d484
11 changed files with 484 additions and 17 deletions
47
Assets/Battle/UI/StatusUI.cs
Normal file
47
Assets/Battle/UI/StatusUI.cs
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
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);
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue