-
Notifications
You must be signed in to change notification settings - Fork 85
Expand file tree
/
Copy pathResetButton.cs
More file actions
99 lines (89 loc) · 3.03 KB
/
ResetButton.cs
File metadata and controls
99 lines (89 loc) · 3.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using HTC.UnityPlugin.ColliderEvent;
using HTC.UnityPlugin.Utility;
using System.Collections.Generic;
using UnityEngine;
public class ResetButton : MonoBehaviour
, IColliderEventPressUpHandler
, IColliderEventPressEnterHandler
, IColliderEventPressExitHandler
{
public Transform[] effectTargets;
public Transform buttonObject;
public Vector3 buttonDownDisplacement;
[SerializeField]
private ColliderButtonEventData.InputButton m_activeButton = ColliderButtonEventData.InputButton.Trigger;
private RigidPose[] resetPoses;
private HashSet<ColliderButtonEventData> pressingEvents = new HashSet<ColliderButtonEventData>();
public ColliderButtonEventData.InputButton activeButton
{
get
{
return m_activeButton;
}
set
{
m_activeButton = value;
// set all child MaterialChanger heighlightButton to value;
var changers = ListPool<MaterialChanger>.Get();
GetComponentsInChildren(changers);
for (int i = changers.Count - 1; i >= 0; --i) { changers[i].heighlightButton = value; }
ListPool<MaterialChanger>.Release(changers);
}
}
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)
{
resetPoses[i] = new RigidPose(effectTargets[i]);
}
}
#if UNITY_EDITOR
protected virtual void OnValidate()
{
activeButton = m_activeButton;
}
#endif
public void OnColliderEventPressUp(ColliderButtonEventData eventData)
{
if (pressingEvents.Contains(eventData) && pressingEvents.Count == 1)
{
for (int i = 0; i < effectTargets.Length; ++i)
{
var rigid = effectTargets[i].GetComponent<Rigidbody>();
if (rigid != null)
{
rigid.MovePosition(resetPoses[i].pos);
rigid.MoveRotation(resetPoses[i].rot);
rigid.velocity = Vector3.zero;
//rigid.angularVelocity = Vector3.zero;
}
else
{
effectTargets[i].position = resetPoses[i].pos;
effectTargets[i].rotation = resetPoses[i].rot;
}
}
}
}
public void OnColliderEventPressEnter(ColliderButtonEventData eventData)
{
if (eventData.button == m_activeButton && pressingEvents.Add(eventData) && pressingEvents.Count == 1)
{
CacheResetPoses();
buttonObject.localPosition += buttonDownDisplacement;
}
}
public void OnColliderEventPressExit(ColliderButtonEventData eventData)
{
if (pressingEvents.Remove(eventData) && pressingEvents.Count == 0)
{
buttonObject.localPosition -= buttonDownDisplacement;
}
}
}