/// <summary> /// Removes event listeners before cancelling the routine so that no callback signals occur. /// </summary> /// <param name="routine">Supposed state to cancel, this may be a routine that was previously started on this but exited.</param> /// <returns>Returns true if was the running routine.</returns> public bool SilentlyExitState(RadicalCoroutine routine) { if (_disposed) { throw new System.InvalidOperationException("Object is disposed."); } if (routine == null) { return(false); } if (_routine == routine) { _routine = null; routine.OnCancelling -= this.OnCancelling; routine.OnFinished -= this.OnFinished; routine.Cancel(); return(true); } else { routine.Cancel(); return(false); } }
public static RadicalCoroutine StartRadicalCoroutineAsync(this MonoBehaviour behaviour, System.Delegate method, object[] args = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (behaviour == null) { throw new System.ArgumentNullException("behaviour"); } if (method == null) { throw new System.ArgumentNullException("method"); } System.Collections.IEnumerator e; if (com.spacepuppy.Utils.TypeUtil.IsType(method.Method.ReturnType, typeof(System.Collections.IEnumerable))) { e = (method.DynamicInvoke(args) as System.Collections.IEnumerable).GetEnumerator(); } else if (com.spacepuppy.Utils.TypeUtil.IsType(method.Method.ReturnType, typeof(System.Collections.IEnumerator))) { e = (method.DynamicInvoke(args) as System.Collections.IEnumerator); } else { throw new System.ArgumentException("Delegate must have a return type of IEnumerable or IEnumerator.", "method"); } var co = new RadicalCoroutine(e); co.StartAsync(behaviour, disableMode); return(co); }
private void OnComponentDestroyed(object sender, System.EventArgs e) { var item = sender as T; if (item == null) { return; } _components.Remove(item); _liveComponents.Remove(item); if (item == _currentMaster) { if (_routine != null) { _routine.Cancel(); _routine = null; } if (_liveComponents.Count > 0) { _currentMaster = _liveComponents[0]; if (_onUpdate != null) { _routine = _currentMaster.StartRadicalCoroutine(this.UpdateRoutine(), RadicalCoroutineDisableMode.CancelOnDisable); } } else { _currentMaster = null; } } }
public override bool Trigger(object arg) { if (!this.CanTrigger) { return(false); } switch (_signal) { case SignalMode.Manual: { _trigger.ActivateTriggerAt(this.CurrentIndexNormalized, this, _passAlongTriggerArg ? arg : null); _currentIndex++; } break; case SignalMode.Auto: { if (_routine != null) { _routine.Cancel(); } _routine = this.StartRadicalCoroutine(this.DoAutoSequence(null), RadicalCoroutineDisableMode.Pauses); } break; } return(true); }
private IEnumerator runTests() { frameCount = 0; yield return(RadicalCoroutine.Run(this, waitForSecondsTest(), "waitForSecondsTest")); frameCount = 0; yield return(RadicalCoroutine.Run(this, waitForNextFrameTest(), "waitForNextFrameTest")); frameCount = 0; yield return(RadicalCoroutine.Run(this, waitForFrameTest(), "waitForFrameTest")); frameCount = 0; yield return(RadicalCoroutine.Run(this, waitForCompositeReturnTest(), "waitForCompositeReturn")); yield return(RadicalCoroutine.Run(this, waitForFrameCancelledTest(), "waitForFrameCancelledTest")); yield return(RadicalCoroutine.Run(this, waitForDisposedEventTest(), "WaitForDisposedEventTest")); yield return(RadicalCoroutine.Run(this, waitForCompletedEventTest(), "waitForCompletedEventTest")); yield return(RadicalCoroutine.Run(this, waitForPausedEventTest(), "waitForPausedEventTest")); yield return(RadicalCoroutine.Run(this, waitForResumedEventTest(), "waitForResumedEventTest")); yield return(RadicalCoroutine.Run(this, cannotAddListenerToEmptyEnumerator(), "cannotAddListenerToEmptyEnumerator")); yield return(RadicalCoroutine.Run(this, waitForNestedIEnumeratorTest(), "waitForNestedIEnumeratorTest")); IntegrationTest.Pass(); }
private void AttemptAutoStart() { int i = this.CurrentIndexNormalized; if (i < 0 || i >= _trigger.Targets.Count) { return; } //if (_signal == SignalMode.Auto && _trigger.Targets[i].Target != null) //{ // var signal = _trigger.Targets[i].Target.GetComponentInChildren<IAutoSequenceSignal>(); // if (signal != null) // { // _routine = this.StartRadicalCoroutine(this.DoAutoSequence(signal), RadicalCoroutineDisableMode.Pauses); // } //} if (_signal == SignalMode.Auto) { IAutoSequenceSignal signal; var targ = GameObjectUtil.GetGameObjectFromSource(_trigger.Targets[i].Target); if (targ != null && targ.GetComponentInChildren <IAutoSequenceSignal>(out signal)) { if (signal != null) { _routine = this.StartRadicalCoroutine(this.DoAutoSequence(signal), RadicalCoroutineDisableMode.Pauses); } } } }
/// <summary> /// Must be only called by RadicalCoroutine itself. /// </summary> /// <param name="routine"></param> internal void UnregisterCoroutine(RadicalCoroutine routine) { _routines.Remove(routine); if (_naiveTrackerTable != null) { var comp = routine.Operator; if (_naiveTrackerTable.ContainsKey(comp) && !this.GetComponentIsCurrentlyManaged(comp)) { _naiveTrackerTable.Remove(comp); } } if (_autoKillTable != null && routine.AutoKillToken != null) { RadicalCoroutine other; if (_autoKillTable.TryGetValue(routine.AutoKillToken, out other)) { if (object.ReferenceEquals(other, routine)) { _autoKillTable.Remove(routine.AutoKillToken); } } } }
private IEnumerator waitForNestedIEnumeratorTest() { frameCount = 0; yield return(RadicalCoroutine.Run(this, parentCoroutine(parentCoroutine(new CompositeCoroutineReturn(new WaitForFrame(4)))), "testCoroutine")); IntegrationTestEx.FailIf(frameCount != 4, "waitForNestedIEnumeratorTest waited for the incorrect number of frames"); }
public void Start(SPSceneManager manager, ISceneLoadOptions options, ISceneBehaviour lastScene) { _manager = manager; _options = options; _lastScene = lastScene; _routine = manager.StartRadicalCoroutine(this.DoLoad()); //GameLoopEntry.Hook.StartRadicalCoroutine(this.DoLoad(), RadicalCoroutineDisableMode.Default); }
public void MakeActiveStyle(bool stackState = false) { if (!this.isActiveAndEnabled) { return; } if (_mode == UpdateMode.Motor) { if (stackState) { _motor.States.StackState(this); } else { _motor.States.ChangeState(this); } } else { _activeStatus = true; if (_routine == null || _routine.Finished) { _routine = this.StartRadicalCoroutine(this.SelfUpdateRoutine(), RadicalCoroutineDisableMode.Pauses); } else if (_routine.OperatingState == RadicalCoroutineOperatingState.Inactive) { _routine.Start(this, RadicalCoroutineDisableMode.Pauses); } } }
public void Add(T item) { if (item == null) { throw new System.ArgumentNullException("item"); } if (_components.Contains(item)) { return; } _components.Add(item); if (item.isActiveAndEnabled) { _liveComponents.Add(item); if (_liveComponents.Count == 1) { _currentMaster = _liveComponents[0]; if (_onUpdate != null) { _routine = _currentMaster.StartRadicalCoroutine(this.UpdateRoutine(), RadicalCoroutineDisableMode.CancelOnDisable); } } } }
public void Schedule(System.Action <ISPAnim> callback) { //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 (_endOfLineCallback == null) { _endOfLineCallback = new CallbackInfo() { timeout = float.PositiveInfinity } } ; _endOfLineCallback.callback += callback; if (_waitRoutine == null) { _waitRoutine = new RadicalCoroutine(this.DoUpdate()); //RadicalCoroutine.UpdateTicker(this.Update); } if (!_waitRoutine.Active) { _waitRoutine.Start(_state.Controller); } }
private void Init(RadicalCoroutine routine) { if (_state != OperationState.Inactive) { throw new InvalidOperationException("RadicalTask is already operating."); } _routine = routine; }
public static RadicalCoroutine StartRadicalCoroutine(this MonoBehaviour behaviour, System.Collections.IEnumerator routine) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (routine == null) throw new System.ArgumentNullException("routine"); var co = new RadicalCoroutine(routine); co.Start(behaviour); return co; }
public static RadicalCoroutine StartRadicalCoroutine(this MonoBehaviour behaviour, System.Func<System.Collections.IEnumerator> method, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (method == null) throw new System.ArgumentNullException("routine"); var co = new RadicalCoroutine(method()); co.Start(behaviour, disableMode); return co; }
protected override void OnTriggerActivate() { if (_routine != null) { _routine.Cancel(); _routine = null; } this.StartRadicalCoroutine(this.TickerCallback(), RadicalCoroutineDisableMode.CancelOnDisable); }
protected override void OnDisable() { base.OnDisable(); if (_routine != null) { _routine.Cancel(); _routine = null; } }
private void Purge() { if (_routine != null) { _routine.Cancel(); } _updateMovementCallback = null; _routine = null; }
public void Dispose() { if (_scheduler != null) { _scheduler.Dispose(); _scheduler = null; } _controller = null; _routine = null; }
public void Cancel() { if (_routine != null) { _routine.Cancel(); _routine = null; } this.SetSignal(); }
protected override void OnTriggerActivate() { if (_routine != null) { _routine.Cancel(); _routine = null; } _routine = this.StartRadicalCoroutine(this.TickerCallback(), RadicalCoroutineDisableMode.CancelOnDisable); }
private void AttemptAutoStart() { if (_signal == SignalMode.Auto && _trigger.Targets.Count > 0 && _trigger.Targets[0].Target != null) { var signal = _trigger.Targets[0].Target.GetComponentInChildren <IAutoSequenceSignal>(); if (signal != null) { _routine = this.StartRadicalCoroutine(this.DoAutoSequence(signal), RadicalCoroutineDisableMode.Pauses); } } }
private void OnCancelling(object sender, System.EventArgs e) { if (_routine == null) { return; } if (_onCancel != null && _routine.Cancelled) { _onCancel(); } _routine = null; }
/// <summary> /// Exit the current state, cancelling it, and firing the cancel callback. /// </summary> public void ExitState() { if (_disposed) { throw new System.InvalidOperationException("Object is disposed."); } if (_routine != null && _routine.Active) { _routine.Cancel(); _routine = null; } }
private void OnFinished(object sender, System.EventArgs e) { if (_routine == null) { return; } if (_onComplete != null && _routine.Complete) { _onComplete(); } _routine = null; }
private void OnCancelling(object sender, System.EventArgs e) { if (_disposed || _routine == null) { return; } if (_onCancel != null && GameLoopEntry.QuitState != QuitState.Quit && _routine.Cancelled) { _onCancel(); } _routine = null; }
public RadicalCoroutine StartRadicalCoroutineAsync(System.Func <System.Collections.IEnumerator> routine, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (routine == null) { throw new System.ArgumentNullException("routine"); } var co = new RadicalCoroutine(routine()); co.StartAsync(this, disableMode); return(co); }
public void Cancel() { if (_routine != null) { _routine.Cancel(); _routine = null; } this.InputResult = InputToken.Unknown; _state = State.Cancelled; this.SignalOnComplete(); }
/// <summary> /// Must be only called by RadicalCoroutine itself. /// </summary> /// <param name="routine"></param> internal void UnregisterCoroutine(RadicalCoroutine routine) { _routines.Remove(routine); if (_naiveTrackerTable != null) { var comp = routine.Operator; if (_naiveTrackerTable.ContainsKey(comp) && !this.GetComponentIsCurrentlyManaged(comp)) { _naiveTrackerTable.Remove(comp); } } }
public void Dispose() { if (_disposed) { return; } _disposed = true; if (_routine != null) { _routine.Cancel(); _routine = 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 (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 = new RadicalCoroutine(this.DoUpdate()); //RadicalCoroutine.UpdateTicker(this.Update); } if (!_waitRoutine.Active) { _waitRoutine.Start(_state.Controller); } }
public void Reset() { if (_routine != null) { _routine.Cancel(); _routine = null; } _currentIndex = 0; if (Application.isPlaying && this.enabled) { this.AttemptAutoStart(); } }
private void InitWaitRoutine() { _waitRoutine = new RadicalCoroutine(this.DoUpdate()); //RadicalCoroutine.UpdateTicker(this.Update); _waitRoutine.OnFinished += (s, e) => { if (object.ReferenceEquals(s, _waitRoutine)) { _waitRoutine = null; } _inUpdate = true; this.CloseOutAllEventCallbacks(); _inUpdate = false; }; }
public void StartSwap(Material mat, float duration) { if (duration <= 0f) { this.StopSwap(); return; } if (!this.enabled) this.enabled = true; if(_flashRoutine != null) { _flashRoutine.Cancel(); _flashRoutine = null; } if (_flashing) { //already started, just replace _renderer.sharedMaterial = mat; if (duration < float.PositiveInfinity) { _flashRoutine = this.InvokeRadical(this.StopSwap, duration); } } else { //start a new _matCache = _renderer.sharedMaterial; _renderer.sharedMaterial = mat; _flashing = true; if (duration < float.PositiveInfinity) { _flashRoutine = this.InvokeRadical(this.StopSwap, duration); } } }
private void Clear() { _state = OperationState.Inactive; _routine = null; _yieldObject = null; }
public override bool Trigger(object arg) { if (!this.CanTrigger) return false; var src = _targetAudioSource.GetTarget<AudioSource>(arg); if (src == null) { Debug.LogWarning("Failed to play audio due to a lack of AudioSource on the target.", this); return false; } if (src.isPlaying) { switch (this.Interrupt) { case InterruptMode.StopIfPlaying: if (_completeRoutine != null) _completeRoutine.Cancel(); _completeRoutine = null; src.Stop(); break; case InterruptMode.DoNotPlayIfPlaying: return false; } } var clip = _clips[Random.Range(0, _clips.Length)]; src.clip = clip; if (clip != null) { if (this._delay > 0) { this.Invoke(() => { if (src != null) { _completeRoutine = this.InvokeRadical(this.OnAudioComplete, clip.length); src.Play(); } }, this._delay); } else { _completeRoutine = this.InvokeRadical(this.OnAudioComplete, clip.length); src.Play(); } return true; } else { return false; } }
public static RadicalCoroutine StartRadicalCoroutineAsync(this MonoBehaviour behaviour, System.Collections.IEnumerable routine, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (routine == null) throw new System.ArgumentNullException("routine"); var co = new RadicalCoroutine(routine.GetEnumerator()); co.StartAsync(behaviour, disableMode); return co; }
public void Start(SceneManager manager, ISceneLoadOptions options, ISceneBehaviour lastScene) { _manager = manager; _options = options; _lastScene = lastScene; _routine = manager.StartRadicalCoroutine(this.DoLoad()); //GameLoopEntry.Hook.StartRadicalCoroutine(this.DoLoad(), RadicalCoroutineDisableMode.Default); }
public void StopSwap() { if (_flashing) { _renderer.sharedMaterial = _matCache; _matCache = null; _flashing = false; this.enabled = false; } if (_flashRoutine != null) { _flashRoutine.Cancel(); _flashRoutine = null; } }
private void Init(RadicalCoroutine routine) { if (_state != OperationState.Inactive) throw new InvalidOperationException("RadicalTask is already operating."); _routine = routine; }
public static RadicalCoroutine StartRadicalCoroutine(this MonoBehaviour behaviour, CoroutineMethod method) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (method == null) throw new System.ArgumentNullException("routine"); var co = new RadicalCoroutine(method().GetEnumerator()); co.Start(behaviour); return co; }
private void OnAudioComplete() { _completeRoutine = null; _onAudioComplete.ActivateTrigger(); }
public static RadicalCoroutine StartRadicalCoroutine(this MonoBehaviour behaviour, System.Delegate method, object[] args = null, RadicalCoroutineDisableMode disableMode = RadicalCoroutineDisableMode.Default) { if (behaviour == null) throw new System.ArgumentNullException("behaviour"); if (method == null) throw new System.ArgumentNullException("method"); System.Collections.IEnumerator e; if (com.spacepuppy.Utils.TypeUtil.IsType(method.Method.ReturnType, typeof(System.Collections.IEnumerable))) { e = (method.DynamicInvoke(args) as System.Collections.IEnumerable).GetEnumerator(); } else if (com.spacepuppy.Utils.TypeUtil.IsType(method.Method.ReturnType, typeof(System.Collections.IEnumerator))) { e = (method.DynamicInvoke(args) as System.Collections.IEnumerator); } else { throw new System.ArgumentException("Delegate must have a return type of IEnumerable or IEnumerator.", "method"); } var co = new RadicalCoroutine(e); co.Start(behaviour, disableMode); return co; }
public RadicalTask(RadicalCoroutine routine) { this.Init(routine); }
public static RadicalTask Create(RadicalCoroutine routine) { //TODO - possibly implment pooling system to reduce gc return new RadicalTask(routine); }