public void Reset(float dur, ITimeSupplier supplier) { _supplier = supplier ?? SPTime.Normal; _dur = dur; _t = 0d; _lastTotal = double.NegativeInfinity; }
public SPTimePeriod(float seconds, ITimeSupplier supplier) { _seconds = seconds; _timeSupplierType = DeltaTimeType.Normal; _timeSupplierName = null; this.TimeSupplier = supplier; }
public SPTime(ITimeSupplier ts) { if (ts == null) throw new System.ArgumentNullException("ts"); _timeSupplierType = SPTime.GetDeltaType(ts); if (ts is CustomTimeSupplier) _timeSupplierName = (ts as CustomTimeSupplier).Id; else _timeSupplierName = null; }
public WaitUntilTime Time(float time, ITimeSupplier timeSupplier = null) { var obj = _pool.GetInstance(); obj.Init(time, timeSupplier); return(obj); }
/// <summary> /// Create a WaitForDuration in seconds as a pooled object. /// /// NOTE - This retrieves a pooled WaitForDuration that should be used only once. It should be immediately yielded and not used again. /// </summary> /// <param name="seconds"></param> /// <param name="supplier"></param> /// <returns></returns> public static WaitForDuration Seconds(float seconds, ITimeSupplier supplier = null) { var w = _pool.GetInstance(); w.Reset(seconds, supplier); return(w); }
public static RadicalCoroutine InvokeRepeatingRadical(this MonoBehaviour behaviour, System.Action method, float delay, float repeatRate, ITimeSupplier time = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.CancelOnDisable) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (method == null) throw new System.ArgumentNullException("method"); return StartRadicalCoroutine(behaviour, RadicalInvokeRedirect(method, delay, repeatRate, time), disableMode); }
protected void Dispose() { this.OnComplete = null; _supplier = null; _t = 0d; _lastTotal = float.NegativeInfinity; _dur = 0f; }
public void Schedule(System.Action <ISPAnim> callback, float timeout, ITimeSupplier supplier) { if (_scheduler == null) { _scheduler = new AnimEventScheduler(this); } _scheduler.Schedule(callback, timeout, supplier); }
public Scheduler(ITimeSupplier time) { if (time == null) { throw new System.ArgumentNullException("time"); } _time = time; }
public RadicalCoroutine InvokeRadical(System.Action method, float delay, ITimeSupplier time = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (method == null) { throw new System.ArgumentNullException("method"); } return(this.StartRadicalCoroutine(CoroutineUtil.RadicalInvokeRedirect(method, delay, -1f, time), disableMode)); }
public void ChangeTimeSupplier(ITimeSupplier time) { if (time == null) { throw new System.ArgumentNullException("time"); } if (time == _time) { return; } _time = time; _version++; if (_firstNode == null) { return; } var total = _time.TotalPrecise; using (var lst = com.spacepuppy.Collections.TempCollection.GetList <ScheduledEvent>(_nodeCount)) { var node = _firstNode; _firstNode = null; while (node != null) { node._nextScheduledTime = node.GetNextScheduledTime(total); if (double.IsNaN(node._nextScheduledTime)) { var tnode = node; node = node._nextNode; tnode._prevNode = null; tnode._nextNode = null; tnode._owner = null; } else { lst.Add(node); } } _nodeCount = lst.Count; if (_nodeCount > 0) { lst.Sort((a, b) => a._nextScheduledTime.CompareTo(b._nextScheduledTime)); _firstNode = lst[0]; _firstNode._prevNode = null; for (int i = 1; i < lst.Count; i++) { lst[i - 1]._nextNode = lst[i]; lst[i]._prevNode = lst[i - 1]; } lst[lst.Count - 1]._nextNode = null; } } }
public Greeting(ITimeSupplier timeSupplier) { if (timeSupplier == null) { throw new ArgumentNullException("timeSupplier", @"Greeting / Greeting"); } _timeSupplier = timeSupplier; }
public SPAnimClip(string name, AnimationClip clip, ITimeSupplier timeSupplier) { _name = name; _clip = clip; _masks = new MaskCollection(); _timeSupplier = new SPTime(timeSupplier); //_firstFrame = 0; //_lastFrame = -1; }
public SPAnimClip(string name, AnimationClip clip, ITimeSupplier timeSupplier) { _name = name; _clip = clip; _timeSupplier = new SPTime(timeSupplier); _mask = new SPAnimMaskSerializedRef(); //_firstFrame = 0; //_lastFrame = -1; }
public SPTime(ITimeSupplier ts) { if (ts == null) { throw new System.ArgumentNullException("ts"); } _timeSupplierType = SPTime.GetDeltaType(ts); _timeSupplierName = SPTime.GetValidatedId(ts); }
public WaitUntilTime NextInterval(float interval, float offset, ITimeSupplier timeSupplier = null) { var obj = _pool.GetInstance(); var ts = timeSupplier ?? SPTime.Normal; float t = MathUtil.FloorToInterval(ts.Total, interval, offset) + interval; obj.Init(t, ts); return(obj); }
static void Main(string[] args) { TimeSupplier = new SimulatedTimeSupplier(); while (COVID_19()) { StayAtHome(); } }
public static DeltaTimeType GetDeltaType(ITimeSupplier time) { if (time == _normalTime) return DeltaTimeType.Normal; else if (time == _realTime) return DeltaTimeType.Real; else if (time == _smoothTime) return DeltaTimeType.Smooth; else return DeltaTimeType.Custom; }
public void Schedule(Action <ISPAnim> callback, float timeout, ITimeSupplier time) { if (_state == null) { throw new System.ObjectDisposedException("ISPAnim"); } if (_scheduler == null) { _scheduler = new AnimEventScheduler(this); } _scheduler.Schedule(callback, timeout, time); }
/// <summary> /// Returns the scale relative to NormalTime that would cause something updating by normal time appear at the scale of 'supplier'. /// Basically if you have an Animation/Animator, which animates relative to Time.timeScale, and you want to set the 'speed' property of it /// to a value so that it appeared at the speed that is defined in 'supplier', you'd set it to this value. /// </summary> /// <param name="supplier"></param> /// <returns></returns> public static float GetInverseScale(ITimeSupplier supplier) { if (supplier == null) { return(1f); } if (supplier is NormalTimeSupplier) { return(1f); } return(supplier.Scale / Time.timeScale); }
public void Schedule(System.Action <ISPAnim> callback, float timeout, ITimeSupplier timeSupplier) { //if (!_state.IsPlaying) throw new System.InvalidOperationException("Can only schedule a callback on a playing animation."); if (callback == null) { throw new System.ArgumentNullException("callback"); } if (timeout == float.PositiveInfinity) { if (_endOfLineCallback == null) { _endOfLineCallback = new CallbackInfo() { timeout = float.PositiveInfinity } } ; _endOfLineCallback.callback += callback; } else { var info = _pool.GetInstance(); info.callback = callback; info.timeout = timeout; info.supplier = (timeSupplier != null) ? timeSupplier : SPTime.Normal; if (_inUpdate) { if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } _toAddOrRemove.Add(info); } else { _timeoutInfos.Add(info); } } if (_waitRoutine == null || _waitRoutine.Finished) { this.InitWaitRoutine(); } if (!_waitRoutine.Active) { _waitRoutine.Start(_state.Controller); } }
public SPTime(ITimeSupplier ts) { if (ts == null) { throw new System.ArgumentNullException("ts"); } _timeSupplierType = SPTime.GetDeltaType(ts); if (ts is CustomTimeSupplier) { _timeSupplierName = (ts as CustomTimeSupplier).Id; } else { _timeSupplierName = null; } }
public static string GetCustomName(ITimeSupplier supplier) { if (_customTimes == null || supplier == null) { return(null); } var e = _customTimes.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Value == supplier) { return(e.Current.Key); } } return(null); }
public void Schedule(System.Action <ISPAnim> callback, float timeout, ITimeSupplier timeSupplier) { //if (!_state.IsPlaying) throw new System.InvalidOperationException("Can only schedule a callback on a playing animation."); if (callback == null) { throw new System.ArgumentNullException("callback"); } if (float.IsPositiveInfinity(timeout) || float.IsNaN(timeout)) { if (_endOfLineCallback == null) { _endOfLineCallback = new CallbackInfo() { timeout = float.NaN } } ; _endOfLineCallback.callback += callback; } else { var info = _pool.GetInstance(); info.callback = callback; info.current = 0f; info.timeout = timeout; info.supplier = (timeSupplier != null) ? timeSupplier : SPTime.Normal; if (_inUpdate) { if (_toAddOrRemove == null) { _toAddOrRemove = TempCollection.GetList <CallbackInfo>(); } _toAddOrRemove.Add(info); } else { _timeoutInfos.Add(info); } } GameLoop.UpdatePump.Add(this); }
/// <summary> /// Reverse lookup for DeltaTimeType from an object. /// </summary> /// <param name="time"></param> /// <returns></returns> public static DeltaTimeType GetDeltaType(ITimeSupplier time) { if (time == _normalTime || time == null) { return(DeltaTimeType.Normal); } else if (time == _realTime) { return(DeltaTimeType.Real); } else if (time == _smoothTime) { return(DeltaTimeType.Smooth); } else { return(DeltaTimeType.Custom); } }
/// <summary> /// Returns the Id of a time supplier as it is stored in the look up table. If the supplier is not managed, null is returned. /// </summary> /// <param name="supplier"></param> /// <returns></returns> public static string GetValidatedId(ITimeSupplier supplier) { if (supplier == null) { return(null); } string id = supplier.Id; ITimeSupplier ts; if (supplier is SPTime) { var dtp = ((SPTime)supplier).TimeSupplierType; supplier = SPTime.GetTime(dtp, id); if (supplier == null) { return(null); } else if (dtp != DeltaTimeType.Custom) { return(supplier.Id); } else { return(id); } } else if (_registeredTimeSuppliers.TryGetValue(id, out ts) && ts == supplier) { return(id); } var e = _registeredTimeSuppliers.GetEnumerator(); while (e.MoveNext()) { if (e.Current.Value == supplier || e.Current.Value.Id == id) { return(e.Current.Key); } } return(null); }
public void Dispose() { _controller = null; _clipId = null; _weight = 1f; _speed = 1f; _layer = 0; _wrapMode = UnityEngine.WrapMode.Default; _blendMode = AnimationBlendMode.Blend; _mask = null; this.UnregisterTimeScaleChangedEvent(); _timeSupplier = null; _state = null; if (_scheduler != null) { _scheduler.Clear(); } _pool.Release(this); }
public static void RegisterCustom(ITimeSupplier supplier) { if (supplier == null) { throw new System.ArgumentNullException("supplier"); } string id = supplier.Id; if (_registeredTimeSuppliers.ContainsKey(id)) { throw new System.ArgumentException(string.Format("A timesupplier with id '{0}' already exists.", id)); } _registeredTimeSuppliers[id] = supplier; if (supplier is CustomTimeSupplier) { if (_customTimeSuppliers.Count == 0) { GameLoop.RegisterInternalEarlyUpdate(SPTime.Update); } _customTimeSuppliers.Add(supplier as ICustomTimeSupplier); } }
internal static System.Collections.IEnumerator RadicalInvokeRedirect(System.Action method, float delay, float repeatRate = -1f, ITimeSupplier time = null) { yield return WaitForDuration.Seconds(delay, time); if (repeatRate < 0f) { method(); } else if (repeatRate == 0f) { while (true) { method(); yield return null; } } else { while (true) { method(); yield return WaitForDuration.Seconds(repeatRate, time); } } }
public TweenHash UseRealTime() { _timeSupplier = SPTime.Real; return(this); }
public TweenHash UseSmoothTime() { _timeSupplier = SPTime.Smooth; return this; }
/// <summary> /// Returns the scale relative to NormalTime that would cause something updating by normal time appear at the scale of 'supplier'. /// Basically if you have an Animation/Animator, which animates relative to Time.timeScale, and you want to set the 'speed' property of it /// to a value so that it appeared at the speed that is defined in 'supplier', you'd set it to this value. /// </summary> /// <param name="supplier"></param> /// <returns></returns> public static float GetInverseScale(ITimeSupplier supplier) { if (supplier == null) return 1f; if (supplier is NormalTimeSupplier) return 1f; return supplier.Scale / Time.timeScale; }
public TweenHash UseNormalTime() { _timeSupplier = SPTime.Normal; return this; }
public TweenHash UseRealTime() { _timeSupplier = SPTime.Real; return this; }
protected void Dispose() { _timeSupplier = null; _finishTime = 0f; }
ITweenHash ITweenHash.Use(ITimeSupplier time) { this.TimeSupplier = time; return this; }
ITweenHash ITweenHash.Use(ITimeSupplier time) { return(this.Use(time)); }
public static RadicalCoroutine InvokeRepeatingRadical(this MonoBehaviour behaviour, System.Action method, float delay, float repeatRate, ITimeSupplier time = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.CancelOnDisable) { if (behaviour == null) { throw new System.ArgumentNullException("behaviour"); } if (method == null) { throw new System.ArgumentNullException("method"); } return(StartRadicalCoroutine(behaviour, RadicalInvokeRedirect(method, delay, repeatRate, time), disableMode)); }
public WaitUntilTime(float time, ITimeSupplier timeSupplier) { this.Init(time, timeSupplier); }
public RadicalCoroutine InvokeRepeatingRadical(System.Action method, float delay, float repeatRate, ITimeSupplier time = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (method == null) throw new System.ArgumentNullException("method"); return this.StartRadicalCoroutine(CoroutineUtil.RadicalInvokeRedirect(method, delay, repeatRate, time), disableMode); }
public WaitUntilTime NextInterval(float interval, float offset, ITimeSupplier timeSupplier = null) { var obj = _pool.GetInstance(); var ts = timeSupplier ?? SPTime.Normal; float t = MathUtil.FloorToInterval(ts.Total, interval, offset) + interval; obj.Init(t, ts); return obj; }
public TweenHash UseSmoothTime() { _timeSupplier = SPTime.Smooth; return(this); }
public TweenHash Use(ITimeSupplier time) { _timeSupplier = time ?? SPTime.Normal; return this; }
public TweenHash Use(ITimeSupplier time) { _timeSupplier = time ?? SPTime.Normal; return(this); }
public WaitUntilTime Time(float time, ITimeSupplier timeSupplier = null) { var obj = _pool.GetInstance(); obj.Init(time, timeSupplier); return obj; }
private static System.Collections.IEnumerator InvokeRedirect(System.Action method, float delay, float repeatRate = -1f, ITimeSupplier time = null) { yield return new WaitForSeconds(delay); if (repeatRate < 0f) { method(); } else if (repeatRate == 0f) { while (true) { method(); yield return null; } } else { var w = new WaitForSeconds(repeatRate); while (true) { method(); yield return w; } } }
ITweenHash ITweenHash.Use(ITimeSupplier time) { return this.Use(time); }
internal static System.Collections.IEnumerator RadicalInvokeRedirect(System.Action method, float delay, float repeatRate = -1f, ITimeSupplier time = null) { yield return(WaitForDuration.Seconds(delay, time)); if (repeatRate < 0f) { method(); } else if (repeatRate == 0f) { while (true) { method(); yield return(null); } } else { while (true) { method(); yield return(WaitForDuration.Seconds(repeatRate, time)); } } }
private void Init(float time, ITimeSupplier timeSupplier) { _finishTime = time; _timeSupplier = timeSupplier ?? SPTime.Normal; }