public static object SetInterval(System.Action cb, int ms) { IntervalHandle handle = new IntervalHandle(); Run(_SetInterval(handle, cb, ms)); return(handle); }
public static object SetUpdate(System.Action cb) { IntervalHandle handle = new IntervalHandle(); Run(_SetUpdate(handle, cb)); return(handle); }
public static object SetTimeout(System.Action cb, int ms) { IntervalHandle handle = new IntervalHandle(); handle.Couroutine = Run(_SetTimeout(handle, cb, ms)); return(handle); }
public static void ClearInterval(object handle) { if (handle != null && handle is IntervalHandle) { IntervalHandle intervalHandle = (IntervalHandle)handle; intervalHandle.Running = false; Stop(intervalHandle.Couroutine); } }
static IEnumerator _SetTimeout(IntervalHandle handle, System.Action cb, int ms) { var seconds = ms / 1000.0f; yield return(new WaitForSeconds(seconds)); if (handle.Running) { cb(); } }
static IEnumerator _SetUpdate(IntervalHandle handle, System.Action cb) { while (true) { if (handle.Running) { cb(); } else { yield break; } yield return(null); } }
static IEnumerator _SetInterval(IntervalHandle handle, System.Action cb, int ms) { var seconds = ms / 1000.0f; while (true) { var end = Time.realtimeSinceStartup + seconds; while (Time.realtimeSinceStartup < end) { yield return(null); } if (handle.Running) { cb(); } else { yield break; } } }
public void ClearInterval (IntervalHandle handle) { }