7using System.Collections;
8using System.Collections.Generic;
15 [AddComponentMenu(
"Interhaptics/AudioHapticSource")]
16 [RequireComponent(typeof(AudioSource))]
24 private bool switchedPlayAtStart =
false;
32 Debug.LogError(
"AudioSource is not assigned, please assign one");
38 audioSource.playOnAwake =
false;
49 AddTarget(hapticBodyParts.Select(hapticBodyPart =>
new CommandData(
Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
51 if (switchedPlayAtStart)
58 public override void Play()
60 AddTarget(hapticBodyParts.Select(hapticBodyPart =>
new CommandData(
Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
65 public override void Stop()
84#if (!ENABLE_METAQUEST && !ENABLE_OPENXR && UNITY_ANDROID && !UNITY_EDITOR) || UNITY_IOS
87 DebugMode(
string.Format(
"Started playing haptics! + {0}", Time.time));
90 float totalTimePlayed = 0f;
93 while (loopsPlayed < maxComputedLoops)
97 DebugMode($
"Loop {loopsPlayed} start at {Time.time}");
104 if (loopsPlayed >= maxComputedLoops)
106 DebugMode($
"Max loops reached: {loopsPlayed} loops at {Time.time}");
111 DebugMode($
"Finished playing haptics at {Time.time} after {totalTimePlayed} seconds");
Coroutine playingCoroutine
void RemoveTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to remove a target from the haptic effect.
void DebugMode(string debugMessage)
Debug method to print messages in the console only when debugMode is enabled.
double hapticEffectDuration
void AddTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to add a target to the haptic effect.
override void PlayEventVibration()
Method to start the coroutine from outside (if necessary). Plays the haptic effect after the vibratio...
override void Stop()
Call this method to stop the haptic effect.
override void Start()
Initialize the haptic effect settings at the start of the game.
override void Play()
Call this method to play the haptic effect.
override IEnumerator ControlVibration()
Controls the vibration perception based on the full length of the haptic material; stops any residual...
override void Awake()
Add the haptic effect file to the when the object is created. The haptic effect file can be in the St...
Operator
Enumeration for operator signs in haptic command data.
Structure for command data in haptic systems.