public void End() { lock (this) { time = 0; active = false; _timeoutCb = null; } }
public RegularTimer(float timeoutArg, NoneForVoid_Handler timeoutCallbackArg) { if (timeoutArg <= 0) { timeout = 2f; } else { timeout = timeoutArg; } timeoutCallback = timeoutCallbackArg; enable = false; time = 0f; }
public void Begin(NoneForVoid_Handler callback, bool autoEnd = false) { _timeoutCb = callback; active = true; _thread = new Thread(() => { while (active) { Thread.Sleep(100); time += 100; if (time > timeout) { _timeoutCb?.Invoke(); if (autoEnd) { End(); } } } }); _thread.Start(); }