Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Interaction): extract haptics out of interactable object
> ** Breaking Changes ** The haptic feedback on the interactable object has now been extracted into it's own script that performs the haptic feedback. This cleans up optional parameters on the interactable object and separates the responsibility of the operation into it's own script.
- Loading branch information
1 parent
5ddd1ef
commit 36c0f9d
Showing
8 changed files
with
202 additions
and
75 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
// Interact Haptics|Scripts|0192 | ||
namespace VRTK | ||
{ | ||
using UnityEngine; | ||
|
||
/// <summary> | ||
/// The Interact Haptics script is attached along side the Interactable Object script and provides controller haptics on touch, grab and use of the object. | ||
/// </summary> | ||
public class VRTK_InteractHaptics : MonoBehaviour | ||
{ | ||
[Header("Haptics On Touch")] | ||
[Tooltip("Denotes how strong the rumble in the controller will be on touch.")] | ||
[Range(0, 3999)] | ||
public ushort strengthOnTouch = 0; | ||
[Tooltip("Denotes how long the rumble in the controller will last on touch.")] | ||
public float durationOnTouch = 0f; | ||
[Tooltip("Denotes interval betweens rumble in the controller on touch.")] | ||
public float intervalOnTouch = minInterval; | ||
|
||
[Header("Haptics On Grab")] | ||
[Tooltip("Denotes how strong the rumble in the controller will be on grab.")] | ||
[Range(0, 3999)] | ||
public ushort strengthOnGrab = 0; | ||
[Tooltip("Denotes how long the rumble in the controller will last on grab.")] | ||
public float durationOnGrab = 0f; | ||
[Tooltip("Denotes interval betweens rumble in the controller on grab.")] | ||
public float intervalOnGrab = minInterval; | ||
|
||
[Header("Haptics On Use")] | ||
[Tooltip("Denotes how strong the rumble in the controller will be on use.")] | ||
[Range(0, 3999)] | ||
public ushort strengthOnUse = 0; | ||
[Tooltip("Denotes how long the rumble in the controller will last on use.")] | ||
public float durationOnUse = 0f; | ||
[Tooltip("Denotes interval betweens rumble in the controller on use.")] | ||
public float intervalOnUse = minInterval; | ||
|
||
private const float minInterval = 0.05f; | ||
|
||
/// <summary> | ||
/// The HapticsOnTouch method triggers the haptic feedback on the given controller for the settings associated with touch. | ||
/// </summary> | ||
/// <param name="controllerActions">The controller to activate the haptic feedback on.</param> | ||
public void HapticsOnTouch(VRTK_ControllerActions controllerActions) | ||
{ | ||
if (strengthOnTouch > 0 && durationOnTouch > 0f) | ||
{ | ||
TriggerHapticPulse(controllerActions, strengthOnTouch, durationOnTouch, intervalOnTouch); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The HapticsOnGrab method triggers the haptic feedback on the given controller for the settings associated with grab. | ||
/// </summary> | ||
/// <param name="controllerActions">The controller to activate the haptic feedback on.</param> | ||
public void HapticsOnGrab(VRTK_ControllerActions controllerActions) | ||
{ | ||
if (strengthOnTouch > 0 && durationOnTouch > 0f) | ||
{ | ||
TriggerHapticPulse(controllerActions, strengthOnGrab, durationOnGrab, intervalOnGrab); | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// The HapticsOnUse method triggers the haptic feedback on the given controller for the settings associated with use. | ||
/// </summary> | ||
/// <param name="controllerActions">The controller to activate the haptic feedback on.</param> | ||
public void HapticsOnUse(VRTK_ControllerActions controllerActions) | ||
{ | ||
if (strengthOnTouch > 0 && durationOnTouch > 0f) | ||
{ | ||
TriggerHapticPulse(controllerActions, strengthOnUse, durationOnUse, intervalOnUse); | ||
} | ||
} | ||
|
||
private void TriggerHapticPulse(VRTK_ControllerActions controllerActions, ushort strength, float duration, float interval) | ||
{ | ||
if (controllerActions) | ||
{ | ||
controllerActions.TriggerHapticPulse(strength, duration, (interval >= minInterval ? interval : minInterval)); | ||
} | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.