Update TimerMgr.cs

This commit is contained in:
ALEXTANG
2022-08-08 16:04:10 +08:00
parent 27a3dd1737
commit 0c51d17278

View File

@@ -1,4 +1,5 @@
using System.Collections.Generic; using System;
using System.Collections.Generic;
using UnityEngine; using UnityEngine;
namespace TEngine namespace TEngine
@@ -413,5 +414,37 @@ namespace TEngine
UpdateTimer(); UpdateTimer();
UpdateUnscaledTimer(); UpdateUnscaledTimer();
} }
private List<System.Timers.Timer> _ticker = new List<System.Timers.Timer>();
public System.Timers.Timer AddSystemTimer(Action<object,System.Timers.ElapsedEventArgs> callBack)
{
var timerTick = new System.Timers.Timer();
int interval = 1000;
timerTick = new System.Timers.Timer(interval);
timerTick.AutoReset = true;
timerTick.Enabled = true;
timerTick.Elapsed += new System.Timers.ElapsedEventHandler(callBack);
_ticker.Add(timerTick);
return timerTick;
}
protected override void OnDestroy()
{
DestroySystemTimer();
base.OnDestroy();
}
private void DestroySystemTimer()
{
for (int i = 0; i < _ticker.Count; i++)
{
if (_ticker[i] != null)
{
_ticker[i].Stop();
}
}
}
} }
} }