Skip to content

Commit 408fe51

Browse files
committed
Version 1.3b08 SteamVR_Input is no longer a component. Persists scenes
* SteamVR_Input_References has been moved to the generated folder so new plugin updates don't wipe yours. Prior beta users: Please delete your existing one in Assets/SteamVR/Resources/SteamVR_Input_References.asset * SteamVR_Input is no longer a MonoBehaviour. This fixes scene transition issues as well as event subscription issues. * The Live Action View has been moved to its own window under the Window menu. * Some excess configuration options were removed from the settings window, some were moved into SteamVR_Settings if still needed. * Added a Hover Button that depresses when the controller gets close to it. * Fixed an issue where default throwables would "auto catch" objects
1 parent 4f361cd commit 408fe51

36 files changed

+1349
-775
lines changed

Assets/SteamVR/Input/Editor/SteamVR_Input_Editor.cs

Lines changed: 104 additions & 167 deletions
Original file line numberDiff line numberDiff line change
@@ -13,24 +13,22 @@
1313
using System;
1414
using UnityEditorInternal;
1515

16-
[CustomEditor(typeof(SteamVR_Input))]
17-
public class SteamVR_Input_Editor : Editor
16+
public class SteamVR_Input_LiveWindow : EditorWindow
1817
{
19-
private const string liveUpdateKey = "SteamVR_Input_LiveUpdates";
18+
private GUIStyle labelStyle;
2019

21-
private double lastOnSceneGUI;
20+
[MenuItem("Window/SteamVR Input Live View")]
21+
public static void ShowWindow()
22+
{
23+
GetWindow<SteamVR_Input_LiveWindow>(false, "SteamVR Input Live View", true);
24+
}
2225

23-
void OnSceneGUI()
26+
void OnInspectorUpdate()
2427
{
2528
Repaint();
26-
lastOnSceneGUI = EditorApplication.timeSinceStartup;
2729
}
2830

29-
private GUIStyle labelStyle;
30-
31-
private bool? liveUpdate;
32-
33-
public override void OnInspectorGUI()
31+
void OnGUI()
3432
{
3533
if (labelStyle == null)
3634
{
@@ -40,184 +38,123 @@ public override void OnInspectorGUI()
4038

4139
Color defaultColor = GUI.backgroundColor;
4240

43-
if (liveUpdate == null)
41+
SteamVR_Input_ActionSet[] actionSets = SteamVR_Input.actionSets;
42+
if (actionSets == null)
43+
actionSets = SteamVR_Input_References.instance.actionSetObjects;
44+
45+
SteamVR_Input_Input_Sources[] sources = SteamVR_Input_Input_Source.GetUpdateSources();
46+
for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++)
4447
{
45-
if (EditorPrefs.HasKey(liveUpdateKey))
46-
liveUpdate = EditorPrefs.GetBool(liveUpdateKey);
47-
else
48-
liveUpdate = true;
49-
}
48+
SteamVR_Input_Input_Sources source = sources[sourceIndex];
49+
EditorGUILayout.LabelField(source.ToString());
5050

51-
bool newLiveUpdate = EditorGUILayout.Toggle("Live view of input action states", liveUpdate.Value);
51+
for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++)
52+
{
53+
SteamVR_Input_ActionSet set = actionSets[actionSetIndex];
54+
string activeText = set.IsActive() ? "Active" : "Inactive";
55+
float setLastChanged = set.GetTimeLastChanged();
5256

53-
if (liveUpdate.Value != newLiveUpdate)
54-
{
55-
liveUpdate = newLiveUpdate;
56-
EditorPrefs.SetBool(liveUpdateKey, newLiveUpdate);
57-
}
57+
if (setLastChanged != -1)
58+
{
59+
float timeSinceLastChanged = Time.time - setLastChanged;
60+
if (timeSinceLastChanged < 1)
61+
{
62+
Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged);
63+
GUI.backgroundColor = setColor;
64+
}
65+
}
5866

59-
bool sceneViewOpen = ((EditorApplication.timeSinceStartup - lastOnSceneGUI) < 0.5f);
67+
EditorGUILayout.LabelField(set.GetShortName(), activeText, labelStyle);
68+
GUI.backgroundColor = defaultColor;
6069

61-
if (Application.isPlaying == false)
62-
{
63-
bool showSettings = GUILayout.Button("SteamVR Settings");
70+
EditorGUI.indentLevel++;
6471

65-
if (showSettings)
66-
{
67-
Selection.activeObject = SteamVR_Settings.instance;
68-
}
69-
}
70-
else if (liveUpdate.Value)
71-
{
72-
if (sceneViewOpen)
73-
{
74-
SteamVR_Input_Input_Sources[] sources = SteamVR_Input_Input_Source.GetUpdateSources();
75-
for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++)
72+
for (int actionIndex = 0; actionIndex < set.allActions.Length; actionIndex++)
7673
{
77-
SteamVR_Input_Input_Sources source = sources[sourceIndex];
78-
EditorGUILayout.LabelField(source.ToString());
79-
80-
for (int actionSetIndex = 0; actionSetIndex < SteamVR_Input.actionSets.Length; actionSetIndex++)
74+
SteamVR_Input_Action action = set.allActions[actionIndex];
75+
76+
if (action.actionSet == null || action.actionSet.IsActive() == false)
8177
{
82-
SteamVR_Input_ActionSet set = SteamVR_Input.actionSets[actionSetIndex];
83-
string activeText = set.IsActive() ? "Active" : "Inactive";
84-
float setLastChanged = set.GetTimeLastChanged();
78+
EditorGUILayout.LabelField(action.GetShortName(), "-", labelStyle);
79+
continue;
80+
}
8581

86-
if (setLastChanged != -1)
87-
{
88-
float timeSinceLastChanged = Time.time - setLastChanged;
89-
if (timeSinceLastChanged < 1)
90-
{
91-
Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged);
92-
GUI.backgroundColor = setColor;
93-
}
94-
}
82+
float actionLastChanged = action.GetTimeLastChanged(source);
9583

96-
EditorGUILayout.LabelField(set.GetShortName(), activeText, labelStyle);
97-
GUI.backgroundColor = defaultColor;
84+
string actionText = "";
9885

99-
EditorGUI.indentLevel++;
86+
float timeSinceLastChanged = -1;
87+
88+
if (actionLastChanged != -1)
89+
{
90+
timeSinceLastChanged = Time.time - actionLastChanged;
10091

101-
for (int actionIndex = 0; actionIndex < set.allActions.Length; actionIndex++)
92+
if (timeSinceLastChanged < 1)
10293
{
103-
SteamVR_Input_Action action = set.allActions[actionIndex];
104-
105-
float actionLastChanged = action.GetTimeLastChanged(source);
106-
107-
string actionText = "";
108-
109-
float timeSinceLastChanged = -1;
110-
111-
if (actionLastChanged != -1)
112-
{
113-
timeSinceLastChanged = Time.time - actionLastChanged;
114-
115-
if (timeSinceLastChanged < 1)
116-
{
117-
Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged);
118-
GUI.backgroundColor = setColor;
119-
}
120-
}
121-
122-
123-
if (action is SteamVR_Input_Action_Boolean)
124-
{
125-
SteamVR_Input_Action_Boolean actionBoolean = (SteamVR_Input_Action_Boolean)action;
126-
actionText = actionBoolean.GetState(source).ToString();
127-
}
128-
else if (action is SteamVR_Input_Action_Single)
129-
{
130-
SteamVR_Input_Action_Single actionSingle = (SteamVR_Input_Action_Single)action;
131-
actionText = actionSingle.GetAxis(source).ToString("0.0000");
132-
}
133-
else if (action is SteamVR_Input_Action_Vector2)
134-
{
135-
SteamVR_Input_Action_Vector2 actionVector2 = (SteamVR_Input_Action_Vector2)action;
136-
actionText = string.Format("({0:0.0000}, {1:0.0000})", actionVector2.GetAxis(source).x, actionVector2.GetAxis(source).y);
137-
}
138-
else if (action is SteamVR_Input_Action_Vector3)
139-
{
140-
SteamVR_Input_Action_Vector3 actionVector3 = (SteamVR_Input_Action_Vector3)action;
141-
Vector3 axis = actionVector3.GetAxis(source);
142-
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000})", axis.x, axis.y, axis.z);
143-
}
144-
else if (action is SteamVR_Input_Action_Pose)
145-
{
146-
SteamVR_Input_Action_Pose actionPose = (SteamVR_Input_Action_Pose)action;
147-
Vector3 position = actionPose.GetLocalPosition(source);
148-
Quaternion rotation = actionPose.GetLocalRotation(source);
149-
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})",
150-
position.x, position.y, position.z,
151-
rotation.x, rotation.y, rotation.z, rotation.w);
152-
}
153-
else if (action is SteamVR_Input_Action_Skeleton)
154-
{
155-
SteamVR_Input_Action_Skeleton actionSkeleton = (SteamVR_Input_Action_Skeleton)action;
156-
Vector3 position = actionSkeleton.GetLocalPosition(source);
157-
Quaternion rotation = actionSkeleton.GetLocalRotation(source);
158-
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})",
159-
position.x, position.y, position.z,
160-
rotation.x, rotation.y, rotation.z, rotation.w);
161-
}
162-
else if (action is SteamVR_Input_Action_Vibration)
163-
{
164-
//SteamVR_Input_Action_Vibration actionVibration = (SteamVR_Input_Action_Vibration)action;
165-
166-
if (timeSinceLastChanged == -1)
167-
actionText = "never used";
168-
169-
actionText = string.Format("{0:0} seconds since last used", timeSinceLastChanged);
170-
}
171-
172-
EditorGUILayout.LabelField(action.GetShortName(), actionText, labelStyle);
173-
GUI.backgroundColor = defaultColor;
94+
Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged);
95+
GUI.backgroundColor = setColor;
17496
}
175-
176-
EditorGUILayout.Space();
17797
}
17898

17999

180-
EditorGUI.indentLevel--;
181-
}
182-
}
183-
else
184-
{
185-
EditorGUILayout.LabelField("Scene view must be visible for live view to function.");
186-
}
187-
}
188-
else
189-
{
190-
EditorGUILayout.LabelField("Live view of action states is disabled.");
191-
}
192-
}
100+
if (action is SteamVR_Input_Action_Boolean)
101+
{
102+
SteamVR_Input_Action_Boolean actionBoolean = (SteamVR_Input_Action_Boolean)action;
103+
actionText = actionBoolean.GetState(source).ToString();
104+
}
105+
else if (action is SteamVR_Input_Action_Single)
106+
{
107+
SteamVR_Input_Action_Single actionSingle = (SteamVR_Input_Action_Single)action;
108+
actionText = actionSingle.GetAxis(source).ToString("0.0000");
109+
}
110+
else if (action is SteamVR_Input_Action_Vector2)
111+
{
112+
SteamVR_Input_Action_Vector2 actionVector2 = (SteamVR_Input_Action_Vector2)action;
113+
actionText = string.Format("({0:0.0000}, {1:0.0000})", actionVector2.GetAxis(source).x, actionVector2.GetAxis(source).y);
114+
}
115+
else if (action is SteamVR_Input_Action_Vector3)
116+
{
117+
SteamVR_Input_Action_Vector3 actionVector3 = (SteamVR_Input_Action_Vector3)action;
118+
Vector3 axis = actionVector3.GetAxis(source);
119+
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000})", axis.x, axis.y, axis.z);
120+
}
121+
else if (action is SteamVR_Input_Action_Pose)
122+
{
123+
SteamVR_Input_Action_Pose actionPose = (SteamVR_Input_Action_Pose)action;
124+
Vector3 position = actionPose.GetLocalPosition(source);
125+
Quaternion rotation = actionPose.GetLocalRotation(source);
126+
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})",
127+
position.x, position.y, position.z,
128+
rotation.x, rotation.y, rotation.z, rotation.w);
129+
}
130+
else if (action is SteamVR_Input_Action_Skeleton)
131+
{
132+
SteamVR_Input_Action_Skeleton actionSkeleton = (SteamVR_Input_Action_Skeleton)action;
133+
Vector3 position = actionSkeleton.GetLocalPosition(source);
134+
Quaternion rotation = actionSkeleton.GetLocalRotation(source);
135+
actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})",
136+
position.x, position.y, position.z,
137+
rotation.x, rotation.y, rotation.z, rotation.w);
138+
}
139+
else if (action is SteamVR_Input_Action_Vibration)
140+
{
141+
//SteamVR_Input_Action_Vibration actionVibration = (SteamVR_Input_Action_Vibration)action;
193142

143+
if (timeSinceLastChanged == -1)
144+
actionText = "never used";
194145

195-
[MenuItem("Assets/Create/YourClass")]
196-
public static void CreateAsset()
197-
{
198-
CreateAsset<SteamVR_Settings>();
199-
}
200-
public static void CreateAsset<T>() where T : ScriptableObject
201-
{
202-
T asset = ScriptableObject.CreateInstance<T>();
146+
actionText = string.Format("{0:0} seconds since last used", timeSinceLastChanged);
147+
}
203148

204-
string path = AssetDatabase.GetAssetPath(Selection.activeObject);
205-
if (path == "")
206-
{
207-
path = "Assets";
208-
}
209-
else if (Path.GetExtension(path) != "")
210-
{
211-
path = path.Replace(Path.GetFileName(AssetDatabase.GetAssetPath(Selection.activeObject)), "");
212-
}
149+
EditorGUILayout.LabelField(action.GetShortName(), actionText, labelStyle);
150+
GUI.backgroundColor = defaultColor;
151+
}
213152

214-
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath(path + "/New " + typeof(T).ToString() + ".asset");
153+
EditorGUILayout.Space();
154+
}
215155

216-
AssetDatabase.CreateAsset(asset, assetPathAndName);
217156

218-
AssetDatabase.SaveAssets();
219-
AssetDatabase.Refresh();
220-
EditorUtility.FocusProjectWindow();
221-
Selection.activeObject = asset;
157+
EditorGUI.indentLevel--;
158+
}
222159
}
223160
}

0 commit comments

Comments
 (0)