r2mods/ilspy_dump/ror2_csproj/RoR2.UI/InfiniteTowerEnemyCounter.cs

76 lines
1.6 KiB
C#
Raw Normal View History

2024-10-04 07:26:37 +00:00
using TMPro;
using UnityEngine;
namespace RoR2.UI;
public class InfiniteTowerEnemyCounter : MonoBehaviour
{
[Tooltip("The root we're toggling")]
[SerializeField]
private GameObject rootObject;
[SerializeField]
[Tooltip("The text we're setting")]
private TextMeshProUGUI counterText;
[Tooltip("The language token for the text field")]
[SerializeField]
private string token;
private InfiniteTowerWaveController waveController;
private CombatSquad combatSquad;
private string counterTextString;
private bool wasActive;
private int oldMemberCount = -1;
private void OnEnable()
{
InfiniteTowerRun infiniteTowerRun = Run.instance as InfiniteTowerRun;
if ((bool)infiniteTowerRun)
{
waveController = infiniteTowerRun.waveController;
if ((bool)waveController)
{
combatSquad = waveController.GetComponent<CombatSquad>();
if ((bool)combatSquad)
{
rootObject.SetActive(waveController.HasFullProgress() && combatSquad.memberCount > 0);
}
else
{
rootObject.SetActive(value: false);
}
}
else
{
rootObject.SetActive(value: false);
}
}
counterTextString = Language.GetString(token);
}
private void Update()
{
if ((bool)combatSquad)
{
int memberCount = combatSquad.memberCount;
bool flag = waveController.HasFullProgress() && combatSquad.memberCount > 0;
if (flag != wasActive)
{
rootObject.SetActive(flag);
wasActive = flag;
}
if (flag && (bool)counterText && memberCount != oldMemberCount)
{
oldMemberCount = memberCount;
string arg = memberCount.ToString();
counterText.text = string.Format(counterTextString, arg);
}
}
}
}