|
|
|
|
|
|
using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using Unity.UIWidgets.foundation; |
|
|
|
using UnityEngine; |
|
|
|
#if UNITY_EDITOR
|
|
|
|
using UnityEditor; |
|
|
|
|
|
|
|
|
|
|
static LinkedList<Action> _callbacks = new LinkedList<Action>(); |
|
|
|
|
|
|
|
internal static void runInMainFromFinalizer(Action callback) { |
|
|
|
lock (_syncObj) { |
|
|
|
_callbacks.AddLast(callback); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
public static void runInMain(Action callback) { |
|
|
|
public static void runInMainFromFinalizer(Action callback) { |
|
|
|
lock (_syncObj) { |
|
|
|
_callbacks.AddLast(callback); |
|
|
|
} |
|
|
|
|
|
|
LinkedList<Action> callbacks; |
|
|
|
|
|
|
|
lock (_syncObj) { |
|
|
|
if (_callbacks.isEmpty()) { |
|
|
|
return; |
|
|
|
} |
|
|
|
|
|
|
|
callbacks = _callbacks; |
|
|
|
_callbacks = new LinkedList<Action>(); |
|
|
|
} |
|
|
|
|
|
|
this._queue = new PriorityQueue<TimerImpl>(); |
|
|
|
} |
|
|
|
|
|
|
|
public Timer runInMain(Action callback) { |
|
|
|
var timer = new TimerImpl(callback); |
|
|
|
|
|
|
|
lock (this._queue) { |
|
|
|
this._queue.enqueue(timer); |
|
|
|
} |
|
|
|
return timer; |
|
|
|
} |
|
|
|
|
|
|
|
this._queue.enqueue(timer); |
|
|
|
lock (this._queue) { |
|
|
|
this._queue.enqueue(timer); |
|
|
|
} |
|
|
|
return timer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
this._queue.enqueue(timer); |
|
|
|
lock (this._queue) { |
|
|
|
this._queue.enqueue(timer); |
|
|
|
} |
|
|
|
return timer; |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
List<TimerImpl> timers = null; |
|
|
|
List<TimerImpl> appendList = null; |
|
|
|
|
|
|
|
while (this._queue.count > 0 && this._queue.peek().deadline <= now) { |
|
|
|
var timer = this._queue.dequeue(); |
|
|
|
if (timers == null) { |
|
|
|
timers = new List<TimerImpl>(); |
|
|
|
} |
|
|
|
lock (this._queue) { |
|
|
|
while (this._queue.count > 0 && this._queue.peek().deadline <= now) { |
|
|
|
var timer = this._queue.dequeue(); |
|
|
|
if (timers == null) { |
|
|
|
timers = new List<TimerImpl>(); |
|
|
|
} |
|
|
|
timers.Add(timer); |
|
|
|
timers.Add(timer); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (timers != null) { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (appendList != null) { |
|
|
|
foreach (var timer in appendList) { |
|
|
|
this._queue.enqueue(timer); |
|
|
|
lock (this._queue) { |
|
|
|
foreach (var timer in appendList) { |
|
|
|
this._queue.enqueue(timer); |
|
|
|
} |
|
|
|
public readonly bool periodic; |
|
|
|
public readonly TimeSpan internval; |
|
|
|
|
|
|
|
public readonly bool periodic; |
|
|
|
readonly TimeSpan _interval; |
|
|
|
this.periodic = periodic; |
|
|
|
|
|
|
|
this.periodic = periodic; |
|
|
|
this.internval = duration; |
|
|
|
this._interval = duration; |
|
|
|
} |
|
|
|
|
|
|
|
public TimerImpl(Action callback) { |
|
|
|
this._deadline = 0; |
|
|
|
this._callback = callback; |
|
|
|
this._done = false; |
|
|
|
} |
|
|
|
|
|
|
|
public double deadline { |
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (this.periodic) { |
|
|
|
this._deadline = now + this.internval.TotalSeconds; |
|
|
|
this._deadline = now + this._interval.TotalSeconds; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|