// Start is called before the first frame update. void Start() { select = SteamVR_Input.GetBooleanAction("SelectRobotWithLaser"); }
public override void Initialize(ActionCanvasBase actionCanvasBase) { base.Initialize(actionCanvasBase); actionAxis = SteamVR_Input.GetAction <SteamVR_Action_Vector2>(actionName + "Axis"); }
private void Start() { Trigger = SteamVR_Input.GetBooleanAction("Trigger"); RTC = GetComponentInChildren <RotateTowardsCamera>(); }
private void Awake() { Log.Info("Snapturn init"); smoothTurn = SteamVR_Input.GetVector2Action("SnapTurn"); }
public void Button_OpenBindingsUI() { OpenVR.Overlay.ShowDashboard(null); SteamVR_Input.OpenBindingUI(mainActionSet, SteamVR_Input_Sources.Any); }
// Update is called once per frame void Update() { SteamVR_Action_Boolean dropAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("drop"); //Vector2 touch = SteamVR_Input.GetVector2Action("joystick_touchpad").axis; if (dropAction.stateDown) { if (leftHand.GetDeviceIndex() == dropAction.trackedDeviceIndex) { leftHand.DetachObject(leftHand.AttachedObjects[0].attachedObject); } else if (rightHand.GetDeviceIndex() == dropAction.trackedDeviceIndex) { rightHand.DetachObject(rightHand.AttachedObjects[0].attachedObject); } } //print("Trigger Axis: " + SteamVR_Input.GetAction<SteamVR_Action_Single>("triggerpullanimate").axis); //print("touch x : " + touch.x); //print("touch y: " + touch.y); SteamVR_Action_Boolean grabAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("grabpinch"); if (grabAction.stateDown) { if (leftHand.GetDeviceIndex() == grabAction.trackedDeviceIndex) { Transform modelTransform = leftHand.AttachedObjects[0].attachedObject.transform.GetChild(0); modelTransform.localPosition = leftHandGunPos; modelTransform.gameObject.GetComponent <Renderer>().material.shader = standardShader; } else if (rightHand.GetDeviceIndex() == grabAction.trackedDeviceIndex) { Transform modelTransform = rightHand.AttachedObjects[0].attachedObject.transform.GetChild(0); modelTransform.localPosition = rightHandGunPos; modelTransform.gameObject.GetComponent <Renderer>().material.shader = standardShader; } } SteamVR_Action_Boolean fireAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("fire"); if (fireAction.stateDown || (useMouseForTesting && Input.GetMouseButtonDown(0))) { if (leftHand.GetDeviceIndex() == fireAction.trackedDeviceIndex) { selectedGun = leftHand.AttachedObjects[0].attachedObject; } else if (rightHand.GetDeviceIndex() == fireAction.trackedDeviceIndex) { selectedGun = rightHand.AttachedObjects[0].attachedObject; } Transform shellOrigin = selectedGun.GetComponent <PickUpWeapon>().shellOrigin; Rigidbody rb = Instantiate <Rigidbody>(shellPrefab.GetComponent <Rigidbody>(), shellOrigin.position, shellOrigin.rotation); // If this were attached to the gun itself, could use Vector3.right here instead, it'd be a helluvalot simpler rb.velocity = Vector3.Normalize(-shellOrigin.forward); if (!useMouseForTesting) { SteamVR_Input.GetAction <SteamVR_Action_Vibration>("Haptic").Execute(0, vibrationDuration, vibrationFrequency, vibrationAmplitute, source); } shotgunBlast.Play(); RaycastHit hit = new RaycastHit(); Transform rayOrigin = selectedGun.transform; bool is2dHit = useMouseForTesting && Physics.Raycast(camera.ScreenPointToRay(Input.mousePosition), out hit, 300f, mask); // click to fire at the drones on desktop Ray r = new Ray(rayOrigin.position, rayOrigin.forward); if (is2dHit || Physics.Raycast(r, out hit, Mathf.Infinity, mask)) { print("hit object name: " + hit.transform.name); TakeDamage td = hit.transform.GetComponent <TakeDamage>(); /*ParticleSystem p = Instantiate<ParticleSystem>(sparkParticlePrefab.GetComponent<ParticleSystem>(), hit.point, Quaternion.LookRotation(hit.normal)); * * ParticleSystem.MainModule main = p.main; * ParticleSystem.Burst burst = new ParticleSystem.Burst(0, 10 * (100 - td.health)); * p.emission.SetBurst(0, burst); * * main.startSpeed = 160f * ((100 - td.health) / 25); * main.startLifetime = .4f * (td.health / 100);*/ td.takeDamage(hitDamage, hit, r, mask); hit.transform.GetComponent <AudioSource>().Play(); /*print("textureCoord.x: " + hit.textureCoord.x); * print("textureCoord.y: " + hit.textureCoord.y); */ } } }
// Update is called once per frame void Update() { grabState = SteamVR_Input.GetBooleanAction("GrabPinch").GetState(SteamVR_Input_Sources.RightHand); }
/// <summary> /// Handles grasping behaviour. /// </summary> private void HandleGrasp() { // Check manager type and if requested to interact. if (managerType == GraspManagerType.Assisted || (managerType == GraspManagerType.Controller && SteamVR_Input.GetAction <SteamVR_Action_Boolean>("ObjectInteractButton").GetStateDown(SteamVR_Input_Sources.Any))) { if (objectGraspable == null) { throw new System.NullReferenceException("There was no object found within grasp."); } // Attach object to hand with hand Tracking script objectInHand = objectGraspable; oIHHandTracker = objectInHand.AddComponent <ObjectGraspHandle>(); oIHHandTracker.handTransform = attachmentPoint; // Check whether the object is interactable and set if so. IInteractable interactionScript = objectInHand.GetComponent <IInteractable>(); if (interactionScript != null) { isInteractable = true; objectInteraction = interactionScript; } // clear flag and handle inGrasp = false; objectGraspable = null; } }
static Player_Vive() { Teleprot = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("Teleport"); GrabPinch = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("GrabPinch"); }
// Update is called once per frame void Update() { anchorUIToLeftController(); Vector3 raycastStart = rightHand.transform.position; //Vector3 raycastDir = (playerCameraContainer.transform.rotation * initialCameraForward).normalized; Vector3 raycastDir = rightHand.transform.forward.normalized; // just need to show if its true (pressed or held down) bool usingSelectInput = SteamVR_Input.GetBooleanAction("SelectInput").GetState(SteamVR_Input_Sources.RightHand); // only want to know if pressed bool usingCommandInput = SteamVR_Input.GetBooleanAction("CommandInput").GetStateDown(SteamVR_Input_Sources.RightHand); bool selectHeldDown = (usingSelectInput && !SteamVR_Input.GetBooleanAction("SelectInput").GetStateUp(SteamVR_Input_Sources.RightHand) && !SteamVR_Input.GetBooleanAction("SelectInput").GetStateDown(SteamVR_Input_Sources.RightHand)); raycastLine.SetPosition(0, raycastStart + raycastOffset); raycastLine.SetPosition(1, raycastStart + raycastDir * raycastLength); if (isBlueCastleSelected) { blueCastle.GetComponent <BlueCastle>().ShowSpawnRange(); } else { blueCastle.GetComponent <BlueCastle>().HideSpawnRange(); } if (usingSelectInput) { if (isRectangularSelecting) { RaycastHit hit; Ray ray = new Ray(raycastStart + raycastOffset, raycastDir); if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR))) { rectangularSelectingEnd = hit.point; clearHoveredUnits(); List <Collider> colliders = rectangularSelectionBox.GetComponent <OverlapBox>().GetColliders(); foreach (Collider collider in colliders) { GameObject currObj = collider.gameObject; if (currObj && currObj.layer == LayerMask.NameToLayer(LAYER_SOLDIER) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Hover blue soldiers { hoverUnit(currObj); } /* * else if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE) && currObj.GetComponent<TeamColors>().IsBlueTeam()) // Hover blue castle * { * clearHoveredUnits(); * hoverUnit(currObj); * blueCastle.GetComponent<BlueCastle>().ShowSpawnRange(); * break; * } */ } } } else if (selectHeldDown) { RaycastHit hit; Ray ray = new Ray(raycastStart + raycastOffset, raycastDir); if (!isDraggingSlider) { if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI))) { sliderInitialPos = rightHand.transform.localPosition; isDraggingSlider = true; } } else { Vector3 deltaPos = calculateCurrFramePositionDelta(rightHand); blueCastle.GetComponent <BlueCastle>().changeSliderValue(-deltaPos.x / 50.0f); } } else { RaycastHit hit; Ray ray = new Ray(raycastStart + raycastOffset, raycastDir); if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR))) { rectangularSelectingStart = hit.point; rectangularSelectingEnd = hit.point; isRectangularSelecting = true; } if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI))) { //if (currObj.layer == LayerMask.NameToLayer(LAYER_UNIT_UI) && currObj.GetComponent<TeamColors>().IsBlueTeam()) // Select blue castle //{ // clearSelectedUnits(); // dehoverUnit(currObj); // selectUnit(currObj); //} } if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE, LAYER_SOLDIER, LAYER_FLOOR, LAYER_UNIT_UI))) { GameObject currObj = hit.transform.gameObject; if (currObj.layer == LayerMask.NameToLayer(LAYER_FLOOR)) // Deselect by clicking floor { clearSelectedUnits(); } else if (currObj.layer == LayerMask.NameToLayer(LAYER_SOLDIER) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Select blue soldiers { currObj.GetComponents <AudioSource>()[0].Play(); dehoverUnit(currObj); selectUnit(currObj); if (isBlueCastleSelected) { deselectUnit(blueCastle); } } else if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE) && currObj.GetComponent <TeamColors>().IsBlueTeam()) // Select blue castle { clearSelectedUnits(); dehoverUnit(currObj); selectUnit(currObj); } } } // release all boolean if (SteamVR_Input.GetBooleanAction("CommandInput").GetStateUp(SteamVR_Input_Sources.RightHand)) { isRectangularSelecting = false; isBlueCastleSelected = false; isUnitUISelected = false; } } else if (usingCommandInput) { RaycastHit hit; Ray ray = new Ray(raycastStart + raycastOffset, raycastDir); if (!isBlueCastleSelected && Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE))) { if (hit.transform.gameObject.GetComponent <TeamColors>().IsBlueTeam()) { blueCastle.GetComponent <BlueCastle>().toggleBaseMenu(); } } if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_UNIT_UI))) { blueCastle.GetComponent <BlueCastle>().toggleCurrentUnit(); } if (isBlueCastleSelected && Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR))) { blueCastle.GetComponent <BlueCastle>().SpawnSoldierInRange(hit.point); } else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE))) { if (hit.transform.gameObject.GetComponent <TeamColors>().IsRedTeam()) { AttackWithSelectedUnits(hit.transform.gameObject); } } else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_RESOURCE))) { GatherWithSelectedUnits(hit.transform.gameObject); } else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_SOLDIER))) { if (hit.transform.gameObject.GetComponent <TeamColors>().IsRedTeam()) { AttackWithSelectedUnits(hit.transform.gameObject); } } else if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_FLOOR))) { DefendWithSelectedUnits(hit.point); } } else { if (isRectangularSelecting) // Complete rectangular selection { isRectangularSelecting = false; List <GameObject> toSelect = new List <GameObject>(); foreach (GameObject hovered in hoveredUnits) { if (!selectedUnits.Contains(hovered)) { toSelect.Add(hovered); } hovered.GetComponents <AudioSource>()[0].Play(); } clearHoveredUnits(); foreach (GameObject hovered in toSelect) { selectUnit(hovered); } } else // Single unit hover { clearHoveredUnits(); RaycastHit hit; Ray ray = new Ray(raycastStart + raycastOffset, raycastDir); if (Physics.Raycast(ray, out hit, raycastLength, LayerMask.GetMask(LAYER_CASTLE, LAYER_SOLDIER, LAYER_RESOURCE))) { GameObject currObj = hit.transform.gameObject; if (!selectedUnits.Contains(currObj)) { hoverUnit(currObj); if (currObj.layer == LayerMask.NameToLayer(LAYER_CASTLE)) { blueCastle.GetComponent <BlueCastle>().ShowSpawnRange(); } } } } } if (isRectangularSelecting) { rectangularSelectionLine.gameObject.SetActive(true); float xDiff = rectangularSelectingEnd.x - rectangularSelectingStart.x; float zDiff = rectangularSelectingEnd.z - rectangularSelectingStart.z; rectangularSelectionLine.SetPosition(0, rectangularSelectingStart + new Vector3(0.0f, 0.5f, 0.0f)); rectangularSelectionLine.SetPosition(1, rectangularSelectingStart + new Vector3(xDiff, 0.5f, 0.0f)); rectangularSelectionLine.SetPosition(2, rectangularSelectingEnd + new Vector3(0.0f, 0.5f, 0.0f)); rectangularSelectionLine.SetPosition(3, rectangularSelectingStart + new Vector3(0.0f, 0.5f, zDiff)); rectangularSelectionLine.SetPosition(4, rectangularSelectingStart + new Vector3(0.0f, 0.5f, 0.0f)); rectangularSelectionBox.gameObject.SetActive(true); rectangularSelectionBox.transform.position = rectangularSelectingStart + new Vector3(xDiff / 2.0f, 0.0f, zDiff / 2.0f); rectangularSelectionBox.transform.localScale = new Vector3(Mathf.Abs(xDiff), rectangularSelectionBox.transform.localScale.y, Mathf.Abs(zDiff)); } else { rectangularSelectionLine.gameObject.SetActive(false); rectangularSelectionBox.gameObject.SetActive(false); } listenAndCastMeteor(); listenAndExecuteFlying(); }
public void Init() { // Get control input settings from script ViveControlInputs = new Dictionary <ViveControlType, ViveControlInput>(); ViveControlInputs.Add(ViveControlType.Grip, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "grip"))); ViveControlInputs.Add(ViveControlType.Trigger, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "trigger"))); ViveControlInputs.Add(ViveControlType.Touchpad, new ViveControlInput(SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "touchpadclick"), SteamVR_Input.GetAction <SteamVR_Action_Boolean>("srinput", "touchpadtouch"), SteamVR_Input.GetAction <SteamVR_Action_Vector2>("srinput", "touchpadposition"))); //// Get control input settings from inspector //for (int i = 0; i < (int)ViveControlType.Max; ++i) // ViveControlInputs[(ViveControlType)i] = ViveControlInputList[i]; // Disable 2D Player.instance.allowToggleTo2D = false; // Get hand and add listener to each button hand = ViveSR_Experience.instance.targetHand; for (int i = 0; i < (int)ViveControlType.Max; ++i) { ViveControlType type = (ViveControlType)i; if (type == ViveControlType.Touchpad) { ViveControlInputs[type].actionTouch.AddOnUpdateListener(ClickListener, hand.handType); } ViveControlInputs[type].actionClick.AddOnUpdateListener(ClickListener, hand.handType); } }
void OnEnable() { //if we're firing OnEnable, this means any compilation has ended. We're good! loadingCustomDefine = false; //look for CurvedUI custom eventsystem, if it makes sense to have it if (PlayerSettings.virtualRealitySupported) { CUIeventSystemPresent = (FindObjectsOfType(typeof(CurvedUIEventSystem)).Length > 0); //Debug.Log("OnEnable: found CUI Event system: " + CUIeventSystemPresent); } //hacky way to make sure event is connected only once, but it works! #if UNITY_2018 || UNITY_2019 EditorApplication.hierarchyChanged -= AddCurvedUIComponents; EditorApplication.hierarchyChanged -= AddCurvedUIComponents; EditorApplication.hierarchyChanged += AddCurvedUIComponents; #else //hacky way to make sure event is connected only once, but it works! EditorApplication.hierarchyWindowChanged -= AddCurvedUIComponents; EditorApplication.hierarchyWindowChanged -= AddCurvedUIComponents; EditorApplication.hierarchyWindowChanged += AddCurvedUIComponents; #endif //check if the currently selected control method is enabled in editor. //Otherwise, show error. if (Application.isPlaying) { CurvedUISettings myTarget = (CurvedUISettings)target; string define = PlayerSettings.GetScriptingDefineSymbolsForGroup(EditorUserBuildSettings.selectedBuildTargetGroup); foreach (var key in ControlMethodDefineDict.Keys) { if (myTarget.ControlMethod == key && !define.Contains(ControlMethodDefineDict[key])) { Debug.LogError("CURVEDUI: Selected control method (" + key.ToString() + ") is not enabled. Enable it on CurvedUISettings component", myTarget.gameObject); } } } #if CURVEDUI_STEAMVR_2 //Get action and their paths to show in the popup. steamVRActions = SteamVR_Input.GetActions <SteamVR_Action_Boolean>(); steamVRActionsPaths = new string[] { "None" }; if (steamVRActions != null && steamVRActions.Length > 0) { List <string> enumList = new List <string>(); //add all action paths to list. for (int i = 0; i < steamVRActions.Length; i++) { enumList.Add(steamVRActions[i].fullPath); } enumList.Add("None"); //need a way to null that field, so add None as last pick. //replace forward slashes with backslack instead. Otherwise they will not show up. for (int index = 0; index < enumList.Count; index++) { enumList[index] = enumList[index].Replace('/', '\\'); } steamVRActionsPaths = enumList.ToArray(); } #endif }
// Start is called before the first frame update void Start() { m_LeftThumbstick = SteamVR_Input.GetVector2Action("thumbstickleftmove"); }
public Dictionary <string, SteamVR_Action_Vector2_Source> GenerateAxis2DInputMap() => new Dictionary <string, SteamVR_Action_Vector2_Source>() { { VRAxis.One, SteamVR_Input.GetAction <SteamVR_Action_Vector2>("default", "Joystick")[SteamHand] }, { VRAxis.OneRaw, SteamVR_Input.GetAction <SteamVR_Action_Vector2>("default", "Joystick")[SteamHand] }, };
protected override void FillMetadata(HandAnchor anchor, ref XRNodeState xRNode) { //base.UpdateHandNodeState(hand, ref xRNode); float thumb = 0f, index = 0f, middle = 0f; //psotion && rotation xRNode.TryGetPosition(out anchor.position); xRNode.TryGetRotation(out anchor.rotation); var inputSource = SteamVR_Input_Sources.LeftHand; string skeletonHandName = "SkeletonLeftHand"; if (anchor.type == NodeType.RightHand) { inputSource = SteamVR_Input_Sources.RightHand; skeletonHandName = "skeletonRightHand"; } //SteamVR_Action_Boolean key_MenuKey = SteamVR_Input.GetBooleanAction("MenuKey"); //SteamVR_Action_Boolean key_SystemKey = SteamVR_Input.GetBooleanAction("SystemKey"); //trigger SteamVR_Action_Boolean triggerPressed = SteamVR_Input.GetBooleanAction("Trigger"); //SteamVR_Action_Single triggerTouchValue = SteamVR_Input.GetSingleAction("triggerTouchValue"); anchor.triggerPressed = triggerPressed.GetState(inputSource); anchor.triggerTouchValue = Mathf.Lerp(anchor.triggerTouchValue, anchor.triggerPressed ? 1f : 0f, Time.deltaTime * 5); index = anchor.triggerTouchValue; //grip SteamVR_Action_Boolean gripPressed = SteamVR_Input.GetBooleanAction("SideTrigger"); //SteamVR_Action_Single gripTouchValue = SteamVR_Input.GetSingleAction("gripTouchValue"); anchor.gripPressed = gripPressed.GetState(inputSource); anchor.gripTouchValue = Mathf.Lerp(anchor.gripTouchValue, anchor.gripPressed ? 1f : 0f, Time.deltaTime * 5); middle = anchor.gripTouchValue; //primary2DAxis SteamVR_Action_Vector2 primary2DAxis = SteamVR_Input.GetVector2Action("ThumbStick"); SteamVR_Action_Boolean primary2DAxisClick = SteamVR_Input.GetBooleanAction("PadDown"); anchor.primary2DAxis = primary2DAxis.GetAxis(inputSource); anchor.primary2DAxisTouch = anchor.primary2DAxis.sqrMagnitude > 0.02f; anchor.primary2DAxisPressed = primary2DAxisClick.GetState(inputSource); thumb = Mathf.Max(thumb, (anchor.primary2DAxisPressed || anchor.primary2DAxisTouch) ? 1f : 0f); thumb = Mathf.Max(thumb, anchor.primary2DAxis.sqrMagnitude > 0.1f ? 1f : 0f); //primary SteamVR_Action_Boolean primaryPressed = SteamVR_Input.GetBooleanAction("BKey"); anchor.primaryPressed = primaryPressed.GetState(inputSource); anchor.primaryTouchValue = (anchor.primaryPressed) ? 1f : 0f; thumb = Mathf.Max(thumb, anchor.primaryTouchValue); //secondary SteamVR_Action_Boolean secondaryPressed = SteamVR_Input.GetBooleanAction("AKey"); anchor.secondaryPressed = secondaryPressed.GetState(inputSource); anchor.secondaryTouchValue = (anchor.secondaryPressed) ? 1f : 0f; thumb = Mathf.Max(thumb, anchor.secondaryTouchValue); //fingers var skeletonHand = SteamVR_Input.GetAction <SteamVR_Action_Skeleton>(skeletonHandName); if (skeletonHand.poseIsValid) { anchor.handPoseChanged = skeletonHand.poseChanged; anchor.fingerCurls[0] = skeletonHand.thumbCurl; anchor.fingerCurls[1] = skeletonHand.indexCurl; anchor.fingerCurls[2] = skeletonHand.middleCurl; anchor.fingerCurls[3] = skeletonHand.ringCurl; anchor.fingerCurls[4] = skeletonHand.pinkyCurl; } else { anchor.handPoseChanged = true; anchor.fingerCurls[0] = thumb; anchor.fingerCurls[1] = index; anchor.fingerCurls[2] = middle; anchor.fingerCurls[3] = middle; anchor.fingerCurls[4] = middle; } }
public float GetValue(SteamVR_Input_Sources source) { return(SteamVR_Input.GetSingleAction("default", inputName).GetAxis(source)); }
public void Awake() { Cursor.lockState = CursorLockMode.Locked; Cursor.visible = false; if (!photonView.IsMine && PhotonNetwork.IsConnected) { this.enabled = false; } else { // _instance = this; _currentInput.PositionInput = Vector3.zero; _currentInput.RotationInput = Vector3.zero; _playerMovement = GetComponent <PlayerMovement>(); if (CheckComponentValue()) { Debug.Log("Player InputController : Components are Unset, Please Check Object"); gameObject.SetActive(false); } _playerCameraComponent = PlayerCamera.GetComponent <Camera>(); _playerCameraComponent.enabled = true; PlayerCamera.GetComponent <AudioListener>().enabled = true; _leftHandAction = PlayerHandL.GetComponent <PlayerHandAction>(); _rightHandAction = PlayerHandR.GetComponent <PlayerHandAction>(); // Delegate : Bind Input by Controller Type if (XRDevice.isPresent) { _trackedObjRightHand = PlayerHandR.GetComponent <SteamVR_Behaviour_Pose>(); _trackedObjLeftHand = PlayerHandL.GetComponent <SteamVR_Behaviour_Pose>(); _north = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("North"); _south = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("South"); _west = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("West"); _east = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("East"); _interaction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("InteractUI"); InputBinderForUpdate += new InputBinder(SVRPositionInput); InputBinderForUpdate += new InputBinder(SVRRotationInput); InputBinderForUpdate += new InputBinder(SVRActionInput); _leftHandAction.SetVRPlayerHandProperties(true); _rightHandAction.SetVRPlayerHandProperties(false); } else { InputBinderForUpdate += new InputBinder(KMPositionInput); InputBinderForUpdate += new InputBinder(KMRotationInput); InputBinderForUpdate += new InputBinder(KMActionInput); _leftHandAction.SetKMPlayerHandProperties(KMPlayerHandLenght, "Fire1", true); _rightHandAction.SetKMPlayerHandProperties(KMPlayerHandLenght, "Fire2", false); } } }
// Update is called once per frame void Update() { Player player = Player.instance; if (!player) { return; } //EVRButtonId touchPad = EVRButtonId.k_EButton_SteamVR_Touchpad; SteamVR_Input_ActionSet_default touchpad = new SteamVR_Input_ActionSet_default(); SteamVR_Action_Boolean teleportAction = SteamVR_Input.GetAction <SteamVR_Action_Boolean>("Teleport"); if (null != player.leftHand) { Quaternion orientation = Camera.main.transform.rotation; var touchPadVector = touchpad.MovementAction.GetAxis(SteamVR_Input_Sources.LeftHand); Vector3 moveDirection = orientation * Vector3.forward * touchPadVector.y + orientation * Vector3.right * touchPadVector.x; Vector3 pos = player.transform.position; bool doRun = teleportAction.GetState(SteamVR_Input_Sources.LeftHand); if (invertedRunTrigger) { doRun = !doRun; } float adjustedMoveSpeed = moveSpeed; if (doRun) { adjustedMoveSpeed = runSpeed; } pos.x += moveDirection.x * adjustedMoveSpeed * Time.deltaTime; pos.z += moveDirection.z * adjustedMoveSpeed * Time.deltaTime; player.transform.position = pos; } if (allowHeadCamera) { if (null != player.rightHand) { Quaternion orientation = player.transform.rotation; var touchPadVector = touchpad.MovementAction.GetAxis(SteamVR_Input_Sources.RightHand); Vector3 euler = transform.rotation.eulerAngles; float angle = 0; if (allowVerticalHeadCamera) { if (headVerticalInverted) { angle = GetAngle(touchPadVector.y); } else { angle = GetAngle(-touchPadVector.y); } } euler.x = Mathf.LerpAngle(euler.x, angle, verticalTurnSpeed * Time.deltaTime); euler.y += touchPadVector.x * horizontalTurnSpeed * Time.deltaTime; player.transform.rotation = Quaternion.Euler(euler); } } }
void Update() { rTriggerState = SteamVR_Input.GetState("InteractUI", SteamVR_Input_Sources.RightHand); lTriggerState = SteamVR_Input.GetState("InteractUI", SteamVR_Input_Sources.LeftHand); if (lTriggerState && selectedHand == "right") { selectedHand = "left"; pStateController.SelectHand("left"); } else if (rTriggerState && selectedHand == "left") { selectedHand = "right"; pStateController.SelectHand("right"); } selectedTriggerState = (selectedHand == "right") ? rTriggerState : lTriggerState; if (selectedTriggerState == true) { if (EventSystem.current.currentSelectedGameObject != null) { ExecuteEvents.Execute(EventSystem.current.currentSelectedGameObject, new BaseEventData(EventSystem.current), ExecuteEvents.submitHandler); } } x_ButtonState = SteamVR_Input.GetState("ResetHeight", SteamVR_Input_Sources.LeftHand); if (x_ButtonState == true) { player.transform.localScale = Vector3.one * (playerHeight / player.eyeHeight); } if (itemAttached && itemAttached.CompareTag("popcan")) { popcanBehaviour pb = itemAttached.GetComponent <popcanBehaviour>(); if (hand.currentAttachedObject == null) { pb.inHand = false; pb.ResetMaterial(); } else { pb.inHand = true; } } if (itemAttached && itemAttached.CompareTag("bomb")) { bombBehaviour bb = itemAttached.GetComponent <bombBehaviour>(); if (hand.currentAttachedObject == null) { bb.inHand = false; } else { bb.hand = hand; bb.inHand = true; bb.triggerPressed = rTriggerState; } } //itemAttached = hand.currentAttachedObject; if (itemAttached && itemAttached.CompareTag("spray")) { sprayCan sc = itemAttached.GetComponent <sprayCan>(); sc.inHand = false; if (gameObject.GetComponent <Hand>().currentAttachedObject != null) { sc.inHand = true; } sc.TriggerState(rTriggerState); } if (itemAttached && itemAttached.CompareTag("fence")) { fenceTool fence = itemAttached.GetComponent <fenceTool>(); if (gameObject.GetComponent <Hand>().currentAttachedObject == null) { fence.inHand = false; } else { fence.inHand = true; } } itemAttached = gameObject.GetComponent <Hand>().currentAttachedObject; pauseButtonState = SteamVR_Input.GetState("Pause", SteamVR_Input_Sources.LeftHand); if (pauseButtonState == true) { if (GameManager.gm.paused) { GameManager.gm.paused = false; GameManager.gm.UnPaused(); } else { GameManager.gm.paused = true; GameManager.gm.Paused(); } } }
//------------------------------------------------- // Called every Update() while a Hand is hovering over this object //------------------------------------------------- private void HandHoverUpdate(Hand hand) { /* * if (isAvailable) * { * * GrabTypes startingGrabType = hand.GetGrabStarting(); * bool isGrabEnding = hand.IsGrabEnding(this.gameObject); * * if (interactable.attachedToHand == null && startingGrabType != GrabTypes.None) * { * if (activeSocket) * { * activeSocket.InteractSlot(hand); * return; * } * * HandsAttached = 1; * grabbingHand = hand; * hand.HoverLock(interactable); * * // Attach this object to the hand * hand.AttachObject(gameObject, startingGrabType, attachmentFlags, grabposition); * } * else if (isGrabEnding) * { * // Detach this object from the hand * hand.DetachObject(gameObject, restoreParent); * * // Call this to undo HoverLock * hand.HoverUnlock(interactable); * * * } */ if (isAvailable) { if (grabTypes == MyGrabTypes.Press) { if (SteamVR_Input.GetStateDown("Shoot", hand.handType)) { if (activeSocket) { activeSocket.InteractSlot(hand); return; } if (hand.ObjectIsAttached(this.gameObject)) { // Detach this object from the hand hand.DetachObject(gameObject, restoreParent); // Call this to undo HoverLock hand.HoverUnlock(interactable); } else { HandsAttached = 1; grabbingHand = hand; hand.HoverLock(interactable); // Attach this object to the hand hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition); } } } else if (grabTypes == MyGrabTypes.Hold) { if (SteamVR_Input.GetStateUp("Shoot", hand.handType)) { if (hand.ObjectIsAttached(this.gameObject)) { // Detach this object from the hand hand.DetachObject(gameObject, restoreParent); // Call this to undo HoverLock hand.HoverUnlock(interactable); } } else if (SteamVR_Input.GetStateDown("Shoot", hand.handType)) { if (!hand.ObjectIsAttached(this.gameObject)) { HandsAttached = 1; grabbingHand = hand; hand.HoverLock(interactable); // Attach this object to the hand hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition); } } } else { if (SteamVR_Input.GetStateDown("Shoot", hand.handType)) { if (!hand.ObjectIsAttached(this.gameObject)) { HandsAttached = 1; grabbingHand = hand; hand.HoverLock(interactable); // Attach this object to the hand hand.AttachObject(gameObject, GrabTypes.Scripted, attachmentFlags, grabposition); } } } } }
void Tutorial() { if (instructions[8].active) { return; } if (instructions[5].active || instructions[7].active) { if (SteamVR_Input.GetStateDown("InteractUI", SteamVR_Input_Sources.Any)) { instructions[5].active = false; instructions[7].active = false; ResetInstructions(); currentTrialGenerator.StartExperiment(); } } if (instructions[4].active || instructions[6].active) { if (SteamVR_Input.GetStateDown("InteractUI", SteamVR_Input_Sources.Any)) { instructions[4].active = false; instructions[6].active = false; ResetInstructions(); currentTrialGenerator.StartExperiment(); } } if (instructions[3].active) { if (SteamVR_Input.GetStateDown("InteractUI", SteamVR_Input_Sources.Any)) { if (currentTrialGenerator.PreferenceMode == PreferenceMode.DEPTH) { instructions[4].active = true; } else if (currentTrialGenerator.PreferenceMode == PreferenceMode.APPEARANCE) { instructions[6].active = true; } } } if (instructions[2].active) { if (SteamVR_Input.GetStateDown("InteractUI", SteamVR_Input_Sources.Any)) { CancelConfirmHint(); showConfrimHint = false; instructions[2].active = false; instructions[3].active = true; } } if (instructions[1].active) { if (SteamVR_Input.GetStateDown("Teleport", SteamVR_Input_Sources.Any)) { instructions[1].active = false; instructions[2].active = true; enhancementScriptWolski.toggle = !enhancementScriptWolski.toggle; enhancementScriptWanat.toggle = !enhancementScriptWolski.toggle; ConfirmHint(); } } if (instructions[0].active) { if (showChangeModeHint && SteamVR_Input.GetStateDown("Teleport", SteamVR_Input_Sources.Any)) { CancelChanegModeHint(); showChangeModeHint = false; instructions[0].active = false; instructions[1].active = true; enhancementScriptWolski.toggle = !enhancementScriptWolski.toggle; enhancementScriptWanat.toggle = !enhancementScriptWolski.toggle; } } }
private void Awake() { #if SDK_STEAM_VR hapticAction = SteamVR_Input.GetAction <SteamVR_Action_Vibration>("VRShooterKit", "Haptic"); #endif }