Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
Interhaptics.Utils.AudioHapticSource Class Reference
Inheritance diagram for Interhaptics.Utils.AudioHapticSource:
Interhaptics.Internal.HapticSource

Public Member Functions

override void Play ()
 Call this method to play the haptic effect.
 
override void Stop ()
 Call this method to stop the haptic effect.
 
override void PlayEventVibration ()
 Method to start the coroutine from outside (if necessary). Plays the haptic effect after the vibrationOffset.
 
override IEnumerator ControlVibration ()
 Controls the vibration perception based on the full length of the haptic material; stops any residual haptics which might come from the controller after the haptic playback length (made for platforms other than mobile)
 
- Public Member Functions inherited from Interhaptics.Internal.HapticSource
virtual void ApplyTargetIntensity ()
 
void ApplySourceIntensity ()
 Call this method to apply the source intensity.
 
void ApplyLooping (int loopValue)
 Call this method to apply the looping state.
 
void DebugMode (string debugMessage)
 Debug method to print messages in the console only when debugMode is enabled.
 
void AddTarget (List< HapticBodyMapping.CommandData > Target)
 Call this method to add a target to the haptic effect.
 
void RemoveTarget (List< HapticBodyMapping.CommandData > Target)
 Call this method to remove a target from the haptic effect.
 

Public Attributes

AudioSource audioSource
 
- Public Attributes inherited from Interhaptics.Internal.HapticSource
HapticMaterial hapticMaterial
 
bool useStreamingAssets = false
 
string hapticEffectStreamingAssetsPath
 
float vibrationOffset
 
bool debugMode
 
bool isLooping
 
int maxLoops = 1
 
float maxLoopTime = 10f
 
double targetIntensity = 1.0
 
bool playAtStart = false
 
bool isPlaying = false
 
double hapticEffectDuration = 0
 
Coroutine playingCoroutine = null
 
double loopStartTime = 0
 

Protected Member Functions

override void Awake ()
 Add the haptic effect file to the when the object is created. The haptic effect file can be in the StreamingAssets folder if the useStreamingAssets property is set to true.
 
override void Start ()
 Initialize the haptic effect settings at the start of the game.
 
- Protected Member Functions inherited from Interhaptics.Internal.HapticSource
virtual void Update ()
 Update the haptic effect settings at every frame.
 

Properties

bool PlayOnAwake [get, set]
 
- Properties inherited from Interhaptics.Internal.HapticSource
int HapticMaterialId [get, set]
 
float SourceIntensity [get, set]
 

Additional Inherited Members

- Static Public Attributes inherited from Interhaptics.Internal.HapticSource
const string ERROR_MESSAGE_MONO = "Interhaptics requires IL2CPP scripting backend for Android. Please change it in Player Settings. Haptics will not play on the Mono scripting backend on the Android platform."
 

Detailed Description

Definition at line 17 of file AudioHapticSource.cs.

Member Function Documentation

◆ Awake()

override void Interhaptics.Utils.AudioHapticSource.Awake ( )
protectedvirtual

Add the haptic effect file to the when the object is created. The haptic effect file can be in the StreamingAssets folder if the useStreamingAssets property is set to true.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 28 of file AudioHapticSource.cs.

29 {
30 if (audioSource == null && !TryGetComponent<AudioSource>(out audioSource))
31 {
32 Debug.LogError("AudioSource is not assigned, please assign one");
33 return;
34 }
35 base.Awake();
36 if (audioSource.playOnAwake)
37 {
38 audioSource.playOnAwake = false; // Prevent AudioSource from auto-playing
39 playAtStart = true; // Enable haptic effect to play on start and sync with audio
40 }
41 }

References Interhaptics.Utils.AudioHapticSource.audioSource, and Interhaptics.Internal.HapticSource.playAtStart.

◆ ControlVibration()

override IEnumerator Interhaptics.Utils.AudioHapticSource.ControlVibration ( )
virtual

Controls the vibration perception based on the full length of the haptic material; stops any residual haptics which might come from the controller after the haptic playback length (made for platforms other than mobile)

Returns

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 82 of file AudioHapticSource.cs.

83 {
84#if (!ENABLE_METAQUEST && !ENABLE_OPENXR && UNITY_ANDROID && !UNITY_EDITOR) || UNITY_IOS
85 yield return new WaitForSeconds(vibrationOffset);
86#endif
87 DebugMode(string.Format("Started playing haptics! + {0}", Time.time));
88 int loopsPlayed = 0;
89 float loopStartTime = Time.time;
90 float totalTimePlayed = 0f;
91 int maxComputedLoops = maxLoops > 0 ? maxLoops : int.MaxValue;
92
93 while (loopsPlayed < maxComputedLoops)
94 {
95 Play(); // Play audio and haptic effect
96 loopsPlayed++;
97 DebugMode($"Loop {loopsPlayed} start at {Time.time}");
98
99 // Wait for the haptic effect duration to finish before restarting
100 yield return new WaitForSeconds((float)hapticEffectDuration);
101 totalTimePlayed = Time.time - loopStartTime;
102
103 // Check if the maxLoops condition has been met
104 if (loopsPlayed >= maxComputedLoops)
105 {
106 DebugMode($"Max loops reached: {loopsPlayed} loops at {Time.time}");
107 break;
108 }
109 }
110 Stop(); // Stop audio and haptic effect
111 DebugMode($"Finished playing haptics at {Time.time} after {totalTimePlayed} seconds");
112 playingCoroutine = null;
113 }
void DebugMode(string debugMessage)
Debug method to print messages in the console only when debugMode is enabled.
override void Stop()
Call this method to stop the haptic effect.
override void Play()
Call this method to play the haptic effect.

References Interhaptics.Internal.HapticSource.DebugMode(), Interhaptics.Internal.HapticSource.hapticEffectDuration, Interhaptics.Internal.HapticSource.loopStartTime, Interhaptics.Internal.HapticSource.maxLoops, Interhaptics.Utils.AudioHapticSource.Play(), Interhaptics.Internal.HapticSource.playingCoroutine, Interhaptics.Utils.AudioHapticSource.Stop(), and Interhaptics.Internal.HapticSource.vibrationOffset.

Referenced by Interhaptics.Utils.AudioHapticSource.PlayEventVibration(), and Interhaptics.Utils.AudioHapticSource.Start().

◆ Play()

override void Interhaptics.Utils.AudioHapticSource.Play ( )
virtual

Call this method to play the haptic effect.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 58 of file AudioHapticSource.cs.

59 {
60 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
61 base.Play();
62 audioSource.Play();
63 }
void AddTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to add a target to the haptic effect.
Operator
Enumeration for operator signs in haptic command data.
Structure for command data in haptic systems.

References Interhaptics.Internal.HapticSource.AddTarget(), and Interhaptics.Utils.AudioHapticSource.audioSource.

Referenced by Interhaptics.Utils.AudioHapticSource.ControlVibration().

◆ PlayEventVibration()

override void Interhaptics.Utils.AudioHapticSource.PlayEventVibration ( )
virtual

Method to start the coroutine from outside (if necessary). Plays the haptic effect after the vibrationOffset.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 73 of file AudioHapticSource.cs.

74 {
75 if (playingCoroutine != null)
76 {
77 StopCoroutine(playingCoroutine);
78 }
79 playingCoroutine = StartCoroutine(ControlVibration());
80 }
override IEnumerator ControlVibration()
Controls the vibration perception based on the full length of the haptic material; stops any residual...

References Interhaptics.Utils.AudioHapticSource.ControlVibration(), and Interhaptics.Internal.HapticSource.playingCoroutine.

Referenced by Interhaptics.Platforms.GameInput.Samples.GameInputXInputHapticController.PlayAudioVibrationController(), and Interhaptics.Samples.AudioControlGUI.StartHaptics().

◆ Start()

override void Interhaptics.Utils.AudioHapticSource.Start ( )
protectedvirtual

Initialize the haptic effect settings at the start of the game.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 43 of file AudioHapticSource.cs.

44 {
45 if (playAtStart)
46 {
47 playAtStart = false; //so it doesn't play only vibration on start
48 }
49 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
50 base.Start();
51 if (switchedPlayAtStart)
52 {
53 playAtStart = true;
54 playingCoroutine = StartCoroutine(ControlVibration());
55 }
56 }

References Interhaptics.Internal.HapticSource.AddTarget(), Interhaptics.Utils.AudioHapticSource.ControlVibration(), Interhaptics.Internal.HapticSource.playAtStart, and Interhaptics.Internal.HapticSource.playingCoroutine.

◆ Stop()

override void Interhaptics.Utils.AudioHapticSource.Stop ( )
virtual

Call this method to stop the haptic effect.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 65 of file AudioHapticSource.cs.

66 {
67 base.Stop();
68 audioSource.Stop();
69 RemoveTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
70 }
void RemoveTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to remove a target from the haptic effect.

References Interhaptics.Utils.AudioHapticSource.audioSource, and Interhaptics.Internal.HapticSource.RemoveTarget().

Referenced by Interhaptics.Utils.AudioHapticSource.ControlVibration().

Member Data Documentation

◆ audioSource

Property Documentation

◆ PlayOnAwake

bool Interhaptics.Utils.AudioHapticSource.PlayOnAwake
getset

Definition at line 26 of file AudioHapticSource.cs.

26{ get { return playAtStart; } set { playAtStart = value; } }

The documentation for this class was generated from the following file: