贺州人民医院电子沙盘
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

78 lines
1.7 KiB

using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace AX.Timer
{
public class Timer : IDisposable
{
private float sumTime;
private float timer;
private bool timerFlag;
private bool isRepeat = false;
private Action TimeOutEvent;
public bool IsTimering { get { return timerFlag; } }
public Timer(float timer)
{
sumTime = timer;
//timerFlag = true;
}
public void AddTimeOutEvent(Action action)
{
TimeOutEvent += action;
}
public void UpdateTimer()
{
if (!timerFlag)
return;
timer += Time.deltaTime;
if (timer >= sumTime)
{
if (TimeOutEvent != null)
{
TimeOutEvent();
}
PauseTimer();
if (isRepeat)
StartTimer();
}
//Debug.Log(timer);
}
private void ResetTime()
{
timer = 0;
}
public void PauseTimer()
{
timerFlag = false;
ResetTime();
}
public void StartTimer()
{
timerFlag = true;
ResetTime();
}
public void StartTimerRepeat()
{
StartTimer();
isRepeat = true;
}
public int GetTimer()
{
return (int)timer;
}
public int GetRemainingTime()
{
return (int)(sumTime - timer);
}
public void Dispose()
{
TimeOutEvent = null;
}
}
}