59 lines
1.5 KiB
C#
59 lines
1.5 KiB
C#
|
using System.Collections;
|
|||
|
using System.Collections.Generic;
|
|||
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
|
|||
|
public class RemainTimeCoroutine : MonoBehaviour {
|
|||
|
|
|||
|
public Text _RemainTime;
|
|||
|
public delegate void _EndCallBack();
|
|||
|
|
|||
|
private void Awake()
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
}
|
|||
|
|
|||
|
public void StartCountTime(int endTime, _EndCallBack callBack = null)
|
|||
|
{
|
|||
|
_EndTime = endTime;
|
|||
|
if (_EndTime > GlobalData.ServerAnsiTime)
|
|||
|
{
|
|||
|
gameObject.SetActive(true);
|
|||
|
StartCoroutine(CountRemainTime(callBack));
|
|||
|
}else
|
|||
|
{
|
|||
|
StopAllCoroutines();
|
|||
|
if (callBack != null)
|
|||
|
callBack.Invoke();
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private float _CountTime;
|
|||
|
private int _EndTime;
|
|||
|
private const float _LerpCountVal = 1.0f;
|
|||
|
IEnumerator CountRemainTime(_EndCallBack callBack)
|
|||
|
{
|
|||
|
while(true)
|
|||
|
{
|
|||
|
yield return null;
|
|||
|
_CountTime += Time.deltaTime;
|
|||
|
if(_CountTime >= _LerpCountVal)
|
|||
|
{
|
|||
|
_CountTime -= _LerpCountVal;
|
|||
|
_RemainTime.EnsureVal(GCGame.Utils.GetRemaintimeByEndTime(_EndTime, GCGame.Utils.RemainTimesType.Hour_Minute_Second));
|
|||
|
if (_EndTime <= GlobalData.ServerAnsiTime)
|
|||
|
{
|
|||
|
if (callBack != null)
|
|||
|
callBack.Invoke();
|
|||
|
yield break;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
private void OnDisable()
|
|||
|
{
|
|||
|
StopAllCoroutines();
|
|||
|
}
|
|||
|
}
|