Interhaptics SDK for Unity 1.6
Loading...
Searching...
No Matches
EventHapticSource.cs
Go to the documentation of this file.
1/* ​
2* Copyright (c) 2023 Go Touch VR SAS. All rights reserved. ​
3* ​
4*/
5
6using UnityEngine;
7using System.Linq;
10using System.Collections.Generic;
11using System.Collections;
12
13namespace Interhaptics.Utils
14{
15 [AddComponentMenu("Interhaptics/EventHapticSource")]
19 public class EventHapticSource : Internal.HapticSource
20 {
22
23#region Lifecycle
24 protected override void Start()
25 {
26 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
27 base.Start();
28 }
29#endregion
30
34 public override void Play()
35 {
36 // Check if all HapticBodyParts have TargetIntensity set to 0, and if so, do not play.
37 if (hapticBodyParts.All(hbp => hbp.TargetIntensity == 0))
38 {
39 DebugMode("All TargetIntensity values are set to 0, not playing haptic effect.");
40 return; // Exit the method without playing.
41 }
42 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
43 base.Play();
44 }
45
49 public override void Stop()
50 {
51#if !UNITY_PS5 //PS5 platform needs this commented out, otherwise residual haptics and no haptic playback until provider update - TODO: remove this when PS5 provider is updated
52 base.Stop();
53 //RemoveTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
54#endif
55 }
56
57 // Use the base class's coroutine for looping. This is necessary to avoid multiple coroutines running at the same time.
58 public override void PlayEventVibration()
59 {
60 AddTarget(hapticBodyParts.Select(hapticBodyPart => new CommandData(Operator.Plus, hapticBodyPart.BodyPart, hapticBodyPart.Side)).ToList());
61 base.PlayEventVibration();
62 }
63 }
64}
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.
Haptic source that plays a haptic effect when triggered by an event. Plays the haptic effect on the s...
override void Start()
Initialize the haptic effect settings at the start of the game.
override void Play()
Plays the haptic effect on the specified body parts.
override void Stop()
Stops the haptic effect on the specified body parts.
override void PlayEventVibration()
Method to start the coroutine from outside (if necessary). Plays the haptic effect after the vibratio...
Operator
Enumeration for operator signs in haptic command data.
Structure for command data in haptic systems.