// --------------------------------------------------------------------------------------------------------------------
//
// Copyright (c) VRMADA, All rights reserved.
//
// --------------------------------------------------------------------------------------------------------------------
using System;
using UnityEngine;
namespace UltimateXR.Haptics
{
///
/// Describes a haptic clip. It is possible to specify an audio clip whose wave will be used as a primary source for
/// the vibration, but also a secondary clip type that will be used if the device doesn't support audio clips as haptic
/// feedback.
/// If no audio clip is specified, the fallback clip type will always be used.
///
[Serializable]
public class UxrHapticClip
{
#region Inspector Properties/Serialized Fields
[SerializeField] private AudioClip _clip;
[SerializeField] [Range(0, 1)] private float _clipAmplitude = 1.0f;
[SerializeField] private UxrHapticMode _hapticMode = UxrHapticMode.Mix;
[SerializeField] private UxrHapticClipType _fallbackClipType = UxrHapticClipType.None;
[SerializeField] [Range(0, 1)] private float _fallbackAmplitude = 1.0f;
[SerializeField] private float _fallbackDurationSeconds = -1.0f;
#endregion
#region Public Types & Data
///
/// Gets or sets the primary to use as source for vibration. If the device does not support
/// audio
/// clips as sources or this value is null, will be used.
///
public AudioClip Clip
{
get => _clip;
set => _clip = value;
}
///
/// Gets or sets the amplitude to play . Valid range is [0.0, 1.0].
///
public float ClipAmplitude
{
get => _clipAmplitude;
set => _clipAmplitude = value;
}
///
/// Gets or sets whether to replace or mix the clip with any current haptic feedback being played.
///
public UxrHapticMode HapticMode
{
get => _hapticMode;
set => _hapticMode = value;
}
///
/// Gets or sets the fallback clip: A value from a pre-defined set of procedurally generated haptic feedback clips. It
/// will be
/// used if the current device can't play as haptics or is not assigned.
///
public UxrHapticClipType FallbackClipType
{
get => _fallbackClipType;
set => _fallbackClipType = value;
}
///
/// Gets or sets the amplitude to play the fallback clip (1.0f = use default).
///
public float FallbackAmplitude
{
get => _fallbackAmplitude;
set => _fallbackAmplitude = value;
}
///
/// Gets or sets the duration in seconds of the fallback clip (negative = use predefined).
///
public float FallbackDurationSeconds
{
get => _fallbackDurationSeconds;
set => _fallbackDurationSeconds = value;
}
#endregion
#region Constructors & Finalizer
///
/// Public constructor.
///
/// The audio clip
/// The fallback clip if the primary audio clip is null
/// The haptic mixing mode
/// The amplitude of the audio clip
/// The amplitude of the fallback clip
/// The duration in seconds of the fallback clip (negative = use predefined)
public UxrHapticClip(AudioClip clip = null,
UxrHapticClipType fallbackClipType = UxrHapticClipType.None,
UxrHapticMode hapticMode = UxrHapticMode.Mix,
float clipAmplitude = 1.0f,
float fallbackAmplitude = 1.0f,
float fallbackDurationSeconds = -1.0f)
{
Clip = clip;
FallbackClipType = fallbackClipType;
HapticMode = hapticMode;
ClipAmplitude = clipAmplitude;
FallbackAmplitude = fallbackAmplitude;
FallbackDurationSeconds = fallbackDurationSeconds;
}
#endregion
}
}