// actions private void AssignAllActionSets() { // default action set defaultActions = SteamVR_Input.GetActionSet("default"); // ui interaction action set menuInteractionActions = SteamVR_Input.GetActionSet("MenuInteraction"); menuInteraction_Select = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/MenuInteraction/in/Select"); menuInteraction_MenuControl = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/MenuInteraction/in/MenuControl"); menuInteraction_Scroll = SteamVR_Input.GetActionFromPath <SteamVR_Action_Vector2>("/actions/MenuInteraction/in/Scroll"); // viz navigation action set vizNavActions = SteamVR_Input.GetActionSet("VizNavigation"); vizNav_Position = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/VizNavigation/in/Position"); vizNav_Rotation = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/VizNavigation/in/Rotation"); vizNav_Select = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/VizNavigation/in/Select"); //vizNav_HardGrip = SteamVR_Input.GetActionFromPath<SteamVR_Action_Single>("/actions/VizNavigation/in/HardGrip"); // dimension explorer action set dimExplorerActions = SteamVR_Input.GetActionSet("DimExplorer"); dimExplorer_Select = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/DimExplorer/in/Select"); dimExplorer_Scroll = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/DimExplorer/in/Scroll"); // timeline action set timelineActions = SteamVR_Input.GetActionSet("Timeline"); timeline_Select = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/Timeline/in/Select"); timeline_Scroll = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/Timeline/in/Scroll"); timeline_Back = SteamVR_Input.GetActionFromPath <SteamVR_Action_Boolean>("/actions/Timeline/in/Back"); }
void Start() { if (GameObject.FindGameObjectWithTag("leftHand").Equals(this.gameObject)) { currentSource = SteamVR_Input_Sources.LeftHand; } else { if (GameObject.FindGameObjectWithTag("rightHand").Equals(this.gameObject)) { currentSource = SteamVR_Input_Sources.RightHand; } else { print("This script is not on right or left hand"); } } pose = GetComponent <SteamVR_Behaviour_Pose>(); hover = GetComponent <Hover>(); currentActionSet = SteamVR_Input.GetActionSet("MySet"); gripClickAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("MySet", "GripClick", false, false); triggerPullAction = SteamVR_Input.GetAction <SteamVR_Action_Single>("MySet", "Teleport", false, false); joyStickAction = SteamVR_Input.GetAction <SteamVR_Action_Vector2>("MySet", "Move", false, false); //Sword specific actions that need to be defined (They won't do anything until we activate the correct action set) detachAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("Sword", "Detach", false, false); triggerClickAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("Sword", "InitiateSlash", false, false); }
/// <summary> /// Returns raw sensor data for the selected channel. /// Currently available data: /// WHEEL: value from 0-1 given by the wheel action set. /// </summary> /// <param name="channel">The channel/data identifier.</param> /// <returns>Raw sensor data for the given channel.</returns> public override float GetRawData(string channel) { if (channel.Equals("TRACKPAD")) { // Check that the action set is active. if (!SteamVR_Input.GetActionSet("vrproep").IsActive()) { SteamVR_Input.GetActionSet("default").Deactivate(); SteamVR_Input.GetActionSet("vrproep").Activate(); } Vector2 trackpadValue = trackpadAction.GetAxis(SteamVR_Input_Sources.Any); return(trackpadValue.x); } else if (channel.Equals("BUTTON")) { bool buttonValue = buttonAction.GetState(SteamVR_Input_Sources.Any); if (buttonValue) { return(1.0f); } else { return(0.0f); } } else { throw new System.Exception("The provided channel does not exist. See documentation for available channels."); } }
private void InitSteamVR() { if (!InitializeSteamVR || !IsSteamVR()) { return; } #if !HVR_STEAMVR return; #else if (!IsVRInitialized) { Debug.LogWarning($"Cannot InitSteamVR. VR not initialized yet."); return; } Valve.VR.SteamVR.Initialize(); if (InitializeSteamVRActions) { var actionSet = SteamVR_Input.GetActionSet(@"\actions\HVR"); actionSet.Activate(); } #endif }
/// <summary> /// Returns all pre-processed sensor data in an array. /// Currently available data: /// 0: the wheel action delta. /// </summary> /// <returns>The array with all pre-processed sensor data.</returns> public override float[] GetAllProcessedData() { // Check that the action set is active. if (!SteamVR_Input.GetActionSet("vrproep").IsActive()) { SteamVR_Input.GetActionSet("default").Deactivate(); SteamVR_Input.GetActionSet("vrproep").Activate(); } Vector2 trackpadValue = trackpadAction.GetAxis(SteamVR_Input_Sources.Any); bool buttonState = buttonAction.GetState(SteamVR_Input_Sources.Any); float buttonValue; if (buttonState) { buttonValue = 1.0f; } else { buttonValue = 0.0f; } float[] data = { trackpadValue.x, buttonValue }; return(data); }
private void Start() { // Check that the action set is active. if (!SteamVR_Input.GetActionSet("vrproep").IsActive()) { SteamVR_Input.GetActionSet("default").Deactivate(); SteamVR_Input.GetActionSet("vrproep").Activate(); } handGO = GameObject.FindGameObjectWithTag("Hand"); // Get tracking handle when able-bodied if (!isTrackedObject) { // Get hand rigid body when prosthesis handRB = handGO.GetComponent <Rigidbody>(); if (handRB == null) { throw new System.Exception("Hand Rigidbody not found."); } } else { averageFilter = new MovingAverageFilter(5); prevHandPosition = handGO.transform.position; } }
public void DisposeSteamVRConnection() { SteamVR_ActionSet_Manager.ChangeSetPriorities(false); SteamVR_Input.GetActionSet("/actions/main").Deactivate(); OpenVR.Shutdown(); SteamVRManager.isConnected = false; }
public override void OnActivated() { m_digitalDataSize = (uint)Marshal.SizeOf(new InputDigitalActionData_t()); m_analogDataSize = (uint)Marshal.SizeOf(new InputAnalogActionData_t()); m_originInfoSize = (uint)Marshal.SizeOf(new InputOriginInfo_t()); m_activeActionSetSize = (uint)Marshal.SizeOf(new VRActiveActionSet_t()); m_poses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount]; m_gamePoses = new TrackedDevicePose_t[0]; m_originDataCache = new Dictionary <ulong, OriginData>((int)OpenVR.k_unMaxActionOriginCount); InitializeHandles(); #if VIU_STEAMVR_2_1_0_OR_NEWER SteamVR_Input.GetActionSet(ACTION_SET_NAME).Activate(SteamVR_Input_Sources.Any, 0, false); #else var actionSet = SteamVR_Input.GetActionSetFromPath(ACTION_SET_PATH); if (actionSet != null) { actionSet.ActivatePrimary(); } #endif #if !VIU_STEAMVR_2_1_0_OR_NEWER m_activeActionSets = new VRActiveActionSet_t[1] { new VRActiveActionSet_t() { ulActionSet = s_actionSetHandle, } }; #endif #if VIU_STEAMVR_2_2_0_OR_NEWER SteamVR_Input.onNonVisualActionsUpdated += UpdateDeviceInput; SteamVR_Input.onPosesUpdated += UpdateDevicePose; #else SteamVR_Input.OnNonVisualActionsUpdated += UpdateDeviceInput; SteamVR_Input.OnPosesUpdated += UpdateDevicePose; #endif s_devicePathHandles = new ulong[OpenVR.k_unMaxTrackedDeviceCount]; EnsureDeviceStateLength(OpenVR.k_unMaxTrackedDeviceCount); // preserve previous tracking space m_prevTrackingSpace = trackingSpace; m_hasInputFocus = inputFocus; SteamVR_Events.InputFocus.AddListener(OnInputFocus); SteamVR_Events.System(EVREventType.VREvent_TrackedDeviceRoleChanged).AddListener(OnTrackedDeviceRoleChanged); s_moduleInstance = this; }
private void StopSteamVR() { #if !HVR_STEAMVR return; #else Valve.VR.SteamVR.SafeDispose(); if (InitializeSteamVRActions) { var actionSet = SteamVR_Input.GetActionSet(@"\actions\HVR"); actionSet.Deactivate(); } #endif }
// Use this for initialization void Start() { // Check that the action set is active. if (!SteamVR_Input.GetActionSet("vrproep").IsActive()) { SteamVR_Input.GetActionSet("default").Deactivate(); SteamVR_Input.GetActionSet("vrproep").Activate(); } // Get head transform headTransform = GameObject.FindGameObjectWithTag("Head").transform; if (headTransform == null) { throw new System.Exception("Head tracking object not found."); } }
public override void OnEnter() { switch (forSources) { case playsources.Any: devices = SteamVR_Input_Sources.Any; break; case playsources.Camera: devices = SteamVR_Input_Sources.Camera; break; case playsources.Chest: devices = SteamVR_Input_Sources.Chest; break; case playsources.Gamepad: devices = SteamVR_Input_Sources.Gamepad; break; case playsources.Head: devices = SteamVR_Input_Sources.Head; break; case playsources.Keyboard: devices = SteamVR_Input_Sources.Keyboard; break; case playsources.LeftFoot: devices = SteamVR_Input_Sources.LeftFoot; break; case playsources.LeftHand: devices = SteamVR_Input_Sources.LeftHand; break; case playsources.LeftShoulder: devices = SteamVR_Input_Sources.LeftShoulder; break; case playsources.RightHand: devices = SteamVR_Input_Sources.RightHand; break; case playsources.RightShoulder: devices = SteamVR_Input_Sources.RightShoulder; break; case playsources.Waist: devices = SteamVR_Input_Sources.Waist; break; } if (actionSet == null) { Debug.LogError("Missing Action Set : " + Owner.name); Finish(); } if (activate.Value) { SteamVR_Input.GetActionSet(actionSet.Value).Activate(devices, 0, disableAllOtherActionSets.Value); } else { SteamVR_Input.GetActionSet(actionSet.Value).Deactivate(devices); } }
public override void OnActivated() { m_digitalDataSize = (uint)Marshal.SizeOf(new InputDigitalActionData_t()); m_analogDataSize = (uint)Marshal.SizeOf(new InputAnalogActionData_t()); m_poses = new TrackedDevicePose_t[OpenVR.k_unMaxTrackedDeviceCount]; m_gamePoses = new TrackedDevicePose_t[0]; InitializeHandles(); #if VIU_STEAMVR_2_1_0_OR_NEWER SteamVR_Input.GetActionSet(ACTION_SET_NAME).Activate(SteamVR_Input_Sources.Any, 0, false); #else var actionSet = SteamVR_Input.GetActionSetFromPath(ACTION_SET_PATH); if (actionSet != null) { actionSet.ActivatePrimary(); } #endif #if VIU_STEAMVR_2_2_0_OR_NEWER SteamVR_Input.onNonVisualActionsUpdated += UpdateDeviceInput; SteamVR_Input.onPosesUpdated += UpdateDeviceConnectionAndPose; #else SteamVR_Input.OnNonVisualActionsUpdated += UpdateDeviceInput; SteamVR_Input.OnPosesUpdated += UpdateDeviceConnectionAndPose; #endif //s_devicePathHandles = new ulong[OpenVR.k_unMaxTrackedDeviceCount]; EnsureDeviceStateLength(8); // preserve previous tracking space m_prevTrackingSpace = trackingSpace; m_hasInputFocus = inputFocus; SteamVR_Events.InputFocus.AddListener(OnInputFocus); s_moduleInstance = this; m_submodules.ActivateAllModules(); }
/// <summary> /// Returns pre-processed sensor data for the selected channel. /// Currently available data: /// 0: the wheel action delta. /// </summary> /// <param name="channel">The channel number.</param> /// <returns>Pre-processed sensor data for the given channel.</returns> public override float GetProcessedData(int channel) { if (channel >= ChannelSize) { throw new System.ArgumentOutOfRangeException("The requested channel number is greater than the available number of channels. The number of available channels is: " + ChannelSize + "."); } else if (channel < 0) { throw new System.ArgumentOutOfRangeException("The channel number starts from 0."); } // Check that the action set is active. if (!SteamVR_Input.GetActionSet("vrproep").IsActive()) { SteamVR_Input.GetActionSet("default").Deactivate(); SteamVR_Input.GetActionSet("vrproep").Activate(); } if (channel == 0) { Vector2 trackpadValue = trackpadAction.GetAxis(SteamVR_Input_Sources.Any); return(trackpadValue.x); } else if (channel == 1) { bool buttonState = buttonAction.GetState(SteamVR_Input_Sources.Any); if (buttonState) { return(1.0f); } else { return(0.0f); } } else { throw new System.Exception("Something went wrong, the provided channel is unavailable."); } }
protected override IEnumerator InitEvnAsync(System.Action <string> onResult) { SteamVR.Initialize(true); yield return(null); while (SteamVR.initializedState == SteamVR.InitializedStates.Initializing) { yield return(0); } if (SteamVR.initializedState == SteamVR.InitializedStates.InitializeSuccess) { onResult?.Invoke(string.Empty); var actionSet = SteamVR_Input.GetActionSet("key"); actionSet?.Activate(SteamVR_Input_Sources.LeftHand); actionSet?.Activate(SteamVR_Input_Sources.RightHand); } else { onResult?.Invoke("UnitySteamvrEvn初始化失败"); } yield return(null); }
void Update() { if (actionSetChanged) { switch (currentActionSet.GetShortName()) { case "MySet": currentActionSet.Activate(currentSource, 0, false); pose.poseAction = SteamVR_Input.GetAction <SteamVR_Action_Pose>("MySet", "Pose", false, false); gripClickAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("MySet", "GripClick", false, false); triggerPullAction = SteamVR_Input.GetAction <SteamVR_Action_Single>("MySet", "Teleport", false, false); joyStickAction = SteamVR_Input.GetAction <SteamVR_Action_Vector2>("MySet", "Move", false, false); break; case "Sword": currentActionSet.Activate(currentSource, 0, false); pose.poseAction = SteamVR_Input.GetAction <SteamVR_Action_Pose>("Sword", "Pose", false, false); //gripClickAction = SteamVR_Input.GetAction<SteamVR_Action_Boolean>("Sword", "InitiateSlash", false, false); triggerClickAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("Sword", "InitiateSlash", false, false); joyStickAction = SteamVR_Input.GetAction <SteamVR_Action_Vector2>("Sword", "Move", false, false); break; default: break; } actionSetChanged = false; } gripClick = gripClickAction.GetStateDown(currentSource); triggerClickUp = triggerClickAction.GetStateUp(currentSource); triggerValue = triggerPullAction.GetAxis(currentSource); triggerClick = triggerClickAction.GetLastStateDown(currentSource); detach = detachAction.GetStateDown(currentSource); moveValue = joyStickAction.GetAxis(currentSource); //INITIATESLASH CODE ---------------------------------------------------------------------------------------------------------------------------------- if (triggerClick && attached && currentActionSet.GetShortName().Equals("Sword")) { slashParticles = currentlyAttachedObject.GetComponent <ParticleSystem>(); ParticleSystem.EmissionModule emiss = slashParticles.emission; emiss.rateOverDistance = 200f; } if (triggerClickUp && attached && currentActionSet.GetShortName().Equals("Sword")) { slashParticles = currentlyAttachedObject.GetComponent <ParticleSystem>(); ParticleSystem.EmissionModule emiss = slashParticles.emission; emiss.rateOverDistance = 0f; } //OBJECT DETACH CODE --------------------------------------------------------------------------------------------------------------------------------- if (attached && detach && hover.closestHoverObj != null) { //Grab a reference to the current closestHoverObject that is obtained by running Hover() in Hover.cs try { ObjectInteraction detachCall = hover.closestHoverObj.GetComponent <ObjectInteraction>(); attached = detachCall.DetachObjectFromController(); currentActionSet.Deactivate(currentSource); currentActionSet = SteamVR_Input.GetActionSet("MySet"); currentlyAttachedObject = null; actionSetChanged = true; } catch (NullReferenceException) { Debug.LogWarning("detachCall Hand is null in OculusInput.cs"); return; } } //OBJECT ATTACH CODE --------------------------------------------------------------------------------------------------------------------------------- if (gripClick && hover.closestHoverObj != null && !attached) { try { ObjectInteraction attachCall = hover.closestHoverObj.GetComponent <ObjectInteraction>(); attached = attachCall.AttachObjectToController(this.gameObject, hover.hoverPoint); currentlyAttachedObject = hover.closestHoverObj; currentActionSet.Deactivate(currentSource); currentActionSet = SteamVR_Input.GetActionSet("Sword"); //CHANGE THIS LATER WHEN WE HAVE MORE THAN ONE ITEM TO PICK UP actionSetChanged = true; } catch (NullReferenceException) { Debug.LogWarning("attachCall Right Hand is null in OculusInput.cs"); return; } } //TRIGGER PRESS CODE --------------------------------------------------------------------------------------------------------------------------------- if (triggerValue > 0.1f) { int layerMask = (1 << 9); if (Physics.Raycast(transform.position, transform.forward - transform.up, out RaycastHit hit, 50f, layerMask)) { teleTarget.transform.position = hit.point; Debug.DrawRay(transform.position, (transform.forward - transform.up) * 100f, Color.blue, 5f); } } if (triggerValue > 0.75f && pressFlag)//Teleport using raycast { print("Teleport"); Debug.DrawRay(transform.position, transform.forward * 100f, Color.red); if (Physics.Raycast(transform.position, transform.forward - transform.up, out RaycastHit hit, 100f)) { cameraRig.transform.position = hit.point; } pressFlag = false; } if (triggerValue < 0.1f)//Must release or almost release trigger before teleporting again { pressFlag = true; } //JOYSTICK MOVEMENT CODE --------------------------------------------------------------------------------------------------------------------------------- if (moveValue.y > 0.1f || moveValue.y < -0.1f) {//Forward and Backward Vector3 controllerMove = new Vector3(((transform.forward - transform.up).normalized).x, 0f, (((transform.forward - transform.up).normalized).z)); cameraRig.transform.Translate(controllerMove * moveValue.y); } if (moveValue.x > 0.1f || moveValue.x < -0.1f) {//Right and Left Vector3 controllerMove = new Vector3(transform.right.x, 0f, transform.right.z); cameraRig.transform.Translate(controllerMove * moveValue.x); } }