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

Public Member Functions

bool InitializeParametricHapticSource ()
 
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.
 
- 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.
 
virtual 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 Attributes

bool useAmplitude
 
TimeValuePair[] timeAmplitudePairs
 
bool usePitch
 
TimeValuePair[] timePitchPairs
 
bool useTransients
 
TimeAmplitudeFrequencyTriplet[] timeAmplitudeFrequencyTriplets
 
HapticBodyPart[] hapticBodyParts
 
- 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.
 

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."
 
- Properties inherited from Interhaptics.Internal.HapticSource
int HapticMaterialId [get, set]
 
float SourceIntensity [get, set]
 

Detailed Description

Definition at line 34 of file ParametricHapticSource.cs.

Member Function Documentation

◆ Awake()

override void Interhaptics.Utils.ParametricHapticSource.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 80 of file ParametricHapticSource.cs.

81 {
82 // Custom initialization for ParametricHapticSource. Bypasses adding a haptic effect
83#if UNITY_ANDROID
84 if (HapticManager.MonoScriptingBackend)
85 {
86 DebugMode(ERROR_MESSAGE_MONO + "Haptic Source");
87 return;
88 }
89 else
90 {
91 DebugMode("IL2CPP Haptic Source");
92 }
93#endif
94 }
void DebugMode(string debugMessage)
Debug method to print messages in the console only when debugMode is enabled.

References Interhaptics.Internal.HapticSource.DebugMode(), and Interhaptics.Internal.HapticSource.ERROR_MESSAGE_MONO.

◆ InitializeParametricHapticSource()

bool Interhaptics.Utils.ParametricHapticSource.InitializeParametricHapticSource ( )

Definition at line 109 of file ParametricHapticSource.cs.

110 {
111 bool initializationSuccess = true;
112
113 // Convert the custom class data to arrays suitable for AddParametricEffect
114 amplitude = useAmplitude ? timeAmplitudePairs.SelectMany(pair => new double[] { pair.time, pair.value }).ToArray() : null;
115 pitch = usePitch ? timePitchPairs.SelectMany(pair => new double[] { pair.time, pair.value }).ToArray() : null;
116 transients = useTransients ? timeAmplitudeFrequencyTriplets.SelectMany(triplet => new double[] { triplet.time, triplet.amplitude, triplet.frequency }).ToArray() : null;
117
118 // Now you can call AddParametricEffect with the converted arrays
119 HapticMaterialId = HAR.AddParametricEffect(
120 amplitude, amplitude?.Length ?? 0,
121 pitch, pitch?.Length ?? 0,
122 freqMin, freqMax,
123 transients, transients?.Length ?? 0,
125 );
126
127 // Check if the ID is valid
128 if (HapticMaterialId == -1)
129 {
130 DebugMode("Failed to create parametric haptic effect.");
131 initializationSuccess = false;
132 }
133 else
134 {
135 DebugMode("Parametric haptic effect created with ID: " + HapticMaterialId);
136 }
137 return initializationSuccess;
138 }
TimeAmplitudeFrequencyTriplet[] timeAmplitudeFrequencyTriplets

References Interhaptics.Internal.HapticSource.DebugMode(), Interhaptics.Internal.HapticSource.HapticMaterialId, Interhaptics.Internal.HapticSource.isLooping, Interhaptics.Utils.ParametricHapticSource.timeAmplitudeFrequencyTriplets, Interhaptics.Utils.ParametricHapticSource.timeAmplitudePairs, Interhaptics.Utils.ParametricHapticSource.timePitchPairs, Interhaptics.Utils.ParametricHapticSource.useAmplitude, Interhaptics.Utils.ParametricHapticSource.usePitch, and Interhaptics.Utils.ParametricHapticSource.useTransients.

Referenced by Interhaptics.Utils.ParametricHapticSource.Start().

◆ Play()

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

Call this method to play the haptic effect.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 141 of file ParametricHapticSource.cs.

142 {
143 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
144 base.Play();
145 }
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.ParametricHapticSource.hapticBodyParts.

◆ PlayEventVibration()

override void Interhaptics.Utils.ParametricHapticSource.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 151 of file ParametricHapticSource.cs.

152 {
153 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
154 base.PlayEventVibration();
155 }

References Interhaptics.Internal.HapticSource.AddTarget(), and Interhaptics.Utils.ParametricHapticSource.hapticBodyParts.

◆ Start()

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

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

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 95 of file ParametricHapticSource.cs.

96 {
97 // Initialize the parametric haptic effect with the vector data
99 base.Start();
100 }

References Interhaptics.Utils.ParametricHapticSource.InitializeParametricHapticSource().

◆ Stop()

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

Call this method to stop the haptic effect.

Reimplemented from Interhaptics.Internal.HapticSource.

Definition at line 146 of file ParametricHapticSource.cs.

147 {
148 base.Stop();
149 }

Member Data Documentation

◆ hapticBodyParts

HapticBodyPart [] Interhaptics.Utils.ParametricHapticSource.hapticBodyParts

◆ timeAmplitudeFrequencyTriplets

TimeAmplitudeFrequencyTriplet [] Interhaptics.Utils.ParametricHapticSource.timeAmplitudeFrequencyTriplets

◆ timeAmplitudePairs

TimeValuePair [] Interhaptics.Utils.ParametricHapticSource.timeAmplitudePairs

◆ timePitchPairs

TimeValuePair [] Interhaptics.Utils.ParametricHapticSource.timePitchPairs

◆ useAmplitude

bool Interhaptics.Utils.ParametricHapticSource.useAmplitude

◆ usePitch

bool Interhaptics.Utils.ParametricHapticSource.usePitch

◆ useTransients

bool Interhaptics.Utils.ParametricHapticSource.useTransients

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