Better status icon system
This commit is contained in:
parent
31cb8fe4c0
commit
515602b670
13 changed files with 464 additions and 250 deletions
|
|
@ -1,25 +1,27 @@
|
|||
using System.Collections;
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class StatusUI : MonoBehaviour
|
||||
{
|
||||
public Image backgroundImage;
|
||||
public Image stunImage;
|
||||
public Text turnsText;
|
||||
public StatusIconUI iconPrefab;
|
||||
|
||||
private BattleParticipant battleParticipant;
|
||||
|
||||
private Dictionary<BattleStatus, StatusIconUI> icons;
|
||||
|
||||
public void Init(BattleParticipant battleParticipant) {
|
||||
this.battleParticipant = battleParticipant;
|
||||
|
||||
this.icons = new Dictionary<BattleStatus, StatusIconUI>();
|
||||
this.battleParticipant.OnStatusChanged += this.NotifyBattleStatusChanged;
|
||||
}
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
void Start() {
|
||||
UpdateAppearance();
|
||||
}
|
||||
|
||||
|
|
@ -32,16 +34,28 @@ public class StatusUI : MonoBehaviour
|
|||
}
|
||||
|
||||
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;
|
||||
int index = 0;
|
||||
foreach (BattleStatus status in Enum.GetValues(typeof(BattleStatus)).Cast<BattleStatus>()) {
|
||||
if (status == BattleStatus.None) {
|
||||
continue;
|
||||
}
|
||||
|
||||
StatusIconUI iconUI = null;
|
||||
this.icons.TryGetValue(status, out iconUI);
|
||||
if (this.battleParticipant.HasStatus(status)) {
|
||||
if (iconUI == null) {
|
||||
iconUI = Instantiate(this.iconPrefab.gameObject, this.transform).GetComponent<StatusIconUI>();
|
||||
iconUI.Init(status);
|
||||
this.icons[status] = iconUI;
|
||||
}
|
||||
iconUI.SetAmount(this.battleParticipant.GetStatusAmount(status), index);
|
||||
index++;
|
||||
} else {
|
||||
if (iconUI != null) {
|
||||
Destroy(iconUI.gameObject);
|
||||
this.icons.Remove(status);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.backgroundImage.enabled = (statusCount > 0);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue