// 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"); }
public static void InitializeHandles() { if (!Application.isPlaying || s_actionInitialized) { return; } s_actionInitialized = true; InitializePaths(); SteamVR.Initialize(); #if VIU_STEAMVR_2_2_0_OR_NEWER SteamVR_ActionSet_Manager.UpdateActionStates(); #elif VIU_STEAMVR_2_1_0_OR_NEWER SteamVR_ActionSet_Manager.UpdateActionSetsState(); #else SteamVR_ActionSet.UpdateActionSetsState(); #endif var vrInput = OpenVR.Input; if (vrInput == null) { Debug.LogError("Fail loading OpenVR.Input"); return; } pressActions.InitiateHandles(vrInput); touchActions.InitiateHandles(vrInput); v1Actions.InitiateHandles(vrInput); v2Actions.InitiateHandles(vrInput); vibrateActions.InitiateHandles(vrInput); s_actionSetHandle = SafeGetActionSetHandle(vrInput, ACTION_SET_PATH); }
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); }
private void Awake() { if (actionSet == null) { actionSet = SteamVR_Actions.Controller_Tests; } actionSet.Activate(SteamVR_Input_Sources.Any, 0, true); Left_Hand_Skeleton = SteamVR_Actions.Controller_Tests.Left_Hand_Skeleton; triggered = SteamVR_Actions.Controller_Tests.Left_Trigger_Click; triggered[SteamVR_Input_Sources.Any].onStateDown += PreformAction; }
public static void InitializeHandles() { if (!Application.isPlaying || s_actionInitialized) { return; } s_actionInitialized = true; InitializePaths(); SteamVR.Initialize(); #if VIU_STEAMVR_2_2_0_OR_NEWER SteamVR_ActionSet_Manager.UpdateActionStates(); #elif VIU_STEAMVR_2_1_0_OR_NEWER SteamVR_ActionSet_Manager.UpdateActionSetsState(); #else SteamVR_ActionSet.UpdateActionSetsState(); #endif var vrInput = OpenVR.Input; if (vrInput == null) { Debug.LogError("Fail loading OpenVR.Input"); return; } pressActions.ResolveHandles(vrInput); touchActions.ResolveHandles(vrInput); v1Actions.ResolveHandles(vrInput); v2Actions.ResolveHandles(vrInput); vibrateActions.ResolveHandles(vrInput); s_actionSetHandle = SafeGetActionSetHandle(vrInput, ACTION_SET_PATH); skeletonActionHandleLeft = SafeGetActionHandle(vrInput, ACTION_SET_PATH + "/in/viu_skeleton_left"); skeletonActionHandleRight = SafeGetActionHandle(vrInput, ACTION_SET_PATH + "/in/viu_skeleton_right"); if (skeletonActionHandleLeft == OpenVR.k_ulInvalidActionHandle) { Debug.LogWarning("Skeleton action for left hand is not found: " + ACTION_SET_PATH + "/in/viu_skeleton_left"); } if (skeletonActionHandleRight == OpenVR.k_ulInvalidActionHandle) { Debug.LogWarning("Skeleton action for right hand is not found: " + ACTION_SET_PATH + "/in/viu_skeleton_right"); } }
public void ToggleOnlyThisActionSet(SteamVR_ActionSet targetActionSet) { SteamVR_ActionSet_Manager.DisableAllActionSets(); defaultActions.Activate(); targetActionSet.Activate(); }
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); } }