powerfun-unity/Assets/Scripts/UI/Prefab/Panel/GameRoomCountDownController.cs
2022-05-10 19:24:07 +08:00

52 lines
985 B
C#

using Assets.Scripts.Apis.Models;
using System;
using UnityEngine;
using UnityEngine.UI;
public class GameRoomCountDownController : PFUIPanel
{
public Text count;
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)
{
Seconds = seconds;
Callback = action;
}
float timer = 0f;
private void Update()
{
timer -= Time.deltaTime;
while (timer < 0)
{
if (Seconds == 0)
{
Callback?.Invoke();
}
if (Seconds < 0)
{
gameObject.SetActive(false);
}
count.text = Seconds.ToString();
Seconds--;
timer += 1f;
}
}
}