59 lines
1.4 KiB
C#
59 lines
1.4 KiB
C#
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; }
|
|
|
|
private bool simple { get; set; }
|
|
public void Init(int seconds,Action action,bool isEnd = false,bool simple = false)
|
|
{
|
|
_stopped = false;
|
|
Seconds = seconds;
|
|
Callback = action;
|
|
this.simple = simple;
|
|
endCount.gameObject.SetActive(false);
|
|
}
|
|
|
|
private bool _stopped;
|
|
public void Stop()
|
|
{
|
|
this._stopped = true;
|
|
}
|
|
|
|
private float _timer = 0f;
|
|
private void Update()
|
|
{
|
|
_timer -= Time.deltaTime;
|
|
while (_timer < 0)
|
|
{
|
|
if (Seconds == 0)
|
|
{
|
|
Callback?.Invoke();
|
|
}
|
|
|
|
if (Seconds <= 0 || _stopped)
|
|
{
|
|
gameObject.SetActive(false);
|
|
}
|
|
|
|
count.gameObject.SetActive(Seconds >0);
|
|
count.text = simple ? Seconds.ToString() : Helper.FormatTicks(Seconds);
|
|
endCount.text = Helper.FormatTicks(Seconds);
|
|
Seconds--;
|
|
_timer += 1f;
|
|
}
|
|
}
|
|
}
|
|
|