From 8d1bb04b71242980662385c8fa740a863bec497a Mon Sep 17 00:00:00 2001 From: Jeff Bail Date: Fri, 26 Apr 2019 11:30:55 -0400 Subject: [PATCH] Cache reset poses so effectTargets maintain position If the effectTargets are moved after the application is running when OnColliderEventPressUp restores the positions from resetPoses back into the effectTargets they'll get restored back to their original position in the scene instead of their updated positions. Called CacheResetPoses() from OnColliderEventPressEnter to update the cache so the restore works properly. --- .../Examples/5.ColliderEvent/Scripts/ResetButton.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts/ResetButton.cs b/Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts/ResetButton.cs index f393f33d..07257573 100644 --- a/Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts/ResetButton.cs +++ b/Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts/ResetButton.cs @@ -37,6 +37,12 @@ public ColliderButtonEventData.InputButton activeButton } private void Start() + { + CacheResetPoses(); + } + + // Updates the resetPoses with the current effectTarget poses + private void CacheResetPoses() { resetPoses = new RigidPose[effectTargets.Length]; for (int i = 0; i < effectTargets.Length; ++i) @@ -44,6 +50,7 @@ private void Start() resetPoses[i] = new RigidPose(effectTargets[i]); } } + #if UNITY_EDITOR protected virtual void OnValidate() { @@ -77,6 +84,7 @@ public void OnColliderEventPressEnter(ColliderButtonEventData eventData) { if (eventData.button == m_activeButton && pressingEvents.Add(eventData) && pressingEvents.Count == 1) { + CacheResetPoses(); buttonObject.localPosition += buttonDownDisplacement; } }