Skip to content

Commit bc131e8

Browse files
committed
Allow ResetButtons to be moved
CachePositions() was created to allow the buttonObject and effectTargets position caches to be updated from OnColliderEventPressEnter. This allows the host of the ResetButton to be moved at runtime. If the cache is not updated the objects would end up getting moved to their start position in the scene after a button press. This is a fix for issue ViveSoftware#114.
1 parent a95b4b4 commit bc131e8

File tree

1 file changed

+12
-1
lines changed
  • Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts

1 file changed

+12
-1
lines changed

Assets/HTC.UnityPlugin/ViveInputUtility/Examples/5.ColliderEvent/Scripts/ResetButton.cs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
using HTC.UnityPlugin.ColliderEvent;
1+
//========= Copyright 2016-2018, HTC Corporation. All rights reserved. ===========
2+
3+
using HTC.UnityPlugin.ColliderEvent;
24
using HTC.UnityPlugin.Utility;
35
using System.Collections.Generic;
46
using UnityEngine;
@@ -39,6 +41,13 @@ public ColliderButtonEventData.InputButton activeButton
3941
}
4042

4143
private void Start()
44+
{
45+
CachePositions();
46+
}
47+
48+
// Cache the positions of the effectTargets and of the buttonObject so they can be restored
49+
// in OnColliderEventPressUp and OnColliderEventPressExit
50+
private void CachePositions()
4251
{
4352
resetPoses = new RigidPose[effectTargets.Length];
4453
for (int i = 0; i < effectTargets.Length; ++i)
@@ -48,6 +57,7 @@ private void Start()
4857

4958
buttonOriginPosition = buttonObject.position;
5059
}
60+
5161
#if UNITY_EDITOR
5262
protected virtual void OnValidate()
5363
{
@@ -81,6 +91,7 @@ public void OnColliderEventPressEnter(ColliderButtonEventData eventData)
8191
{
8292
if (eventData.button == m_activeButton && pressingEvents.Add(eventData) && pressingEvents.Count == 1)
8393
{
94+
CachePositions();
8495
buttonObject.position = buttonOriginPosition + buttonDownDisplacement;
8596
}
8697
}

0 commit comments

Comments
 (0)