/// <summary> /// Initializes the dictionaries used by this action /// </summary> public virtual void PreInitialize() { SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetUpdateSources(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { InitializeDictionaries(sources[sourceIndex]); } }
/// <summary> /// Updates the states of all the skeleton actions /// </summary> /// <param name="skipStateAndEventUpdates">Controls whether or not events are fired from this update call</param> public static void UpdateSkeletonActions(bool skipStateAndEventUpdates = false) { if (initialized == false) { return; } var sources = SteamVR_Input_Source.GetUpdateSources(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { UpdateSkeletonActions(sources[sourceIndex], skipStateAndEventUpdates); } if (OnSkeletonsUpdated != null) { OnSkeletonsUpdated(skipStateAndEventUpdates); } }
/// <summary> /// Updates the states of all the non visual actions (boolean, single, vector2, vector3) /// </summary> public static void UpdateNonVisualActions() { if (initialized == false) { return; } SteamVR_ActionSet.UpdateActionSetsState(); var sources = SteamVR_Input_Source.GetUpdateSources(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { UpdateNonVisualActions(sources[sourceIndex]); } if (OnNonVisualActionsUpdated != null) { OnNonVisualActionsUpdated(); } }
private void OnGUI() { if (labelStyle == null) { labelStyle = new GUIStyle(EditorStyles.textField); labelStyle.normal.background = Texture2D.whiteTexture; } scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); Color defaultColor = GUI.backgroundColor; SteamVR_ActionSet[] actionSets = SteamVR_Input.actionSets; if (actionSets == null) { actionSets = SteamVR_Input_References.instance.actionSetObjects; } SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetUpdateSources(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { SteamVR_Input_Sources source = sources[sourceIndex]; EditorGUILayout.LabelField(source.ToString()); for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++) { SteamVR_ActionSet set = actionSets[actionSetIndex]; string activeText = set.IsActive() ? "Active" : "Inactive"; float setLastChanged = set.GetTimeLastChanged(); if (setLastChanged != -1) { float timeSinceLastChanged = Time.time - setLastChanged; if (timeSinceLastChanged < 1) { Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged); GUI.backgroundColor = setColor; } } EditorGUILayout.LabelField(set.GetShortName(), activeText, labelStyle); GUI.backgroundColor = defaultColor; EditorGUI.indentLevel++; for (int actionIndex = 0; actionIndex < set.allActions.Length; actionIndex++) { SteamVR_Action action = set.allActions[actionIndex]; if (action.actionSet == null || action.actionSet.IsActive() == false) { EditorGUILayout.LabelField(action.GetShortName(), "-", labelStyle); continue; } float actionLastChanged = action.GetTimeLastChanged(source); string actionText = ""; float timeSinceLastChanged = -1; if (actionLastChanged != -1) { timeSinceLastChanged = Time.time - actionLastChanged; if (timeSinceLastChanged < 1) { Color setColor = Color.Lerp(Color.green, defaultColor, timeSinceLastChanged); GUI.backgroundColor = setColor; } } if (action is SteamVR_Action_Boolean) { SteamVR_Action_Boolean actionBoolean = (SteamVR_Action_Boolean)action; actionText = actionBoolean.GetState(source).ToString(); } else if (action is SteamVR_Action_Single) { SteamVR_Action_Single actionSingle = (SteamVR_Action_Single)action; actionText = actionSingle.GetAxis(source).ToString("0.0000"); } else if (action is SteamVR_Action_Vector2) { SteamVR_Action_Vector2 actionVector2 = (SteamVR_Action_Vector2)action; actionText = string.Format("({0:0.0000}, {1:0.0000})", actionVector2.GetAxis(source).x, actionVector2.GetAxis(source).y); } else if (action is SteamVR_Action_Vector3) { SteamVR_Action_Vector3 actionVector3 = (SteamVR_Action_Vector3)action; Vector3 axis = actionVector3.GetAxis(source); actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000})", axis.x, axis.y, axis.z); } else if (action is SteamVR_Action_Pose) { SteamVR_Action_Pose actionPose = (SteamVR_Action_Pose)action; Vector3 position = actionPose.GetLocalPosition(source); Quaternion rotation = actionPose.GetLocalRotation(source); actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})", position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, rotation.w); } else if (action is SteamVR_Action_Skeleton) { SteamVR_Action_Skeleton actionSkeleton = (SteamVR_Action_Skeleton)action; Vector3 position = actionSkeleton.GetLocalPosition(source); Quaternion rotation = actionSkeleton.GetLocalRotation(source); actionText = string.Format("({0:0.0000}, {1:0.0000}, {2:0.0000}) : ({3:0.0000}, {4:0.0000}, {5:0.0000}, {6:0.0000})", position.x, position.y, position.z, rotation.x, rotation.y, rotation.z, rotation.w); } else if (action is SteamVR_Action_Vibration) { //SteamVR_Input_Action_Vibration actionVibration = (SteamVR_Input_Action_Vibration)action; if (timeSinceLastChanged == -1) { actionText = "never used"; } actionText = string.Format("{0:0} seconds since last used", timeSinceLastChanged); } EditorGUILayout.LabelField(action.GetShortName(), actionText, labelStyle); GUI.backgroundColor = defaultColor; } EditorGUILayout.Space(); } EditorGUI.indentLevel--; } EditorGUILayout.EndScrollView(); }