/// <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); } }
protected override void OnDisable() { base.OnDisable(); if (_routine != null) { _routine.Cancel(); _routine = null; } }
public void Reset() { if (_routine != null) { _routine.Cancel(); _routine = null; } _currentIndex = 0; if (Application.isPlaying && this.enabled) { this.AttemptAutoStart(); } }
private void Purge() { if (_routine != null) { _routine.Cancel(); } _updateMovementCallback = null; _routine = null; }
public void Cancel() { if (_routine != null) { _routine.Cancel(); _routine = null; } this.SetSignal(); }
public RadicalCoroutine ChangeState(IEnumerator routine, System.Action onCancel = null, System.Action onComplete = null) { if (routine == null) { throw new System.ArgumentNullException("routine"); } if (_routine != null) { _routine.Cancel(); } _onCancel = onCancel; _onComplete = onComplete; _routine = _handle.StartRadicalCoroutine(routine, _disableMode); _routine.OnCancelling += this.OnCancelling; _routine.OnFinished += this.OnFinished; return(_routine); }
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.Invoke(this.StopSwap, duration); } } else { //start a new _matCache = _renderer.sharedMaterial; _renderer.sharedMaterial = mat; _flashing = true; if (duration < float.PositiveInfinity) { _flashRoutine = this.Invoke(this.StopSwap, duration); } } }
public void Cancel() { if (_routine != null) { _routine.Cancel(); _routine = null; } this.InputResult = InputToken.Unknown; _state = State.Cancelled; this.SignalOnComplete(); }
private IEnumerator waitForFrameCancelledTest() { RadicalCoroutine coroutine = RadicalCoroutine.Create(testCoroutine(), "testCoroutine"); StartCoroutine(coroutine.Enumerator); coroutine.ECancelled += delegate { waitForFrameCancelled = true; }; coroutine.Cancel(); while (!coroutine.Disposed) { yield return(null); } IntegrationTestEx.FailIf(!waitForFrameCancelled, "ECancelled was not dispatched for cancelled coroutine."); }
public void UndoRagdoll() { if (!_ragdolled) { return; } if (_cachedController != null) { _cachedController.ChangeMover(_cachedMover); } else { this.SetJointsKinematic(true); this.SetCollidersEnabled(false); if (_falseJointCoroutine != null) { _falseJointCoroutine.Cancel(); } } var mecanim = this.GetComponent <Animator>(); if (mecanim != null) { mecanim.enabled = _mecanimEnabledCache; } var anim = this.GetComponent <Animator>(); if (anim != null) { anim.enabled = _animatorEnabledCache; } _cachedController = null; _cachedMover = null; _falseJointCoroutine = null; _mecanimEnabledCache = false; _animatorEnabledCache = false; _ragdolled = false; }
public T[] PopOldest(int count) { if (count > _liveComponents.Count) { throw new InvalidOperationException("Count is greater than number of live objects."); } T[] arr = new T[count]; for (int i = 0; i < count; i++) { arr[i] = _liveComponents[0]; _components.Remove(arr[i]); _liveComponents.RemoveAt(0); } if (arr.Contains(_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; } } return(arr); }
public override bool Trigger(object sender, 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 override bool Trigger(object sender, object arg) { if (!this.CanTrigger) { return(false); } var manager = Services.Get <IAudioManager>(); if (manager == null || manager.BackgroundAmbientAudioSource == null) { Debug.LogWarning("Failed to play audio due to a lack of AudioManager.", this); return(false); } var src = manager.BackgroundAmbientAudioSource; if (src.isPlaying) { switch (this.Interrupt) { case AudioInterruptMode.StopIfPlaying: if (_completeRoutine != null) { _completeRoutine.Cancel(); } _completeRoutine = null; src.Stop(); break; case AudioInterruptMode.DoNotPlayIfPlaying: return(false); case AudioInterruptMode.PlayOverExisting: //play one shot over existing audio break; } } 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(); src.PlayOneShot(clip); } }, this._delay); } else { _completeRoutine = this.InvokeRadical(this.OnAudioComplete, clip.length); //src.Play(); src.PlayOneShot(clip); } return(true); } else { return(false); } }
public void Stop() { _routine.Cancel(); }