7using System.Collections.Generic;
10using System.Collections;
16 [AddComponentMenu(
"Interhaptics/HapticSource")]
19 [Header(
"Haptic Effect File")]
22 [Tooltip(
"Use the StreamingAssets path to load the haptic effect file.")]
26 [Tooltip(
"Path to the haptic effect file in the StreamingAssets folder.")]
28 [Header(
"Haptic Source Settings")]
31 private float sourceIntensity = 1.0f;
32 [Tooltip(
"Indicates the delay before playing the vibration.")]
35 private float textureOffset;
36 private float stiffnessOffset;
39 [Tooltip(
"Indicates whether the effect should loop.")]
42 [ConditionalHide(
"isLooping",
true)]
43 [Tooltip(
"Maximum number of loops")]
46 [ConditionalHide(
"isLooping",
true)]
47 [Tooltip(
"Maximum time for loops")]
57 private float currentSourceIntensity;
64 public 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.";
73 get => sourceIntensity;
76 sourceIntensity = value;
77 DebugMode(
"Source intensity set to: " + sourceIntensity);
89 if (HapticManager.MonoScriptingBackend)
118 DebugMode(
"No haptic effect provided. Please assign a HapticMaterial in the inspector or provide a path to a haptic effect file in the StreamingAssets directory.");
129 currentSourceIntensity = sourceIntensity;
167 if (sourceIntensity != currentSourceIntensity)
170 currentSourceIntensity = sourceIntensity;
171 DebugMode(
"Source intensity changed to: " + sourceIntensity);
194 DebugMode(
"Applied looping: " + loopValue);
206 Debug.Log(debugMessage);
226#if (UNITY_ANDROID && !ENABLE_METAQUEST) || UNITY_IOS && !UNITY_EDITOR
240 public void AddTarget(List<HapticBodyMapping.CommandData> Target)
258#if (!ENABLE_METAQUEST && !ENABLE_OPENXR && UNITY_ANDROID && !UNITY_EDITOR) || UNITY_IOS
265 DebugMode($
"Finished playing haptics at {Time.time} after {totalTimePlayed} seconds");
281 DebugMode(
string.Format(
"Started playing haptics! + {0}", Time.time));
289 float effectStartTime = Time.time;
290 float effectEndTime = effectStartTime +
maxLoopTime;
295 while (Time.time < effectEndTime)
300 DebugMode($
"Stopped playing haptics at {Time.time} after reaching max loop time of {maxLoopTime} seconds");
Represents a haptic material, which is a ScriptableObject in Unity. This class is used to handle hapt...
virtual void Update()
Update the haptic effect settings at every frame.
Coroutine playingCoroutine
HapticMaterial hapticMaterial
virtual void ApplyTargetIntensity()
string hapticEffectStreamingAssetsPath
virtual void Start()
Initialize the haptic effect settings at the start of the game.
virtual void PlayEventVibration()
Method to start the coroutine from outside (if necessary). Plays the haptic effect after the vibratio...
virtual void Play()
Call this method to play the haptic effect.
virtual IEnumerator ControlVibration()
Controls the vibration perception based on the full length of the haptic material; stops any residual...
void RemoveTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to remove a target from the haptic effect.
const string ERROR_MESSAGE_MONO
virtual void Awake()
Add the haptic effect file to the when the object is created. The haptic effect file can be in the St...
void DebugMode(string debugMessage)
Debug method to print messages in the console only when debugMode is enabled.
virtual void Stop()
Call this method to stop the haptic effect.
double hapticEffectDuration
void AddTarget(List< HapticBodyMapping.CommandData > Target)
Call this method to add a target to the haptic effect.
void ApplySourceIntensity()
Call this method to apply the source intensity.
void ApplyLooping(int loopValue)
Call this method to apply the looping state.