Fixed
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
|
||||
[DisallowMultipleComponent]
|
||||
public sealed class CannonTimerView : MonoBehaviour
|
||||
{
|
||||
[SerializeField] private NetworkCannonController controller;
|
||||
[SerializeField] private TMP_Text timerText;
|
||||
[SerializeField] private string emptyText = "INSERT ROCKET";
|
||||
[SerializeField] private string loadedFormat = "DELAY {0:0}s";
|
||||
[SerializeField] private string countdownFormat = "FIRE IN {0:0.0}s";
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
if (controller != null)
|
||||
controller.Changed += Refresh;
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
if (controller != null)
|
||||
controller.Changed -= Refresh;
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (controller != null && controller.State == CannonState.Countdown)
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void Refresh()
|
||||
{
|
||||
if (timerText == null || controller == null)
|
||||
return;
|
||||
|
||||
timerText.text = controller.State switch
|
||||
{
|
||||
CannonState.Empty => emptyText,
|
||||
CannonState.Loaded => string.Format(loadedFormat, controller.SelectedDelay),
|
||||
CannonState.Countdown => string.Format(
|
||||
countdownFormat, controller.RemainingSeconds),
|
||||
_ => emptyText
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user