powerfun-unity/Assets/Scripts/UI/Prefab/Panel/GameRoomCountDownController.cs
2022-08-17 18:28:28 +08:00

64 lines
1.3 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; }
protected override void Awake()
{
base.Awake();
}
public override void Show()
{
base.Show();
}
public void Init(int seconds,Action action,bool isEnd = false)
{
Seconds = seconds;
Callback = action;
endCount.gameObject.SetActive(isEnd);
}
public override void Close()
{
base.Close();
}
float timer = 0f;
private void Update()
{
timer -= Time.deltaTime;
while (timer < 0)
{
if (Seconds == 0)
{
Callback?.Invoke();
}
if (Seconds < 0)
{
gameObject.SetActive(false);
}
else
{
count.text = Helper.FormatTicks(Seconds);
endCount.text = Helper.FormatTicks(Seconds);
}
Seconds--;
timer += 1f;
}
}
}