public GetAxis ( SteamVR_Input_Sources inputSource ) : float | ||
inputSource | SteamVR_Input_Sources | The device you would like to get data from. Any if the action is not device specific. |
return | float |
/// <summary> /// Performs smoothing based on deltaTime parameter. /// </summary> public void Update(float deltaTime, SteamVR_Input_Sources inputSource) { if (type == BlenderTypes.AnalogAction) { if (smoothingSpeed == 0) { value = action_single.GetAxis(inputSource); } else { value = Mathf.Lerp(value, action_single.GetAxis(inputSource), deltaTime * smoothingSpeed); } } if (type == BlenderTypes.BooleanAction) { if (smoothingSpeed == 0) { value = action_bool.GetState(inputSource) ? 1 : 0; } else { value = Mathf.Lerp(value, action_bool.GetState(inputSource) ? 1 : 0, deltaTime * smoothingSpeed); } } }
// Update is called once per frame public override void Update(float dt) { wing.transform.rotation = leftHand.rotation; wing2.transform.rotation = rightHand.rotation; //if (test0.transform.up.y > 0) wing.transform.rotation = test0.rotation; //if (test1.transform.up.y > 0) wing2.transform.rotation = test1.rotation; //Debug.Log(test0.transform.up); bool leftInput = squeezeAction.GetAxis(Valve.VR.SteamVR_Input_Sources.LeftHand) > 0.5f || Input.GetKey(KeyCode.A); bool rightInput = squeezeAction.GetAxis(Valve.VR.SteamVR_Input_Sources.RightHand) > 0.5f || Input.GetKey(KeyCode.S); if (!leftInput && !rightInput) { flyVector = new Vector3(0, 0, 0); speed = .0f; Vector3 nextPos = transform.position + dt * new Vector3(0, -5.0f, 0); if (nextPos.y < groundY) { nextPos = new Vector3(transform.position.x, groundY, transform.position.z); } transform.position = nextPos; //player.position = transform.position - playerOffset; } else { if (leftInput) { flyVector += dt * wing.GetChild(0).up; } if (rightInput) { flyVector += dt * wing2.GetChild(0).up; } speed += dt * 5.0f; if (speed > 5.0f) { speed = 5.0f; } transform.position += speed * dt * flyVector; // player.position = transform.position - playerOffset; } Debug.Log(flyVector); }
// Update is called once per frame public override void Update(float dt) { //Vector3 handDiff = new Vector3(test.position.x - HUDCamera.position.x, 0, test.position.z - HUDCamera.position.z).normalized; Vector3 handDiff = new Vector3(rightHand.position.x - HUDCamera.position.x, 0, rightHand.position.z - HUDCamera.position.z).normalized; body.rotation = Quaternion.Lerp(body.rotation, Quaternion.LookRotation(handDiff, Vector3.up), dt * 5.0f); //float handOffset = test.position.y - handInitY; float handOffset = rightHand.position.y - handInitY; if (handOffset > 0.35f) { handOffset = 0.35f; } else if (handOffset < -0.55f) { handOffset = -0.55f; } arm.localPosition = new Vector3(arm.localPosition.x, handOffset + armInitY, arm.localPosition.z); Debug.Log(squeezeAction.GetAxis(Valve.VR.SteamVR_Input_Sources.RightHand)); if ((Input.GetKeyDown(KeyCode.G) || squeezeAction.GetAxis(Valve.VR.SteamVR_Input_Sources.RightHand) > 0.8f) && !grib) { Collider[] hits = Physics.OverlapBox(hand.transform.position + new Vector3(0, -0.5f, 0), new Vector3(0.5f, 0.5f, 0.5f), hand.rotation, 1 << LayerMask.NameToLayer("GribObject")); if (hits.Length > 0) { grabObject = hits[0].transform; grabObject.parent.parent = hand; grib = true; robot.canMove = false; } Debug.Log(hits.Length); } else if (squeezeAction.GetAxis(Valve.VR.SteamVR_Input_Sources.RightHand) < 0.1f && grib) { grib = false; grabObject.parent.parent = null; robot.canFall = true; robot.canMove = true; } }
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(); }
private void OnGUI() { if (SteamVR_Input.actionSets == null) { EditorGUILayout.LabelField("Must first generate actions. Open SteamVR Input window."); return; } bool startUpdatingSourceOnAccess = SteamVR_Action.startUpdatingSourceOnAccess; SteamVR_Action.startUpdatingSourceOnAccess = false; if (labelStyle == null) { labelStyle = new GUIStyle(EditorStyles.textField); labelStyle.normal.background = Texture2D.whiteTexture; setLabelStyle = new GUIStyle(EditorStyles.label); setLabelStyle.wordWrap = true; setLabelStyle.normal.background = Texture2D.whiteTexture; } scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition); Color defaultColor = GUI.backgroundColor; SteamVR_ActionSet[] actionSets = SteamVR_Input.actionSets; SteamVR_Input_Sources[] sources = SteamVR_Input_Source.GetAllSources(); if (sourceFoldouts == null) { sourceFoldouts = new Dictionary <SteamVR_Input_Sources, bool>(); setFoldouts = new Dictionary <SteamVR_Input_Sources, Dictionary <string, bool> >(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { sourceFoldouts.Add(sources[sourceIndex], false); setFoldouts.Add(sources[sourceIndex], new Dictionary <string, bool>()); for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++) { SteamVR_ActionSet set = actionSets[actionSetIndex]; setFoldouts[sources[sourceIndex]].Add(set.GetShortName(), true); } } sourceFoldouts[SteamVR_Input_Sources.Any] = true; sourceFoldouts[SteamVR_Input_Sources.LeftHand] = true; sourceFoldouts[SteamVR_Input_Sources.RightHand] = true; } DrawMap(); for (int sourceIndex = 0; sourceIndex < sources.Length; sourceIndex++) { SteamVR_Input_Sources source = sources[sourceIndex]; sourceFoldouts[source] = EditorGUILayout.Foldout(sourceFoldouts[source], source.ToString()); if (sourceFoldouts[source] == false) { continue; } EditorGUI.indentLevel++; for (int actionSetIndex = 0; actionSetIndex < actionSets.Length; actionSetIndex++) { SteamVR_ActionSet set = actionSets[actionSetIndex]; bool setActive = set.IsActive(source); string activeText = setActive ? "Active" : "Inactive"; float setLastChanged = set.GetTimeLastChanged(); if (setLastChanged != -1) { float timeSinceLastChanged = Time.realtimeSinceStartup - setLastChanged; if (timeSinceLastChanged < 1) { Color blendColor = setActive ? Color.green : inactiveSetColor; Color setColor = Color.Lerp(blendColor, defaultColor, timeSinceLastChanged); GUI.backgroundColor = setColor; } } EditorGUILayout.BeginHorizontal(); setFoldouts[source][set.GetShortName()] = EditorGUILayout.Foldout(setFoldouts[source][set.GetShortName()], set.GetShortName()); EditorGUILayout.LabelField(activeText, labelStyle); GUI.backgroundColor = defaultColor; EditorGUILayout.EndHorizontal(); if (setFoldouts[source][set.GetShortName()] == false) { continue; } EditorGUI.indentLevel++; for (int actionIndex = 0; actionIndex < set.allActions.Length; actionIndex++) { SteamVR_Action action = set.allActions[actionIndex]; if (source != SteamVR_Input_Sources.Any && action is SteamVR_Action_Skeleton) { continue; } bool isUpdating = action.IsUpdating(source); bool inAction = action is ISteamVR_Action_In; bool noData = false; if (inAction && isUpdating == false) { GUI.backgroundColor = Color.yellow; noData = true; } else { bool actionBound = action.GetActiveBinding(source); if (setActive == false) { GUI.backgroundColor = inactiveSetColor; } else if (actionBound == false) { GUI.backgroundColor = Color.red; noData = true; } } if (noData) { EditorGUILayout.LabelField(action.GetShortName(), "-", labelStyle); GUI.backgroundColor = defaultColor; continue; } float actionLastChanged = action.GetTimeLastChanged(source); string actionText = ""; float timeSinceLastChanged = -1; if (actionLastChanged != -1) { timeSinceLastChanged = Time.realtimeSinceStartup - 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; } EditorGUI.indentLevel--; EditorGUILayout.Space(); } EditorGUI.indentLevel--; } EditorGUILayout.Space(); EditorGUILayout.LabelField("Active Action Set List"); EditorGUI.indentLevel++; EditorGUILayout.LabelField(SteamVR_ActionSet_Manager.debugActiveSetListText, setLabelStyle); EditorGUI.indentLevel--; EditorGUILayout.Space(); EditorGUILayout.EndScrollView(); SteamVR_Action.startUpdatingSourceOnAccess = startUpdatingSourceOnAccess; }