|
|
- using System.Collections;
- using System.Collections.Generic;
- using System.Linq;
- using UnityEngine;
- using TMPro;
- using Variables;
-
- public class StartScreenUI : MonoBehaviour
- {
-
- [SerializeField]
- private Reference<float> m_StartTime;
-
- [SerializeField]
- private TextMeshProUGUI m_countdownText;
-
- [SerializeField]
- private AnimationCurve m_lerpCurve;
-
- [SerializeField]
- private Transform m_startPosition;
-
- [SerializeField]
- private Transform m_endPosition;
-
-
- [SerializeField]
- private List<NumberAlias> m_aliases;
-
-
-
-
- private void OnEnable()
- {
- m_StartTime.OnValueChanged += UpdateCountDown;
- }
-
-
- private void OnDisable()
- {
- m_StartTime.OnValueChanged -= UpdateCountDown;
- }
-
-
- private void UpdateCountDown(float value)
- {
- int number = (int)value;
- if (m_aliases.Any(p => p.Number == number))
- {
- m_countdownText.text = m_aliases.First(p => p.Number == number).Name;
- }
- else
- {
- m_countdownText.text = number.ToString();
- }
-
-
-
- float ratio = m_lerpCurve.Evaluate(value % 1);
-
- m_countdownText.transform.position = Vector3.Lerp(m_endPosition.position, m_startPosition.position, ratio);
- }
-
- [ContextMenu("Do Count Down")]
- private void CountDown()
- {
- StartCoroutine(CountToZero(m_StartTime));
-
- }
-
- private IEnumerator CountToZero(float start)
- {
- m_StartTime.Value = start;
- while (m_StartTime > 0)
- {
- m_StartTime.Value -= Time.deltaTime;
- yield return new WaitForEndOfFrame();
- }
- }
-
-
-
- [System.Serializable]
- public struct NumberAlias
- {
- public int Number;
- public string Name;
- }
-
- }
|