// Update is called once per frame void Update() { SteamVR_Controller.Device[] controllerDevices = experimentManager.GetControllers(); bool controller1_TouchPadDown = controllerDevices[0].GetPressDown(SteamVR_Controller.ButtonMask.Touchpad); if (controller1_TouchPadDown) { RotatePersonHelper(controllerDevices[0]); } bool controller2_TouchPadDown = controllerDevices[1].GetPressDown(SteamVR_Controller.ButtonMask.Touchpad); if (controller2_TouchPadDown) { RotatePersonHelper(controllerDevices[1]); } }
// Use this for initialization void Start() { choiceSelected = false; lastTrackPadValues = new Vector2[2]; lastTouchTrackPad = new bool[2]; try { experimentManager = GameObject.Find(experimentManagerName).GetComponent <ExperimentManager>(); userInputUi = userInputUiGameObject.GetComponent <TextMesh>(); controllers = experimentManager.GetControllers(); experimentManager.ToggleAutoSceneChange(false); // Set survey one meter in front of user transform.position = new Vector3(0.0f, experimentManager.getUserHeadTransform().position.y, 1.0f); } catch { Debug.LogError("Unable to link to experiment manager..."); Application.Quit(); } }
// Update is called once per frame void Update() { Transform [] controllerTransforms = experimentManager.GetControllerTransforms(); SteamVR_Controller.Device [] controllerDevices = experimentManager.GetControllers(); rayCastLineUi.enabled = false; // Determine which hand is being used for laser if (laserActive == false) { for (int i = 0; i < 2; i++) { if (controllerDevices[i].GetPress(EVRButtonId.k_EButton_Grip)) { laserActive = true; activeLaserIndex = i; break; } } } // Determine if laser is still active bool currentLaserStatus = controllerDevices[activeLaserIndex].GetPress(EVRButtonId.k_EButton_Grip); if ((currentLaserStatus == false) && (laserActive == true) && (lastHit.point != Vector3.zero) && canMoveThere) { experimentManager.TeleportUser(lastHit.point); } laserActive = currentLaserStatus; rayCastLineUi.enabled = laserActive; // Draw out line if laser is active if (laserActive == true) { rayCastLineUi.enabled = true; rayCastLineUi.SetPosition(0, controllerTransforms[activeLaserIndex].position + controllerTransforms[activeLaserIndex].forward.normalized * 0.025f); rayCastLineUi.startColor = Color.red; rayCastLineUi.endColor = Color.red + Color.white * 0.75f; RaycastHit hit; Physics.Raycast(controllerTransforms[activeLaserIndex].position, controllerTransforms[activeLaserIndex].TransformDirection(Vector3.forward), out hit, Mathf.Infinity); lastHit = hit; // Great user is pointing at something, see if we can move there canMoveThere = false; if (hit.point != Vector3.zero) { rayCastLineUi.SetPosition(1, hit.point); if (hit.collider.name.Length >= moveableEnding.Length) { if (hit.collider.name.Substring(hit.collider.name.Length - moveableEnding.Length, moveableEnding.Length) == moveableEnding) { canMoveThere = true; rayCastLineUi.startColor = Color.green; rayCastLineUi.endColor = Color.green + Color.white * 0.75f; } } } // User is not pointing at anything, we can't move there.... else { rayCastLineUi.SetPosition(1, controllerTransforms[activeLaserIndex].position + controllerTransforms[activeLaserIndex].forward.normalized * 3.0f); } } }