namespace Zinnia.Haptics { using UnityEngine; using Zinnia.Extension; /// /// The basis of a haptic process that can be started or cancelled. /// public abstract class HapticProcess : MonoBehaviour { /// /// The state of whether the is active. /// /// if the is considered active. public virtual bool IsActive() { return this.CheckIsActiveAndEnabled(); } /// /// Starts the haptic process. /// public virtual void Begin() { if (!IsActive()) { return; } DoBegin(); } /// /// Cancels the existing haptic process. /// public virtual void Cancel() { DoCancel(); } /// /// Cancels any existing haptic process and then starts a new one. /// public virtual void Restart() { Cancel(); Begin(); } /// /// Starts the haptic process. /// protected abstract void DoBegin(); /// /// Cancels the existing haptic process. /// protected abstract void DoCancel(); protected virtual void OnDisable() { Cancel(); } } }