namespace Zinnia.Haptics
{
using System.Collections;
using UnityEngine;
///
/// Creates a haptic pattern based on a custom routine and utilizes a to create the effect.
///
public abstract class RoutineHapticPulser : HapticProcess
{
[Tooltip("The pulse process to utilize.")]
[SerializeField]
private HapticPulser hapticPulser;
///
/// The pulse process to utilize.
///
public HapticPulser HapticPulser
{
get
{
return hapticPulser;
}
set
{
hapticPulser = value;
}
}
[Tooltip("Multiplies the current audio peak to affect the wave intensity.")]
[SerializeField]
private float intensityMultiplier = 1f;
///
/// Multiplies the current audio peak to affect the wave intensity.
///
public float IntensityMultiplier
{
get
{
return intensityMultiplier;
}
set
{
intensityMultiplier = value;
}
}
///
/// A reference to the started routine.
///
protected Coroutine hapticRoutine;
///
/// The original intensity of to reset back to after the process is complete.
///
protected float cachedIntensity;
///
public override bool IsActive()
{
return base.IsActive() && HapticPulser != null && HapticPulser.IsActive();
}
///
protected override void DoBegin()
{
cachedIntensity = HapticPulser.Intensity;
hapticRoutine = StartCoroutine(HapticProcessRoutine());
}
///
protected override void DoCancel()
{
if (hapticRoutine == null)
{
return;
}
StopCoroutine(hapticRoutine);
hapticRoutine = null;
HapticPulser.Cancel();
ResetIntensity();
}
///
/// Resets the back to its original value.
///
protected virtual void ResetIntensity()
{
HapticPulser.Intensity = cachedIntensity;
}
///
/// A custom routine to generate a haptic pattern.
///
/// An Enumerator to manage the running of the Coroutine.
protected abstract IEnumerator HapticProcessRoutine();
}
}