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(); }
public void UpdateComponents(CVRRenderModels renderModels) { if (renderModels == null) { return; } if (transform.childCount == 0) { return; } if (nameCache == null) { nameCache = new Dictionary <int, string>(); } for (int childIndex = 0; childIndex < transform.childCount; childIndex++) { Transform child = transform.GetChild(childIndex); // Cache names since accessing an object's name allocate memory. string componentName; if (!nameCache.TryGetValue(child.GetInstanceID(), out componentName)) { componentName = child.name; nameCache.Add(child.GetInstanceID(), componentName); } var componentState = new RenderModel_ComponentState_t(); if (!renderModels.GetComponentStateForDevicePath(renderModelName, componentName, SteamVR_Input_Source.GetHandle(inputSource), ref controllerModeState, ref componentState)) { continue; } child.localPosition = SteamVR_Utils.GetPosition(componentState.mTrackingToComponentRenderModel); child.localRotation = SteamVR_Utils.GetRotation(componentState.mTrackingToComponentRenderModel); Transform attach = null; for (int childChildIndex = 0; childChildIndex < child.childCount; childChildIndex++) { Transform childChild = child.GetChild(childChildIndex); int childInstanceID = childChild.GetInstanceID(); string childName; if (!nameCache.TryGetValue(childInstanceID, out childName)) { childName = childChild.name; nameCache.Add(childInstanceID, componentName); } if (childName == SteamVR_RenderModel.k_localTransformName) { attach = childChild; } } if (attach != null) { attach.position = transform.TransformPoint(SteamVR_Utils.GetPosition(componentState.mTrackingToComponentLocal)); attach.rotation = transform.rotation * SteamVR_Utils.GetRotation(componentState.mTrackingToComponentLocal); initializedAttachPoints = true; } bool visible = (componentState.uProperties & (uint)EVRComponentProperty.IsVisible) != 0; if (visible != child.gameObject.activeSelf) { child.gameObject.SetActive(visible); } } }
/// <summary> /// <strong>[Should not be called by user code]</strong> /// Initializes the handle for the inputSource, and any other related SteamVR data. /// </summary> public virtual void Initialize() { inputSourceHandle = SteamVR_Input_Source.GetHandle(inputSource); }
public override void UpdateValue(SteamVR_Input_Sources inputSource, bool skipStateAndEventUpdates) { if (skipStateAndEventUpdates == false) { base.ResetLastStates(inputSource); } base.UpdateValue(inputSource, true); bool poseChanged = base.changed[inputSource]; int inputSourceInt = (int)inputSource; if (skipStateAndEventUpdates == false) { changed[inputSource] = false; for (int boneIndex = 0; boneIndex < numBones; boneIndex++) { lastBonePositions[inputSourceInt][boneIndex] = bonePositions[inputSourceInt][boneIndex]; lastBoneRotations[inputSourceInt][boneIndex] = boneRotations[inputSourceInt][boneIndex]; } } EVRInputError err = OpenVR.Input.GetSkeletalActionData(handle, ref tempSkeletonActionData, skeletonActionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { // Debug.LogError("GetSkeletalActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); active[inputSource] = false; return; } active[inputSource] = active[inputSource] && tempSkeletonActionData.bActive; //anding from the pose active state activeOrigin[inputSource] = tempSkeletonActionData.activeOrigin; if (active[inputSource]) { err = OpenVR.Input.GetSkeletalBoneData(handle, skeletalTransformSpace[inputSource], rangeOfMotion[inputSource], tempBoneTransforms, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("GetSkeletalBoneData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); } for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++) { // SteamVR's coordinate system is right handed, and Unity's is left handed. The FBX data has its // X axis flipped when Unity imports it, so here we need to flip the X axis as well bonePositions[inputSourceInt][boneIndex].x = -tempBoneTransforms[boneIndex].position.v0; bonePositions[inputSourceInt][boneIndex].y = tempBoneTransforms[boneIndex].position.v1; bonePositions[inputSourceInt][boneIndex].z = tempBoneTransforms[boneIndex].position.v2; boneRotations[inputSourceInt][boneIndex].x = tempBoneTransforms[boneIndex].orientation.x; boneRotations[inputSourceInt][boneIndex].y = -tempBoneTransforms[boneIndex].orientation.y; boneRotations[inputSourceInt][boneIndex].z = -tempBoneTransforms[boneIndex].orientation.z; boneRotations[inputSourceInt][boneIndex].w = tempBoneTransforms[boneIndex].orientation.w; } // Now that we're in the same handedness as Unity, rotate the root bone around the Y axis // so that forward is facing down +Z Quaternion qFixUpRot = Quaternion.AngleAxis(Mathf.PI * Mathf.Rad2Deg, Vector3.up); boneRotations[inputSourceInt][0] = qFixUpRot * boneRotations[inputSourceInt][0]; } changed[inputSource] = changed[inputSource] || poseChanged; if (skipStateAndEventUpdates == false) { for (int boneIndex = 0; boneIndex < tempBoneTransforms.Length; boneIndex++) { if (Vector3.Distance(lastBonePositions[inputSourceInt][boneIndex], bonePositions[inputSourceInt][boneIndex]) > changeTolerance) { changed[inputSource] |= true; break; } if (Mathf.Abs(Quaternion.Angle(lastBoneRotations[inputSourceInt][boneIndex], boneRotations[inputSourceInt][boneIndex])) > changeTolerance) { changed[inputSource] |= true; break; } } base.CheckAndSendEvents(inputSource); } if (changed[inputSource]) { lastChanged[inputSource] = Time.time; } if (skipStateAndEventUpdates == false) { lastRecordedActive[inputSource] = active[inputSource]; lastRecordedPoseActionData[inputSource] = poseActionData[inputSource]; } }
public override void UpdateValue(SteamVR_Input_Sources inputSource) { lastActionData[inputSource] = actionData[inputSource]; lastActive[inputSource] = active[inputSource]; EVRInputError err = OpenVR.Input.GetAnalogActionData(handle, ref tempActionData, actionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("GetAnalogActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); } active[inputSource] = tempActionData.bActive; activeOrigin[inputSource] = tempActionData.activeOrigin; updateTime[inputSource] = tempActionData.fUpdateTime; changed[inputSource] = false; actionData[inputSource] = tempActionData; if (GetAxisDelta(inputSource).magnitude > changeTolerance) { changed[inputSource] = true; lastChanged[inputSource] = Time.time; if (onChange[inputSource] != null) { onChange[inputSource].Invoke(this); } } if (onUpdate[inputSource] != null) { onUpdate[inputSource].Invoke(this); } if (onActiveChange[inputSource] != null && lastActive[inputSource] != active[inputSource]) { onActiveChange[inputSource].Invoke(this, active[inputSource]); } }
/// <summary><strong>[Should not be called by user code]</strong> /// Updates the data for this action and this input source. Sends related events. /// </summary> public override void UpdateValue() { lastActionData = actionData; lastActive = active; lastAxis = axis; lastDelta = delta; EVRInputError err = OpenVR.Input.GetAnalogActionData(handle, ref actionData, actionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("<b>[SteamVR]</b> GetAnalogActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); } updateTime = Time.realtimeSinceStartup; axis = new Vector3(actionData.x, actionData.y, actionData.z); delta = new Vector3(actionData.deltaX, actionData.deltaY, actionData.deltaZ); changed = false; if (active) { if (delta.magnitude > changeTolerance) { changed = true; changedTime = Time.realtimeSinceStartup + actionData .fUpdateTime; //fUpdateTime is the time from the time the action was called that the action changed if (onChange != null) { onChange.Invoke(vector3Action, inputSource, axis, delta); } } if (axis != Vector3.zero) { if (onAxis != null) { onAxis.Invoke(vector3Action, inputSource, axis, delta); } } if (onUpdate != null) { onUpdate.Invoke(vector3Action, inputSource, axis, delta); } } if (onActiveBindingChange != null && lastActiveBinding != activeBinding) { onActiveBindingChange.Invoke(vector3Action, inputSource, activeBinding); } if (onActiveChange != null && lastActive != active) { onActiveChange.Invoke(vector3Action, inputSource, activeBinding); } }
/// <summary> /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive. /// </summary> /// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public bool GetPoseAtTimeOffset(SteamVR_Input_Sources inputSource, float secondsFromNow, out Vector3 position, out Quaternion rotation, out Vector3 velocity, out Vector3 angularVelocity) { EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, secondsFromNow, ref tempPoseActionData, poseActionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { if (err == EVRInputError.InvalidHandle) { //todo: ignoring this error for now since it throws while the dashboard is up } else { Debug.LogError("GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); //todo: this should be an error } velocity = Vector3.zero; angularVelocity = Vector3.zero; position = Vector3.zero; rotation = Quaternion.identity; return(false); } velocity = new Vector3(tempPoseActionData.pose.vVelocity.v0, tempPoseActionData.pose.vVelocity.v1, -tempPoseActionData.pose.vVelocity.v2); angularVelocity = new Vector3(-tempPoseActionData.pose.vAngularVelocity.v0, -tempPoseActionData.pose.vAngularVelocity.v1, tempPoseActionData.pose.vAngularVelocity.v2); position = SteamVR_Utils.GetPosition(tempPoseActionData.pose.mDeviceToAbsoluteTracking); rotation = SteamVR_Utils.GetRotation(tempPoseActionData.pose.mDeviceToAbsoluteTracking); return(true); }
/// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public virtual void UpdateValue(SteamVR_Input_Sources inputSource, bool skipStateAndEventUpdates) { changed[inputSource] = false; if (skipStateAndEventUpdates == false) { ResetLastStates(inputSource); } EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, predictedSecondsFromNow, ref tempPoseActionData, poseActionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); } poseActionData[inputSource] = tempPoseActionData; active[inputSource] = tempPoseActionData.bActive; activeOrigin[inputSource] = tempPoseActionData.activeOrigin; updateTime[inputSource] = Time.time; if (Vector3.Distance(GetLocalPosition(inputSource), GetLastLocalPosition(inputSource)) > changeTolerance) { changed[inputSource] = true; } else if (Mathf.Abs(Quaternion.Angle(GetLocalRotation(inputSource), GetLastLocalRotation(inputSource))) > changeTolerance) { changed[inputSource] = true; } if (skipStateAndEventUpdates == false) { CheckAndSendEvents(inputSource); } if (changed[inputSource]) { lastChanged[inputSource] = Time.time; } if (onUpdate[inputSource] != null) { onUpdate[inputSource].Invoke(this); } if (skipStateAndEventUpdates == false) { lastRecordedActive[inputSource] = active[inputSource]; lastRecordedPoseActionData[inputSource] = poseActionData[inputSource]; } }
/// <summary> /// SteamVR keeps a log of past poses so you can retrieve old poses or estimated poses in the future by passing in a secondsFromNow value that is negative or positive. /// </summary> /// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public bool GetVelocitiesAtTimeOffset(SteamVR_Input_Sources inputSource, float secondsFromNow, out Vector3 velocity, out Vector3 angularVelocity) { EVRInputError err = OpenVR.Input.GetPoseActionData(handle, universeOrigin, secondsFromNow, ref tempPoseActionData, poseActionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("GetPoseActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); //todo: this should be an error velocity = Vector3.zero; angularVelocity = Vector3.zero; return(false); } velocity = new Vector3(tempPoseActionData.pose.vVelocity.v0, tempPoseActionData.pose.vVelocity.v1, -tempPoseActionData.pose.vVelocity.v2); angularVelocity = new Vector3(-tempPoseActionData.pose.vAngularVelocity.v0, -tempPoseActionData.pose.vAngularVelocity.v1, tempPoseActionData.pose.vAngularVelocity.v2); return(true); }
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; }
/// <summary><strong>[Should not be called by user code]</strong> /// Updates the data for this action and this input source. Sends related events. /// </summary> public override void UpdateValue() { lastActionData = actionData; lastActive = active; EVRInputError err = OpenVR.Input.GetAnalogActionData(handle, ref actionData, actionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) Debug.LogError("<b>[SteamVR_Standalone]</b> GetAnalogActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); updateTime = Time.realtimeSinceStartup; changed = false; if (active) { if (delta > changeTolerance || delta < -changeTolerance) { changed = true; changedTime = Time.realtimeSinceStartup + actionData.fUpdateTime; //fUpdateTime is the time from the time the action was called that the action changed if (onChange != null) onChange.Invoke(singleAction, inputSource, axis, delta); } if (axis != 0) { if (onAxis != null) onAxis.Invoke(singleAction, inputSource, axis, delta); } if (onUpdate != null) { onUpdate.Invoke(singleAction, inputSource, axis, delta); } } if (onActiveBindingChange != null && lastActiveBinding != activeBinding) onActiveBindingChange.Invoke(singleAction, inputSource, activeBinding); if (onActiveChange != null && lastActive != active) onActiveChange.Invoke(singleAction, inputSource, activeBinding); }
/// <param name="inputSource">The device you would like to get data from. Any if the action is not device specific.</param> public override void UpdateValue(SteamVR_Input_Sources inputSource) { lastActionData[inputSource] = actionData[inputSource]; EVRInputError err = OpenVR.Input.GetDigitalActionData(handle, ref tempActionData, actionData_size, SteamVR_Input_Source.GetHandle(inputSource)); if (err != EVRInputError.None) { Debug.LogError("GetDigitalActionData error (" + fullPath + "): " + err.ToString() + " handle: " + handle.ToString()); } actionData[inputSource] = tempActionData; changed[inputSource] = tempActionData.bChanged; active[inputSource] = tempActionData.bActive; activeOrigin[inputSource] = tempActionData.activeOrigin; updateTime[inputSource] = tempActionData.fUpdateTime; if (changed[inputSource]) { lastChanged[inputSource] = Time.time; } if (onStateDown[inputSource] != null && GetStateDown(inputSource)) { onStateDown[inputSource].Invoke(this); } if (onStateUp[inputSource] != null && GetStateUp(inputSource)) { onStateUp[inputSource].Invoke(this); } if (onChange[inputSource] != null && GetChanged(inputSource)) { onChange[inputSource].Invoke(this); } if (onUpdate[inputSource] != null) { onUpdate[inputSource].Invoke(this); } if (onActiveChange[inputSource] != null && lastActionData[inputSource].bActive != active[inputSource]) { onActiveChange[inputSource].Invoke(this, active[inputSource]); } }
/// <summary> /// Trigger the haptics at a certain time for a certain length /// </summary> /// <param name="secondsFromNow">How long from the current time to execute the action (in seconds - can be 0)</param> /// <param name="durationSeconds">How long the haptic action should last (in seconds)</param> /// <param name="frequency">How often the haptic motor should bounce (0 - 320 in hz. The lower end being more useful)</param> /// <param name="amplitude">How intense the haptic action should be (0 - 1)</param> /// <param name="inputSource">The device you would like to execute the haptic action. Any if the action is not device specific.</param> public void Execute(float secondsFromNow, float durationSeconds, float frequency, float amplitude, SteamVR_Input_Sources inputSource) { lastChanged[inputSource] = Time.time; var err = OpenVR.Input.TriggerHapticVibrationAction(handle, secondsFromNow, durationSeconds, frequency, amplitude, SteamVR_Input_Source.GetHandle(inputSource)); //Debug.Log(string.Format("haptic: {5}: {0}, {1}, {2}, {3}, {4}", secondsFromNow, durationSeconds, frequency, amplitude, inputSource, this.GetShortName())); if (err != EVRInputError.None) { Debug.LogError("TriggerHapticVibrationAction (" + fullPath + ") error: " + err.ToString() + " handle: " + handle.ToString()); } }