namespace Zinnia.Tracking.Velocity { using System.Collections; using UnityEngine; using Zinnia.Extension; /// /// Derived from to apply artificial velocities to the by changing the properties. /// /// /// This applier uses coroutine. /// public class ArtificialVelocityApplier : ArtificialVelocityApplierProcess { /// /// The routine to handle the deceleration of the object based on the drag over time. /// protected Coroutine decelerationRoutine; /// public override void Apply() { if (!this.IsValidState()) { return; } CancelDeceleration(); canProcess = true; decelerationRoutine = StartCoroutine(BeginDeceleration()); } /// /// Cancels the . /// public override void CancelDeceleration() { base.CancelDeceleration(); if (decelerationRoutine != null) { StopCoroutine(decelerationRoutine); decelerationRoutine = null; } } /// /// Begins decelerating the based on any opposing drag forces. /// /// An Enumerator to manage the running state of the Coroutine. protected virtual IEnumerator BeginDeceleration() { while (canProcess) { Process(); yield return null; } decelerationRoutine = null; } } }