public override void Init(MyTimer myTimer) { timer = myTimer; timer.TimerStarted += argTimer => timerStartedDelegate?.Invoke(argTimer.Name, argTimer.Seconds); timer.TimerFinished += argTimer => timerFinishedDelegate?.Invoke(argTimer.Name, argTimer.Seconds); timer.TimerTick += argTimer => TimerTickDelegate?.Invoke(argTimer.Name, argTimer.Seconds); }
private int StartTimer(TimerTickDelegate tickFunc, float interval, float delayTime, int triggerTimes, float duration, OnBeginTimerDelegate beginFunc, OnEndTimerDelegate endFunc) { ++timerIndex; Timer timer = new Timer(); timer.id = timerIndex; timer.interval = interval; timer.triggerTimes = triggerTimes; timer.delayTime = delayTime; // duration 0 表示一直触发 timer.duration = duration; timer.OnBeginCallBack = beginFunc; timer.OnEndCallBack = endFunc; timer.OnTick = tickFunc; timer.Init(); timerList.Add(timer); return(timerIndex); }
public int DelayCallFunc(TimerTickDelegate tickFunc, float delayTime) { return(StartTimer(tickFunc, 0.0f, delayTime, 1, 0, null, null)); }
// triggerTimes 和 duration 不能同时大于0 // 如果同时,那么哪个先到,哪个起作用 public int RepeatCallFunc(TimerTickDelegate tickFunc, float interval, float duration = 0, OnBeginTimerDelegate beginFunc = null, OnEndTimerDelegate endFunc = null) { return(StartTimer(tickFunc, interval, 0.0f, 0, duration, beginFunc, endFunc)); }
private void OnTimerTick(MyTimer myTimer) { TimerTickDelegate?.Invoke(myTimer.Name, myTimer.Seconds); }