1、Timer timer = new Timer); 创建时间管理器 参数float time, TimeUnit timeUnit,bool ignoreTimeScale = false, bool autoStart = true) time:时间值、timeUnit 时间单位(帧率、秒、厘秒、毫秒)、ignoreTimeScale 忽略时间缩放(可以使游戏暂停更容易实现)、autoStart 自动开始计时
2、timer.loop = true; // 循环 timer.Finished +=method; // 回调函数 timer.Pause); // 暂停
using System.Collections.Generic;
using UnityEngine;
namespace Epitome
{
public delegate void FinishedHandler);
public class Timer
{
TimerManager.TimerState timer;
public bool Running { get { return timer.Running; } }
public bool Paused { get { return timer.Paused; } }
public bool Loop
{
set { timer.HasRepeat = value; }
get { return timer.HasRepeat; }
}
public event FinishedHandler Finished;
public Timerfloat time, TimeUnit timeUnit,bool ignoreTimeScale = false, bool autoStart = true)
{
timer = TimerManager.Instance.CreateTimertime, timeUnit, ignoreTimeScale);
timer.Finished += TimerFinished;
if autoStart) timer.Start);
}
public void Start) { timer.Start); }
public void Stop) { timer.Stop); }
public void Pause) { timer.Pausehttp://www.my516.com); }
public void UnPause) { timer.UnPause); }
public void TimerFinished)
{
FinishedHandler handler = Finished;
if handler != null)
handler);
}
}
———————