void Update() { if (controller == null) { if ((int)trackedObject.index != -1) { controller = SteamVR_Controller.Input((int)trackedObject.index); } else { return; } } if (controller.GetPress(gripButton)) { Vector3 deltaPos = transform.position - previousPos; cameraRig.position -= deltaPos; /*if (Vector3.Distance(transform.position, test) > 0.01f) { Debug.Log("triggered pulse " + transform.position.ToString() + " " + test.ToString()); controller.TriggerHapticPulse(1000); test = transform.position; } else { Debug.Log(Vector3.Distance(transform.position, test)); }*/ } if (controller.GetPressDown(triggerButton)) { canvas.gameObject.SetActive(!canvas.gameObject.activeInHierarchy); } canvas.position = transform.position; canvas.rotation = transform.rotation * Quaternion.Euler(90, 0, 0); previousPos = transform.position; }
void FixedUpdate() { device = SteamVR_Controller.Input ((int)trackedObj.index); if (device.GetTouch (SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log ("You are holding 'touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchDown on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated PressDown on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("You activated PressUp on the touchpad"); sphere.transform.position = Vector3.zero; sphere.GetComponent<Rigidbody>().velocity = Vector3.zero; sphere.GetComponent<Rigidbody>().angularVelocity = Vector3.zero; } }
void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); //if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) // BowlingMachine.bowlAgain(); }
// Use this for initialization void Start () { SteamVR_TrackedObject.EIndex index = GetComponentInParent<SteamVR_TrackedObject>().index; controller = new SteamVR_Controller.Device((uint)index); lineRenderer = GetComponent<LineRenderer>(); charge = transform.FindChild("Charge").gameObject; chargeOriginScale = charge.transform.localScale.y; }
void Update() { if (controller == null) { if ((int)trackedObject.index != -1) { controller = SteamVR_Controller.Input((int)trackedObject.index); } else { return; } } Vector3 pos = controllerTransform.position; pos = new Vector3(Mathf.Floor(pos.x), Mathf.Floor(pos.y), Mathf.Floor(pos.z)) + new Vector3(0.5f, 0.5f, 0.5f); RaycastHit hit; if (menuCollider.Raycast(new Ray(controllerTransform.position, controllerTransform.forward), out hit, 100f)) { if (menuCanvas.gameObject.activeInHierarchy) { lineRenderer.enabled = true; lineTransform.localScale = new Vector3(lineTransform.localScale.x, hit.distance / 32f, lineTransform.localScale.z); lineTransform.localPosition = new Vector3(0, 0, hit.distance / 32f); RaycastHit buttonHit; if (Physics.Raycast(new Ray(controllerTransform.position, controllerTransform.forward), out buttonHit, 100f) && controller.GetPressDown(triggerButton)) { VRBlockButton button = buttonHit.transform.GetComponent<VRBlockButton>(); if (button != null) { button.Click(); Debug.Log("clicked"); } } } } else { lineRenderer.enabled = false; if (controller.GetPress(triggerButton)) { for (int x = 0; x < block.GetLength(0); x++) { for (int y = 0; y < block.GetLength(1); y++) { for (int z = 0; z < block.GetLength(2); z++) { if (block[x, y, z].GetName() != "Air") { world.SetBlock((int)(pos.x + x), (int)(pos.y + y), (int)(pos.z + z), block[x, y, z].Copy()); } } } } } if (controller.GetPress(gripButton)) { world.SetBlock((int)pos.x, (int)pos.y, (int)pos.z, new AirBlock()); } } transform.position = Vector3.Lerp(transform.position, pos, Time.deltaTime * smoothPos); //transform.rotation = Quaternion.Lerp(transform.rotation, Quaternion.Euler(0, 0, 0), Time.deltaTime * smoothRot); if (update) { RenderCursor(); update = false; } }
// Use this for initialization void Start () { rightController = new SteamVR_Controller.Device(4); body = GetComponent<Rigidbody>(); aliveTime = 0.0f; ableToGravitate = true; }
void Start() { paused = false; menuscreen = GameObject.FindGameObjectWithTag ("Menu"); menuscreen.SetActive (false); myEventSystem = GameObject.Find("EventSystem").GetComponent<UnityEngine.EventSystems.EventSystem> (); GameObject[] shooters = GameObject.FindGameObjectsWithTag("Shooter"); left = l.GetComponent<basic_shoot>().controller; right = r.GetComponent<basic_shoot>().controller; }
private void Update() { controllerIndex = (uint)trackedController.index; device = SteamVR_Controller.Input((int)controllerIndex); if (hapticPulseCountdown > 0) { device.TriggerHapticPulse(hapticPulseStrength); hapticPulseCountdown -= 1; } }
// Use this for initialization void Start() { maxhealth = 100; health = maxhealth; level = 1; spawnEnd = false; levelEnd = false; levelStarted = true; timer = 60; left = b.GetComponent<basic_shoot>().controller; right = b1.GetComponent<basic_shoot>().controller; }
// Update is called once per frame void Update() { if (Controller == null) { Controller = SteamVR_Controller.Input((int)GetComponent<SteamVR_TrackedObject>().index); return; } // Get the input vector from kayboard or analog stick Vector3 directionVector; bool hydraJump = false; Vector2 touchpadaxis = Controller.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); directionVector = new Vector3(touchpadaxis.x, 0, touchpadaxis.y); hydraJump = Controller.GetPress(Valve.VR.EVRButtonId.k_EButton_Grip); if (old_vert_axis < 0.9f && Input.GetAxis("Vertical") >= 0.9f) { if (forward_input_delay < 0.4f && !transform.parent.GetComponent<AimScript>().IsAiming()) { motor.SetRunning(Mathf.Clamp((0.4f - forward_input_delay) / 0.2f, 0.01f, 1.0f)); running = true; } forward_input_delay = 0.0f; } forward_input_delay += Time.deltaTime; if (forward_input_delay > 0.4f || transform.parent.GetComponent<AimScript>().IsAiming()) { motor.SetRunning(0.0f); running = false; } if (running) { directionVector.z = 1.0f; } old_vert_axis = Input.GetAxis("Vertical"); if (directionVector != Vector3.zero) { // Get the length of the directon vector and then normalize it // Dividing by the length is cheaper than normalizing when we already have the length anyway var directionLength = directionVector.magnitude; directionVector = directionVector / directionLength; // Make sure the length is no bigger than 1 directionLength = Mathf.Min(1, directionLength); // Make the input vector more sensitive towards the extremes and less sensitive in the middle // This makes it easier to control slow speeds when using analog sticks directionLength = directionLength * directionLength; // Multiply the normalized direction vector by the modified length directionVector = directionVector * directionLength; } // Apply the direction to the CharacterMotor motor.inputMoveDirection = transform.rotation * directionVector; motor.inputJump = Input.GetButton("Jump") || hydraJump; }
// Update is called once per frame void Update() { dev = SteamVR_Controller.Input((int)tracked.index); if (dev.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("Shoot"); count++; if (count > fireRate) { if (!playerController) { playerController = GameObject.Find("LocalPlayer"); } playerController.GetComponent <JPInputController>().VRShoot(transform.parent.parent.gameObject.GetComponent <JPControlShip>().shipName); //laser.FireVR(); count = 0; } } }
void Update() { #if SteamVR_Legacy controller = SteamVR_Controller.Input((int)trackedObj.index); #endif mirroredObject(); ShowLaser(); RaycastHit hit; if (Physics.Raycast(trackedObj.transform.position, trackedObj.transform.forward, out hit, 100)) { hitPoint = hit.point; PickupObject(hit.transform.gameObject); if (pickedUpObject == true && lastSelectedObject == hit.transform.gameObject) { PadScrolling(hit.transform.gameObject); } ShowLaser(hit); } }
// Update is called once per frame void FixedUpdate() { if (potentialAdjust != null) { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { potentialAdjust.onPullStart(transform.position); } else if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { potentialAdjust.onPullChanged(transform.position); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { potentialAdjust.onPullEnd(transform.position); } } }
void Start() { gameManager = FindObjectOfType <GameManager>(); restart = gameManager.restartButton; quit = gameManager.quitButton; //quick test to determine if Calculate Standard Deviation is working trackedObj = GetComponent <SteamVR_TrackedObject>(); //viveControllerModel = GetComponentInChildren<SteamVR_RenderModel>().gameObject; device = SteamVR_Controller.Input((int)trackedObj.index); //InitializeDisplacementArray(); //standardDeviation=Vector3.zero; gloveSoundManager = GetComponent <GloveSoundManager>(); //gloveProperties = GetComponent<PhysicsProperties>(); }
// Update is called once per frame void Update() { left_device = SteamVR_Controller.Input((int)leftController.index); right_device = SteamVR_Controller.Input((int)rightController.index); if (left_device.GetPress(EVRButtonId.k_EButton_Axis0)) { transform.Translate(Camera.main.transform.forward * thrust * Time.deltaTime); } else if (right_device.GetPress(EVRButtonId.k_EButton_Axis0)) { transform.Translate(-Camera.main.transform.forward * thrust * Time.deltaTime); } if (health <= 0) { //Application.LoadLevel("Defeat"); } }
protected void OnManipulatorUpdated(SteamVR_Controller.Device state) { // simulate mouse touch events with the trigger if (state.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { if (TargetObject != null) { TargetObject.SendMessage("OnMouseDown"); } } if (state.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { if (TargetObject != null) { TargetObject.SendMessage("OnMouseUp"); } } }
protected virtual void Update() { timeRepeat -= Time.deltaTime; var controllerObject = GameObject.Find("RightController"); //HACK For trigger!!! bool triggerClicked = false; if (timeRepeat < 0) { try { trackedObject = controllerObject.GetComponent <SteamVR_TrackedObject>(); device = SteamVR_Controller.Input((int)trackedObject.index); triggerClicked = device.GetHairTriggerDown(); //Vector2 triggerPosition = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); //triggerClicked = triggerPosition.x > 0.999f; // trigger treshold seems to be 0.9f } catch (NullReferenceException e) { Debug.LogWarning(e.Message); } } if (triggerClicked && triggerTime < 0) { triggerPressed(); triggerTime = 1f; triggerClicked = false; } //reset button timeout if trigger button is up if (SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.FarthestRight)).GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { triggerTime = -1; } if (Input.GetMouseButtonDown(0)) { mousePressed(); } if (Input.GetKeyDown(KeyCode.LeftArrow)) { } }
private void logControllerInteraction(SteamVR_Controller.Device controller) { if (leftGripButtonDown) { Debug.Log("Grip Button was just pressed"); } if (leftGripButtonUp) { Debug.Log("Grip Button was just unpressed"); } if (leftTriggerButtonDown) { Debug.Log("Trigger Button was just pressed"); } if (leftTriggerButtonUp) { Debug.Log("Trigger Button was just unpressed"); } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)controller.index); if (!ballSpawned && device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { coroutine = SpawnTimer(1.0f); StartCoroutine(coroutine); ballClone = (GameObject)Instantiate(baseball, transform.position, transform.rotation); ballClone.GetComponent <Rigidbody>().velocity = transform.up * ballVelocity; ballSpawned = true; } if (Input.GetKeyDown(KeyCode.S)) { ballClone.GetComponent <Rigidbody>().velocity = transform.forward * ballVelocity; ballClone.GetComponent <BallHandler>().ballBeenHit = true; } }
// Update is called once per frame void Update() { if (!trackedObj) trackedObj = GetComponent<SteamVR_TrackedObject>(); if (trackedObj != null) { device = SteamVR_Controller.Input((int)trackedObj.index); } if (device != null) { triggerPress = device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger); triggerState = device.GetTouch(SteamVR_Controller.ButtonMask.Trigger); mainButtonPressed = device.GetTouch(SteamVR_Controller.ButtonMask.ApplicationMenu); secondaryButtonPressed = device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad); touchpadVector = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad); } }
// Use this for initialization void Start() { device = null; ourCollider = GetComponentInChildren <Collider>(); if (!ourCollider) { Debug.Log("collider is null"); } // set our controller device indices controller_left.SetDeviceIndex(LEFT_IND); controller_right.SetDeviceIndex(RIGHT_IND); Debug.Log("Left device index: " + (int)controller_left.index); Debug.Log("Right device index: " + (int)controller_right.index); GetComponent <cakeslice.Outline>().enabled = !GetComponent <cakeslice.Outline>().enabled; readGas = false; StartCoroutine(DelayGas(2)); }
public void OnManipulatorRightUpdated(SteamVR_Controller.Device state) { // right touchpad if (state.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { Vector2 touchAxis = state.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); Vector3 fwdDirection = HmdRotation * Vector3.forward; fwdDirection.y = 0f; // allow only planar movement Vector3 fwdDisplacement = fwdDirection.normalized * (editorMovementSpeed * inverseWorldScale[HighLogic.LoadedScene] * touchAxis.y) * Time.deltaTime; Vector3 rightDirection = HmdRotation * Vector3.right; rightDirection.y = 0f; // allow only planar movement Vector3 rightDisplacement = rightDirection.normalized * (editorMovementSpeed * inverseWorldScale[HighLogic.LoadedScene] * touchAxis.x) * Time.deltaTime; CurrentPosition += fwdDisplacement + rightDisplacement; } // right menu button if (state.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { Core.ResetInitialHmdPosition(); } // simulate mouse touch events with the trigger if (state.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorRight.FingertipCollidedGameObjects) { obj.SendMessage("OnMouseDown"); } } if (state.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorRight.FingertipCollidedGameObjects) { obj.SendMessage("OnMouseUp"); } } }
// Token: 0x06002030 RID: 8240 RVA: 0x0009EB34 File Offset: 0x0009CD34 private IEnumerator HapticPulses(SteamVR_Controller.Device controller, float flMagnitude, int nCount) { if (controller != null) { int nRangeMax = (int)Util.RemapNumberClamped(flMagnitude, 0f, 1f, 100f, 900f); nCount = Mathf.Clamp(nCount, 1, 10); ushort i = 0; while ((int)i < nCount) { ushort durationMicroSec = (ushort)Random.Range(100, nRangeMax); controller.TriggerHapticPulse(durationMicroSec, EVRButtonId.k_EButton_Axis0); yield return(new WaitForSeconds(0.01f)); ushort num = i + 1; i = num; } } yield break; }
// Update is called once per frame void Update() { // Swap hands if (Input.GetKeyDown(KeyCode.Tab)) { var temp = leftObj; leftObj = rightObj; rightObj = temp; } if (leftObj != null && (int)leftObj.index != -1) { leftDevice = SteamVR_Controller.Input((int)leftObj.index); } if (rightObj != null && (int)rightObj.index != -1) { rightDevice = SteamVR_Controller.Input((int)rightObj.index); } }
// Update is called once per frame void Update() { SteamVR_Controller.Device device = SteamVR_Controller.Input((int)rightController.index); if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { //dragging = false; BoardColiderSetFales(); Ray ray = new Ray(rightController.transform.position, rightController.transform.forward); //var ray = Camera.main.ScreenPointToRay(Input.mousePosition); RaycastHit hit; if (Physics.Raycast(ray, out hit)) { //hit 是被打到的物件 if (hit.transform.tag.Equals("Inputfield")) { InputField inputNumber = hit.transform.GetComponent <InputField> (); //Debug.Log ( hit.transform.name); int Number = inputArray.IndexOf(hit.transform.gameObject.GetComponent <InputField> ()); //inputNumber.name.Substring(1); speechenity.changeField(Number); Debug.Log(Number); } else if (hit.transform.tag.Equals("NOTE")) { showText.text = hit.transform.GetComponentInChildren <Card> ().Ctitle; showTextContent.text = hit.transform.GetComponent <Card>().Ctext; showAssn.text = hit.transform.GetComponentInChildren <Card> ().ASsn; showEtime.text = hit.transform.GetComponent <Card>().Etime.ToString(); showEstimate.text = hit.transform.GetComponent <Card>().Estimate.ToString(); Debug.Log("GetNote"); } //dragging = true; } BoardColiderSetTrue(); } }
void Update() { // Get the controller device. device = SteamVR_Controller.Input((int)trackedObj.index); // If something is selected. if (currentlySelectedObject != null) { // If there isn't a joint yet on the selected object. if (grabJoint == null && device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Connect(); } // If a joint does exist and the user releases the button else if (grabJoint != null && device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { // Disconnect the joint and store rigid body. Rigidbody rigidbody = Disconnect(); var origin = trackedObj.origin ? trackedObj.origin : trackedObj.transform.parent; if (origin != null) { rigidbody.velocity = origin.TransformVector(device.velocity); rigidbody.angularVelocity = origin.TransformVector(device.angularVelocity) * 0.01f; } else { rigidbody.velocity = device.velocity; rigidbody.angularVelocity = device.angularVelocity * 0.01f; } rigidbody.maxAngularVelocity = rigidbody.angularVelocity.magnitude; } } if (isLeftHand) { } }
void CheckReferencesVive() { try { _GazeClick = new Gaze.GazeInteractionDictionaryOpenVR { LeftTrackedObject = LeftTrackedObject, RightTrackedObject = RightTrackedObject }; if (GazeParameters.GazeButtonOpenVR == EControllersInput.NONE) { CheckGazeInteractions = false; } else if (GazeParameters.GazeButtonOpenVR == EControllersInput.WHEEL_BUTTON) { CheckGazeInteractions = false; Debug.LogError("VRSF : Cannot check the Gaze Click with the Wheel Button of the mouse for the Vive."); } else if (GazeParameters.GazeButtonOpenVR == EControllersInput.A_BUTTON || GazeParameters.GazeButtonOpenVR == EControllersInput.B_BUTTON || GazeParameters.GazeButtonOpenVR == EControllersInput.X_BUTTON || GazeParameters.GazeButtonOpenVR == EControllersInput.Y_BUTTON || GazeParameters.GazeButtonOpenVR == EControllersInput.RIGHT_THUMBREST || GazeParameters.GazeButtonOpenVR == EControllersInput.LEFT_THUMBREST) { CheckGazeInteractions = false; Debug.LogError("VRSF : Cannot check the Gaze Click with the " + GazeParameters.GazeButtonOpenVR + " button for the Vive."); } else if (GazeParameters.GazeButtonOpenVR.ToString().Contains("RIGHT")) { _GazeController = RightController; } else if (GazeParameters.GazeButtonOpenVR.ToString().Contains("LEFT")) { _GazeController = LeftController; } _IsSetup = true; } catch (System.Exception e) { Debug.Log("VRSF : VR Components not setup yet, waiting for next frame.\n" + e); } }
void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedobj.index); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you are holding 'Touch' the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have activated 'touchdown' the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have activated 'touchdown' the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you are holding 'Touch' the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have activated 'touchdown' the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("you have activated 'touchdown' the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("you have activated 'pressdown' the touchpad"); sphere.transform.position = new Vector3(0, 0, 0); sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; sphere = null; } }
// Update is called once per frame void Update() { if (v != null) { transform.position = v.transform.position; } if (countTime) { time_taken += Time.deltaTime * 1000; } if (highlight_studynode) { highlight(); //restart -= Time.deltaTime; if (study_obj.studyStage < 3) { restart = 0; } if (restart <= 0 || Input.GetKeyDown(KeyCode.E)) { deleteEdges(); highlight_studynode = false; reachedNode(); } } else { exit_highlight(); restart = 10; } if (miniatureNode != null) { SteamVR_Controller.Device controller1 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Leftmost)); SteamVR_Controller.Device controller2 = SteamVR_Controller.Input(SteamVR_Controller.GetDeviceIndex(SteamVR_Controller.DeviceRelation.Rightmost)); if (controller1.GetHairTrigger() == false && controller1.GetHairTrigger() == false) { Vector3 magnitude = (transform.position - wim.C) / 15; Vector3 Sm = wim.Cm + magnitude; miniatureNode.transform.position = Sm; } } }
} // Update is called once per frame void Update() { //hacky will change #if UNITY_STANDALONE_WIN SteamVR_Controller.Device device = SteamVR_Controller.Input((int)trackedObj.index); if (curSelGameObject != null && device.GetTouch(SteamVR_Controller.ButtonMask.Grip)) { if (curSelGameObject.transform.parent == (eportmesh.transform)) { lastSelGameObject = curSelGameObject; Undoer.prevTrans.Add(new UndoManager.PrevTrans(curSelGameObject.transform.position, curSelGameObject.transform.rotation, curSelGameObject.transform.localScale, curSelGameObject)); Undoer.globalUndo.Add(1); curSelGameObject.transform.SetParent(cursor.transform); } curSelGameObject.transform.SetParent(cursor.transform); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip)) { if (curSelGameObject != null) { curSelGameObject.transform.SetParent(eportmesh.transform); } } #elif UNITY_ANDROID if (curSelGameObject != null && isGripped == true) { Debug.Log("LEtsGo"); if (curSelGameObject.transform.parent == (eportmesh.transform)) { lastSelGameObject = curSelGameObject; Undoer.prevTrans.Add(new UndoManager.PrevTrans(curSelGameObject.transform.position, curSelGameObject.transform.rotation, curSelGameObject.transform.localScale, curSelGameObject)); Undoer.globalUndo.Add(1); curSelGameObject.transform.SetParent(cursor.transform); } curSelGameObject.transform.SetParent(cursor.transform); } #endif }
// Update is called once per frame void Update() { if (!Data.movementFlag) { return; } device = SteamVR_Controller.Input((int)controller.index); if (Data.gameState != GameState.ROAM && device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { } else if (device.GetPress(SteamVR_Controller.ButtonMask.Grip) && device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { } else { if (teleport_active && device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { laser_line.active = true; } if (teleport_active && device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { laser_line.active = false; RaycastHit hit; if (Physics.Raycast(this.transform.position, this.transform.forward, out hit, max_dist)) { player.transform.position = hit.point + new Vector3(0, 0.5f, 0); } else { Vector3 pos = player.transform.position + this.transform.forward * max_dist; if (Physics.Raycast(player.transform.position, new Vector3(0, -1, 0), out hit, 1000)) { player.transform.position.Set(pos.x, hit.point.y + 0.5f, pos.z); } else if (Physics.Raycast(player.transform.position, new Vector3(0, 1, 0), out hit, 1000)) { player.transform.position.Set(pos.x, hit.point.y + 0.5f, pos.z); } } } } }
private bool OnButtonInput() { if (!vr) { return(Input.GetButtonDown(button)); } else { if (Input.GetAxis(button) > 0.9f) { if (controllerIndex == -1) { controllerIndex = (int)playerAnchor.GetComponent <SteamVR_TrackedObject>().index; } SteamVR_Controller.Device device = SteamVR_Controller.Input(controllerIndex); if (device == null) { controllerIndex = -1; return(false); } totalAngularRot += device.angularVelocity; //Debug.Log(button + ": " + totalAngularRot); if (Mathf.Abs(totalAngularRot.y) > 30f) { //Debug.Log(button + ": " + device.velocity + ", " + device.angularVelocity); //Debug.Log(button + ": " + device.velocity.sqrMagnitude + ", " + device.angularVelocity.sqrMagnitude); return(true); } else { return(false); } } else { totalAngularRot = Vector3.zero; return(false); } } }
void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'Touch' on the trigger"); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'TouchDown' on the trigger"); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'TouchUp' on the trigger"); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'Press' on the trigger"); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'PressDown' on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are activating 'PressUp' on the trigger"); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("You are activating 'PressUp' on the touchpad"); sphere.transform.position = new Vector3(0, 1.3f, 0.5f); sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } }
// Update is called once per frame void FixedUpdate() { device = SteamVR_Controller.Input((int)trackedObj.index); if (device.GetTouch(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Touch' on the Trigger."); } if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchDown on the Trigger."); } if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated TouchUp on the Trigger."); } if (device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You are holding 'Press' on the Trigger."); //device.TriggerHapticPulse(); } if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated PressDown on the Trigger."); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { Debug.Log("You activated PressUp on the Trigger."); } if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { Debug.Log("You activated PressUp on the Touchpad."); sphere.transform.position = new Vector3(0, 0, 0); sphere.GetComponent <Rigidbody>().velocity = Vector3.zero; sphere.GetComponent <Rigidbody>().angularVelocity = Vector3.zero; } }
// Update is called once per frame void Update() { if (useVR == 2) { deviceL = SteamVR_Controller.Input((int)trackedObjectL.index); deviceR = SteamVR_Controller.Input((int)trackedObjectR.index); touchpadR = deviceR.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); touchpadL = deviceL.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); if (transform.localScale.x < 6) { if ((deviceR.GetPress(SteamVR_Controller.ButtonMask.Touchpad) && touchpadR.x > 0.6f) || Input.GetKey("d")) { transform.localScale += new Vector3(Scale, Scale, Scale); } } if (transform.localScale.x > 2) { if ((deviceR.GetPress(SteamVR_Controller.ButtonMask.Touchpad) && touchpadR.x < -0.6f) || Input.GetKey("s")) { transform.localScale -= new Vector3(Scale, Scale, Scale); } } } else if (useVR == 1) { if (transform.localScale.x < 6) { if (OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick).x > 0.6f || Input.GetKey("d")) { transform.localScale += new Vector3(Scale, Scale, Scale); } } if (transform.localScale.x > 2) { if (OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick).x < -0.6f || Input.GetKey("s")) { transform.localScale -= new Vector3(Scale, Scale, Scale); } } } }
// Use this for initialization //void Start () { // device = SteamVR_Controller.Input((int)rightHand.index); // if (device == null) // Debug.Log("Device is null"); // else // Debug.Log("Device: " + device.index); //} // Update is called once per frame void Update() { string msg = null; if (Input.GetButtonDown("Fire1")) { msg = "Fire1 down"; } if (Input.GetButtonUp("Fire1")) { msg = "Fire1 up"; } #if UNITY_STANDALONE // SteamVR device = SteamVR_Controller.Input((int)rightHand.index); if (device != null && device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { msg = "Trigger press"; device.TriggerHapticPulse(700); } if (device != null && device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) { msg = "Trigger release"; } #endif #if UNITY_ANDROID if (GvrControllerInput.ClickButtonDown) { msg = "Button down"; } if (GvrControllerInput.ClickButtonUp) { msg = "Button up"; } #endif if (msg != null) { Debug.Log("Input: " + msg); } }
public void OnManipulatorLeftUpdated(SteamVR_Controller.Device state) { // left touchpad if (state.GetPress(EVRButtonId.k_EButton_SteamVR_Touchpad)) { Vector2 touchAxis = state.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); Vector3 upDisplacement = Vector3.up * (editorMovementSpeed * inverseWorldScale[HighLogic.LoadedScene] * touchAxis.y) * Time.deltaTime; Vector3 newPosition = CurrentPosition + upDisplacement; if (newPosition.y < 0f) { newPosition.y = 0f; } CurrentPosition = newPosition; } // left menu button if (state.GetPressDown(EVRButtonId.k_EButton_ApplicationMenu)) { Core.ResetInitialHmdPosition(); } // simulate mouse touch events with the trigger if (state.GetPressDown(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorLeft.FingertipCollidedGameObjects) { obj.SendMessage("OnMouseDown"); } } if (state.GetPressUp(EVRButtonId.k_EButton_SteamVR_Trigger)) { foreach (var obj in DeviceManager.Instance.ManipulatorLeft.FingertipCollidedGameObjects) { obj.SendMessage("OnMouseUp"); } } }
/* * Updates controller indecies as well as input booleans. */ void CheckInput() { //LeftController: int newLeftIndex = (int)leftControllerTrackedObject.index; if (newLeftIndex != -1 && newLeftIndex != leftControllerIndex) { //LeftController has changed, update: leftControllerIndex = newLeftIndex; leftController = SteamVR_Controller.Input(newLeftIndex); } //Check LeftController input if (newLeftIndex != -1) { leftButtonPressed = leftController.GetPress(runButtonId); } else { leftButtonPressed = false; } //RightController: int newRightIndex = (int)rightControllerTrackedObject.index; if (newRightIndex != -1 && newRightIndex != rightControllerIndex) { //RightController has changed, update: rightControllerIndex = newRightIndex; rightController = SteamVR_Controller.Input(newRightIndex); } //Check RightController input: if (newRightIndex != -1) { rightButtonPressed = rightController.GetPress(runButtonId); } else { rightButtonPressed = false; } }
void Update() { controller = GetComponent <Valve.VR.InteractionSystem.Hand> ().controller; if (controller != null) { velocity = controller.velocity; } if (controller != null) { if (controller.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { controller.TriggerHapticPulse(1800); percent = 0; } } /* if (controller != null) { * if (controller.GetPressDown (SteamVR_Controller.ButtonMask.Trigger)) { * controller.TriggerHapticPulse (1800); * maxVelocityX = 0; * maxVelocityY = 0; * maxVelocityZ = 0; * totalMax = 0; * } * } * * * * if (velocity.x > maxVelocityX) { * maxVelocityX = velocity.x; * } * if (velocity.y > maxVelocityY) { * maxVelocityY = velocity.y; * } * if (velocity.z > maxVelocityZ) { * maxVelocityZ = velocity.z; * } * if (maxVelocityX + maxVelocityY + maxVelocityZ > totalMax) { * totalMax = maxVelocityX + maxVelocityY + maxVelocityZ; * }*/ }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)controller.index); RCInput.palleteUpR = false; RCInput.palleteDownR = false; RCInput.palleteRightR = false; RCInput.palleteLeftR = false; RCInput.triggerR = device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger); if (device.GetPress(SteamVR_Controller.ButtonMask.Touchpad)) { Vector2 touchpad = (device.GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0)); //print("Pressing Touchpad"); if (touchpad.y > 0.7f) { RCInput.palleteUpR = true; // print("Moving Up"); } else if (touchpad.y < -0.7f) { RCInput.palleteDownR = true; //print("Moving Down"); } if (touchpad.x > 0.7f) { RCInput.palleteRightR = true; // print("Moving Right"); } else if (touchpad.x < -0.7f) { RCInput.palleteLeftR = true; // print("Moving left"); } } }
// Update is called once per frame void Update() { device = SteamVR_Controller.Input((int)controller.index); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Trigger)) { player.transform.position = startPos; print("Jump"); if (counter <= textarray.Length - 2) { counter += 1; } else { counter = 0; } print(textarray[counter]); } screen.GetComponent <Renderer>().material.SetTexture("_MainTex", textarray[counter]); if (device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) { player.transform.position = startPos; } if (device.GetTouch(SteamVR_Controller.ButtonMask.Touchpad)) { touchpad = device.GetAxis(EVRButtonId.k_EButton_SteamVR_Touchpad); print("touch"); print(touchpad.x + "x " + touchpad.y + " y"); if (touchpad.y > 0.1 || touchpad.y < -0.1) { player.transform.position += player.transform.forward * Time.deltaTime * touchpad.y * 5; playerPos = player.transform.position; //print(player.transform.position + " y " + touchpad.x + "x"); } if (touchpad.x > 0.1 || touchpad.x < -0.1) { player.transform.Rotate(0, touchpad.x * sensitivityX * 0.1f, 0); } // print(playerPos + "test2"); } }
//Transform _previousParent; // Use this for initialization void Start() { _trackedObject = GetComponent<SteamVR_TrackedObject>(); if (_trackedObject == null) { Debug.Log("HandTrack.cs: Couldn't find a TrackedObject component"); } if (_trackedObject) _inputDevice = SteamVR_Controller.Input((int)_trackedObject.index); // if (_attachedStick) // { // _textPrompt = _attachedStick.GetComponent<TextMesh>(); // } leftPos = _player.transform.TransformPoint(new Vector3(-1, 0, 0)); rightPos = _player.transform.TransformPoint(new Vector3(1, 0, 0)); }
IEnumerator DoStartCoroutine() { var i = -1; if ((int)trackedObj.index > i++) { device = SteamVR_Controller.Input((int)trackedObj.index); strength.Value = Mathf.Clamp01(strength.Value); float startTime = FsmTime.RealtimeSinceStartup; while (FsmTime.RealtimeSinceStartup - startTime <= duration.Value) { int valveStrength = Mathf.RoundToInt(Mathf.Lerp(0, 3999, strength.Value)); device.TriggerHapticPulse((ushort)valveStrength); yield return null; } var curTime = FsmTime.RealtimeSinceStartup - duration.Value; if (curTime > duration.Value) { Fsm.Event(sendEvent); } } }
// Use this for initialization void Start() { loseScreen.SetActive (false); maxhealth = 100; health = maxhealth; level = 1; spawnEnd = false; levelEnd = false; levelStarted = true; timer = 60; count = 0; spawnr = GameObject.FindGameObjectWithTag("Spawner"); spawnr.GetComponent<virus_spawn>().changeOdds(currOdds); currKill = 0; maxCurrK = 5; GameObject[] spawner = GameObject.FindGameObjectsWithTag("Spawner"); GameObject[] shooters = GameObject.FindGameObjectsWithTag("Shooter"); for (int i = 0; i < shooters.Length; i++) shooters[i].GetComponent<basic_shoot>().TurnOn(); left = l.GetComponent<basic_shoot>().controller; right = r.GetComponent<basic_shoot>().controller; for (int i = 0; i < spawner.Length; i++) spawner[i].GetComponent<virus_spawn>().TurnOn(); }
public override void OnUpdate() { var i = -1; if ((int)trackedObj.index > i++) { device = SteamVR_Controller.Input((int)trackedObj.index); switch (menuType) { case setMenuType.getPress: var padDown = device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDown) { Fsm.Event(sendEvent); } storeResult.Value = padDown; break; case setMenuType.getPressUp: var padDownUp = device.GetPressUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDownUp) { Fsm.Event(sendEvent); } storeResult.Value = padDownUp; break; case setMenuType.getPressDown: var padDownDown = device.GetPressDown(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padDownDown) { Fsm.Event(sendEvent); } storeResult.Value = padDownDown; break; case setMenuType.getTouch: var padTouch = device.GetTouch(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouch) { Fsm.Event(sendEvent); } storeResult.Value = padTouch; break; case setMenuType.getTouchUp: var padTouchUp = device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouchUp) { Fsm.Event(sendEvent); } storeResult.Value = padTouchUp; break; case setMenuType.getTouchDown: var padTouchDown = device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu); if (padTouchDown) { Fsm.Event(sendEvent); } storeResult.Value = padTouchDown; break; } } }
void AquireDevice() { device = SteamVR_Controller.Input((int)trackedObj.index); }
private void Start() { controllerIndex = (uint)trackedController.index; device = SteamVR_Controller.Input((int)controllerIndex); }
private void SetDeviceIndex(int index) { deviceIndex = index; controller = SteamVR_Controller.Input(index); }
private void SetDeviceIndex(int index) { DeviceIndex = index; Controller = SteamVR_Controller.Input(index); StartCoroutine(DoInitialize()); }
void Awake() { leftController = new SteamVR_Controller.Device(3); Debug.Log(leftController.index); }
private void InitController( int index ) { if ( controller == null ) { controller = SteamVR_Controller.Input( index ); gameObject.AddComponent<SteamVR_TrackedObject>().index = ( SteamVR_TrackedObject.EIndex )index; } }
// Use this for initialization void Start() { trackedObj = GetComponent<SteamVR_TrackedObject>(); device = SteamVR_Controller.Input((int)trackedObj.index); light = GetComponentInChildren<Light>(); }
private void SetDeviceIndex(int index) { Controller = SteamVR_Controller.Input(index); StartCoroutine(DoSetDeviceIndex(index)); }
// Update is called once per frame void Update() { // return if I am not a hunter player if (!isActive || !isLocalPlayer) return; // Flags for determining controller state per frame bool leftActive = true; bool leftTriggerPulled = false; bool rightTriggerPulled = false; bool leftGripPressed = false; bool rightGripPressed = false; // Setup Vive Controller try { rightController = SteamVR_Controller.Input((int)rightTrackedObject.index); rightTriggerPulled = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); rightGripPressed = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip); } catch (System.Exception) { Debug.Log ("No controllers Connected"); } bool triggersPulled = (leftTriggerPulled || rightTriggerPulled); bool gripsPressed = (leftGripPressed || rightGripPressed); // waiting for some time at the beginning of the game // such that the hiders have enough time to hide if (waiting) { int secondsElapsed = (int)Time.timeSinceLevelLoad; if (secondsElapsed < 15) { UIText.text = "Wait for " + (15 - secondsElapsed) + " second(s)"; return; } else { waiting = false; GetComponent<myViveController>().enabled = true; } } // return if game is over if (timer.GameOver()) { GetComponent<myPlayerController>().enabled = false; UIText.text = "Game Over!"; GetComponent<PointCounter> ().stopCounting (); return; } // time counter: can only shoot when a certain amount of time (FireRate) has passed timeCounter += Time.deltaTime; // Raycasting - used for shooting and opening doors if (isServer) { //Ray leftControllerRay = new Ray (leftTrackedObject.transform.position, leftTrackedObject.transform.forward); Ray rightControllerRay = new Ray (rightTrackedObject.transform.position, rightTrackedObject.transform.forward); RaycastHit objectHit; GameObject obj = null; if (Physics.Raycast(rightControllerRay, out objectHit, ShootDistance)) { obj = objectHit.transform.gameObject; // if aiming at a player if (obj.tag.Equals("Player")) { } else if (obj.tag.Equals("Door") && objectHit.distance < InteractDistance) { UIText.text = "Press the trigger button to open/close the door"; // VIVE REIMPLEMENT if (triggersPulled) { GetComponent<AudioSource>().PlayOneShot(doorSound, 2f); doorController.CmdMoveDoor(obj); } } else { UIText.text = ""; } } else { UIText.text = ""; } // VIVE REIMPLEMENT if (triggersPulled && timeCounter > FireRate) { // reset time counter timeCounter = 0.0f; // play the gun sound effect GetComponent<AudioSource>().Play(); // Haptic feedback! rightController.TriggerHapticPulse (1200); if (obj != null && obj.tag.Equals("Player")) { GameObject playerHit = obj; playerHit.GetComponent<PropController>().TakeDamage(Damage); this.gameObject.GetComponent<PointCounter> ().addKillPoints (); Debug.Log("Hit: " + playerHit); } } } else { Ray camRay = myCamera.ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2)); RaycastHit objectHit; GameObject obj = null; if (Physics.Raycast(camRay, out objectHit, ShootDistance)) { obj = objectHit.transform.gameObject; // if aiming at a player if (obj.tag.Equals("Player")) { } else if (obj.tag.Equals("Door") && objectHit.distance < InteractDistance) { UIText.text = "Press the Grip button to open/close the door"; // VIVE REIMPLEMENT if (triggersPulled) { GetComponent<AudioSource>().PlayOneShot(doorSound, 2f); doorController.CmdMoveDoor(obj); } } else { UIText.text = ""; } } else { UIText.text = ""; } // VIVE REIMPLEMENT if (triggersPulled && timeCounter > FireRate) { // reset time counter timeCounter = 0.0f; rightController.TriggerHapticPulse(700); // play the gun sound effect GetComponent<AudioSource>().Play(); if (obj != null && obj.tag.Equals("Player")) { GameObject playerHit = obj; playerHit.GetComponent<PropController>().TakeDamage(Damage); Debug.Log("Hit: " + playerHit); } } } }
// Use this for initialization void Start() { GameObject controller = this.transform.parent.gameObject; SteamVR_TrackedObject trackedObject = controller.GetComponent<SteamVR_TrackedObject>(); device = SteamVR_Controller.Input((int)trackedObject.index); this.UpdateAsObservable() .Subscribe(v => { var currentPosition = this.transform.position; speed = (currentPosition - oldPosition) / Time.deltaTime; oldPosition = currentPosition; var currenRotaion = this.transform.forward; angularVelocity = Quaternion.FromToRotation(oldRotation,currenRotaion); oldRotation = currenRotaion; }); /* this.OnCollisionEnterAsObservable() .Where(v => speed.magnitude > 0.5f) .Subscribe(v => { v.gameObject.GetComponent<Rigidbody>().AddForce(speed / 0.5f, ForceMode.Impulse); } );*/ //つかむ動作をしたとき this.OnTriggerStayAsObservable() .Where(v => v.GetComponent<GrabbableObject>() != null) .Where(v => grabbingObject == null) .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) .Select(v => v.gameObject) .Where(v => v.GetComponent<IGrabbable>().Grabbed == false) .Subscribe(v => GrabAction(v)); //手を放したとき this.UpdateAsObservable() .Where(_ => device.GetPressUp(SteamVR_Controller.ButtonMask.Trigger)) .Where(_ => grabbingObject != null) .Where(_ => grabbingObject.GetComponent<IGrabbable>() != null) .Subscribe(_ => UnGrabAction(grabbingObject,true)); //道具をつかんだとき this.OnTriggerStayAsObservable() .Where(v => v.GetComponent<IGrippable>() != null) .Where(v => grabbingObject == null) .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) .Select(v => v.gameObject) .Where(v => v.GetComponent<IGrippable>().Grabbed == false) .Subscribe(v => GripAction(v)); //道具を放したとき this.UpdateAsObservable() .Where(_ => device.GetPressDown(SteamVR_Controller.ButtonMask.Grip)) .Where(_ => grabbingObject != null) .Where(_ => grabbingObject.GetComponent<IGrippable>() != null) .Select(_ => grabbingObject) .Subscribe(v => UnGripAction(v,true)); //道具を切り替えたとき this.OnTriggerStayAsObservable() .Where(v => v.GetComponent<IGrippable>() != null) .Where(v => grabbingObject == null) .Where(v => device.GetPress(SteamVR_Controller.ButtonMask.Trigger)) .Select(v => v.gameObject) .Where(v => v.GetComponent<IGrippable>().Grabbed == true) .Subscribe(v => SwichGripAction(v,v.transform.parent.gameObject)); //道具のトリガーを引いたとき this.UpdateAsObservable() .Where(_ => grabbingObject != null) .Where(_ => grabbingObject.GetComponent<IShootable>() != null) .Where(_ => Mathf.Abs(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x) > 0.0f) .Select(_ => grabbingObject) .Subscribe(v => { grabbingObject.GetComponent<IShootable>().Shot(device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x); } ); }
// Use this for initialization void Awake() { left = l.GetComponent<basic_shoot> ().controller; right = r.GetComponent<basic_shoot> ().controller; plate = GameObject.Find ("tut"); }
private void InitController( int index ) { if ( controller == null ) { controller = SteamVR_Controller.Input( index ); gameObject.AddComponent<SteamVR_TrackedObject>().index = (SteamVR_TrackedObject.EIndex)index; // // Update and show SteamVR_RenderModel // if ( createRenderModel ) { renderModel = new GameObject( "SteamVR_RenderModel" ).AddComponent<SteamVR_RenderModel>(); renderModel.transform.parent = transform; renderModel.transform.localPosition = Vector3.zero; renderModel.transform.localRotation = Quaternion.identity; renderModel.transform.localScale = Vector3.one; } else { renderModel = GetComponentInChildren<SteamVR_RenderModel>(); } if ( renderModel != null ) { renderModel.modelOverride = null; renderModel.index = (SteamVR_TrackedObject.EIndex)index; renderModel.enabled = true; renderModel.UpdateModel(); } this.BroadcastMessage( "OnHandInitialized", index, SendMessageOptions.DontRequireReceiver ); // let child objects know we've initialized } }
private void Start() { //originalRotation = transform.localRotation; //UpdateUI(); device = SteamVR_Controller.Input ((int)trackedObj.index); IsMagic1 = false; IsMagic2 = false; MagicTimer1 = 0; MagicTimer2 = 0; boss = GameObject.FindGameObjectWithTag ("boss"); bossMove = boss.GetComponent<BossMove> (); }
private void Update() { controllerIndex = (uint)trackedController.index; device = SteamVR_Controller.Input((int)controllerIndex); Vector2 currentTriggerAxis = device.GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger); Vector2 currentTouchpadAxis = device.GetAxis(); //Trigger if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerPressed(SetButtonEvent(ref triggerPressed, true, currentTriggerAxis.x)); EmitAlias(ButtonAlias.Trigger, true, currentTriggerAxis.x, ref triggerPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Trigger)) { OnTriggerReleased(SetButtonEvent(ref triggerPressed, false, 0f)); EmitAlias(ButtonAlias.Trigger, false, 0f, ref triggerPressed); } else { if (Vector2ShallowEquals(triggerAxis, currentTriggerAxis)) { triggerAxisChanged = false; } else { OnTriggerAxisChanged(SetButtonEvent(ref triggerAxisChanged, true, currentTriggerAxis.x)); } } //ApplicationMenu if (device.GetTouchDown(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuPressed(SetButtonEvent(ref applicationMenuPressed, true, 1f)); EmitAlias(ButtonAlias.Application_Menu, true, 1f, ref applicationMenuPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.ApplicationMenu)) { OnApplicationMenuReleased(SetButtonEvent(ref applicationMenuPressed, false, 0f)); EmitAlias(ButtonAlias.Application_Menu, false, 0f, ref applicationMenuPressed); } //Grip if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Grip)) { OnGripPressed(SetButtonEvent(ref gripPressed, true, 1f)); EmitAlias(ButtonAlias.Grip, true, 1f, ref gripPressed); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Grip)) { OnGripReleased(SetButtonEvent(ref gripPressed, false, 0f)); EmitAlias(ButtonAlias.Grip, false, 0f, ref gripPressed); } //Touchpad Pressed if (device.GetPressDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadPressed(SetButtonEvent(ref touchpadPressed, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Press, true, 1f, ref touchpadPressed); } else if (device.GetPressUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadReleased(SetButtonEvent(ref touchpadPressed, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Press, false, 0f, ref touchpadPressed); } //Touchpad Touched if (device.GetTouchDown(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchStart(SetButtonEvent(ref touchpadTouched, true, 1f)); EmitAlias(ButtonAlias.Touchpad_Touch, true, 1f, ref touchpadTouched); } else if (device.GetTouchUp(SteamVR_Controller.ButtonMask.Touchpad)) { OnTouchpadTouchEnd(SetButtonEvent(ref touchpadTouched, false, 0f)); EmitAlias(ButtonAlias.Touchpad_Touch, false, 0f, ref touchpadTouched); } else { if (Vector2ShallowEquals(touchpadAxis, currentTouchpadAxis)) { touchpadAxisChanged = false; } else { OnTouchpadAxisChanged(SetButtonEvent(ref touchpadTouched, true, 1f)); touchpadAxisChanged = true; } } // Save current touch and trigger settings to detect next change. touchpadAxis = new Vector2(currentTouchpadAxis.x, currentTouchpadAxis.y); triggerAxis = new Vector2(currentTriggerAxis.x, currentTriggerAxis.y); }
void Update() { if (!isServer || !isLocalPlayer) return; float xLeftInput = 0; float zLeftInput = 0; float xRightInput = 0; float zRightInput = 0; bool leftActive = true; // Setting up the Vive controllers bool leftGripPressed = false; try { leftController = SteamVR_Controller.Input((int)leftTrackedObject.index); leftGripPressed = leftController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip); if (leftController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) { // Get the left inputs xLeftInput = leftController.GetAxis().x; zLeftInput = leftController.GetAxis ().y; } } catch (System.Exception) { //Just roll with it leftActive = false; } bool rightGripPressed = false; try { rightController = SteamVR_Controller.Input((int)rightTrackedObject.index); rightGripPressed = rightController.GetPressDown(Valve.VR.EVRButtonId.k_EButton_Grip); if (rightController.GetPress(Valve.VR.EVRButtonId.k_EButton_SteamVR_Touchpad)) { // Get the left inputs xRightInput = rightController.GetAxis().x; zRightInput = rightController.GetAxis ().y; } } catch (System.Exception) { if (!leftActive) { Debug.Log ("No controllers Connected"); } } //Calculate movement velocity as a 3D vector // Strafe float _xMov = xLeftInput + xRightInput; // Forward float _zMov = zLeftInput + zRightInput; Vector3 _movHorizontal; Vector3 _movVertical; // Move relative to the first person camera if (isServer) { _movHorizontal = firstPersonCam.transform.right * _xMov; _movVertical = firstPersonCam.transform.forward * _zMov; } finalSpeed = speed; // Final movement vector Vector3 _velocity = (_movHorizontal + _movVertical).normalized * finalSpeed; bool gripsPressed = (leftGripPressed || rightGripPressed); //if the player is jumping if (gripsPressed && !isFalling) { isFalling = true; playerAudio.PlayOneShot(jumpSound, 0.6f); motor.Jump(); } // Apply movement motor.Move(_velocity); // Calculate rotation as a 3D vector (turning around) float _yRot = Input.GetAxisRaw("Mouse X"); Vector3 _rotation = new Vector3(0f, _yRot, 0f) * lookSensitivity; // Apply rotation motor.Rotate(_rotation); // Calculate camera rotation as a 3D vector (turning around) float _xRot = Input.GetAxisRaw("Mouse Y"); // REVERT: Change yRot to 0f Vector3 _cameraRotation = new Vector3(_xRot, _yRot, 0f) * lookSensitivity; // Apply rotation motor.RotateCamera(_cameraRotation); }