namespace Zinnia.Haptics { using UnityEngine; using Zinnia.Haptics.Collection; /// /// Processes each active in the given and can optionally cease after the first valid process. /// public class HapticProcessor : HapticProcess { [Tooltip("The HapticProcess collection to attempt to process.")] [SerializeField] private HapticProcessObservableList hapticProcesses; /// /// The collection to attempt to process. /// public HapticProcessObservableList HapticProcesses { get { return hapticProcesses; } set { hapticProcesses = value; } } [Tooltip("Whether to cease the processing of the collection after the first valid HapticProcess is processed.")] [SerializeField] private bool ceaseAfterFirstSourceProcessed = true; /// /// Whether to cease the processing of the collection after the first valid is processed. /// public bool CeaseAfterFirstSourceProcessed { get { return ceaseAfterFirstSourceProcessed; } set { ceaseAfterFirstSourceProcessed = value; } } /// /// The backing field for holding the value of . /// private HapticProcess activeHapticProcess; /// /// The current active being utilized. /// public virtual HapticProcess ActiveHapticProcess { get => activeHapticProcess != null && activeHapticProcess.IsActive() ? activeHapticProcess : null; protected set { activeHapticProcess = value; } } /// /// Starts the first active found. /// protected override void DoBegin() { ActiveHapticProcess = null; if (HapticProcesses == null) { return; } foreach (HapticProcess process in HapticProcesses.NonSubscribableElements) { if (process.IsActive()) { ActiveHapticProcess = process; if (CeaseAfterFirstSourceProcessed) { break; } else { ActiveHapticProcess.Begin(); } } } if (CeaseAfterFirstSourceProcessed && ActiveHapticProcess != null) { ActiveHapticProcess.Begin(); } } /// /// Cancels the current from running. /// protected override void DoCancel() { if (ActiveHapticProcess != null) { ActiveHapticProcess.Cancel(); } } } }