From 89c7de9e543b35f34ca27f11cbaefea9792a1e42 Mon Sep 17 00:00:00 2001 From: "Theston E. Fox" Date: Fri, 20 Jan 2017 16:02:24 +0000 Subject: [PATCH] fix(Interaction): set error if helper script not on interactable object The Interactable Object script has a couple of helper scripts such as Interact Haptics and Controller Appearance that need to be on the same GameObject as the Interactable Object. This fix throws a Log Error if they are attached to anything other than an Interactable Object. --- .../Interactions/VRTK_InteractControllerAppearance.cs | 10 +++++++++- .../VRTK/Scripts/Interactions/VRTK_InteractHaptics.cs | 10 +++++++++- DOCUMENTATION.md | 4 ++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/Assets/VRTK/Scripts/Interactions/VRTK_InteractControllerAppearance.cs b/Assets/VRTK/Scripts/Interactions/VRTK_InteractControllerAppearance.cs index 3c9b84da5..0b49c1657 100644 --- a/Assets/VRTK/Scripts/Interactions/VRTK_InteractControllerAppearance.cs +++ b/Assets/VRTK/Scripts/Interactions/VRTK_InteractControllerAppearance.cs @@ -4,7 +4,7 @@ namespace VRTK using UnityEngine; /// - /// The Interact Controller Appearance script is used to determine whether the controller model should be visible or hidden on touch, grab or use. + /// The Interact Controller Appearance script is attached on the same GameObject as an Interactable Object script and is used to determine whether the controller model should be visible or hidden on touch, grab or use. /// /// /// `VRTK/Examples/008_Controller_UsingAGrabbedObject` shows that the controller can be hidden when touching, grabbing and using an object. @@ -92,6 +92,14 @@ public void ToggleControllerOnUse(bool showController, VRTK_ControllerActions co } } + protected virtual void OnEnable() + { + if (!GetComponent()) + { + Debug.LogError("The `VRTK_InteractControllerAppearance` script is required to be attached to a GameObject that has the `VRTK_InteractableObject` script also attached to it."); + } + } + private void ToggleController(bool showController, VRTK_ControllerActions controllerActions, GameObject obj, float touchDelay) { if (showController) diff --git a/Assets/VRTK/Scripts/Interactions/VRTK_InteractHaptics.cs b/Assets/VRTK/Scripts/Interactions/VRTK_InteractHaptics.cs index 0e66200cc..0c13a0fa9 100644 --- a/Assets/VRTK/Scripts/Interactions/VRTK_InteractHaptics.cs +++ b/Assets/VRTK/Scripts/Interactions/VRTK_InteractHaptics.cs @@ -4,7 +4,7 @@ namespace VRTK using UnityEngine; /// - /// The Interact Haptics script is attached along side the Interactable Object script and provides controller haptics on touch, grab and use of the object. + /// The Interact Haptics script is attached on the same GameObject as an Interactable Object script and provides controller haptics on touch, grab and use of the object. /// public class VRTK_InteractHaptics : MonoBehaviour { @@ -73,6 +73,14 @@ public void HapticsOnUse(VRTK_ControllerActions controllerActions) } } + protected virtual void OnEnable() + { + if (!GetComponent()) + { + Debug.LogError("The `VRTK_InteractHaptics` script is required to be attached to a GameObject that has the `VRTK_InteractableObject` script also attached to it."); + } + } + private void TriggerHapticPulse(VRTK_ControllerActions controllerActions, float strength, float duration, float interval) { if (controllerActions) diff --git a/DOCUMENTATION.md b/DOCUMENTATION.md index 22ef3f99c..9b28a7fa7 100644 --- a/DOCUMENTATION.md +++ b/DOCUMENTATION.md @@ -2472,7 +2472,7 @@ The ForceResetUsing will force the controller to stop using the currently touche ### Overview -The Interact Haptics script is attached along side the Interactable Object script and provides controller haptics on touch, grab and use of the object. +The Interact Haptics script is attached on the same GameObject as an Interactable Object script and provides controller haptics on touch, grab and use of the object. ### Inspector Parameters @@ -2527,7 +2527,7 @@ The HapticsOnUse method triggers the haptic feedback on the given controller for ### Overview -The Interact Controller Appearance script is used to determine whether the controller model should be visible or hidden on touch, grab or use. +The Interact Controller Appearance script is attached on the same GameObject as an Interactable Object script and is used to determine whether the controller model should be visible or hidden on touch, grab or use. ### Inspector Parameters