Skip to content

Commit

Permalink
Allow ResetButtons to be moved
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JeffBail committed Apr 17, 2019
1 parent a95b4b4 commit bc131e8
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using HTC.UnityPlugin.ColliderEvent;
//========= Copyright 2016-2018, HTC Corporation. All rights reserved. ===========

using HTC.UnityPlugin.ColliderEvent;
using HTC.UnityPlugin.Utility;
using System.Collections.Generic;
using UnityEngine;
Expand Down Expand Up @@ -39,6 +41,13 @@ public ColliderButtonEventData.InputButton activeButton
}

private void Start()
{
CachePositions();
}

// Cache the positions of the effectTargets and of the buttonObject so they can be restored
// in OnColliderEventPressUp and OnColliderEventPressExit
private void CachePositions()
{
resetPoses = new RigidPose[effectTargets.Length];
for (int i = 0; i < effectTargets.Length; ++i)
Expand All @@ -48,6 +57,7 @@ private void Start()

buttonOriginPosition = buttonObject.position;
}

#if UNITY_EDITOR
protected virtual void OnValidate()
{
Expand Down Expand Up @@ -81,6 +91,7 @@ public void OnColliderEventPressEnter(ColliderButtonEventData eventData)
{
if (eventData.button == m_activeButton && pressingEvents.Add(eventData) && pressingEvents.Count == 1)
{
CachePositions();
buttonObject.position = buttonOriginPosition + buttonDownDisplacement;
}
}
Expand Down

0 comments on commit bc131e8

Please sign in to comment.