using Assets.Scenes.Ride.Scripts; using Assets.Scripts.Apis.Models; using System; using UnityEngine; using UnityEngine.UI; public class GameRoomCountDownController : PFUIPanel { public Text count; public Text endCount; private int Seconds { get; set; } public GameRoomModel GameRoom { get; set; } private Action Callback { get; set; } protected override void Awake() { base.Awake(); } public override void Show() { base.Show(); } private bool isSimple { get; set; } public void Init(int seconds,Action action,bool isEnd = false,bool isSimple = false) { stopped = false; Seconds = seconds; Callback = action; endCount.gameObject.SetActive(false); this.isSimple = isSimple; } public override void Close() { base.Close(); } private bool stopped; public void Stop() { this.stopped = true; } float timer = 0f; private void Update() { timer -= Time.deltaTime; while (timer < 0) { if (Seconds == 0) { Callback?.Invoke(); } if (Seconds < 0 || stopped) { gameObject.SetActive(false); } else { if (isSimple) { count.text = Seconds.ToString(); } else { count.text = Helper.FormatTicks(Seconds); } endCount.text = Helper.FormatTicks(Seconds); } Seconds--; timer += 1f; } } }