// Update is called once per frame void Update() { OVRInput.Update(); if (!quitMenuUp) { if (titleUp) { if (OVRInput.Get(OVRInput.Button.DpadRight) || Input.GetKeyUp(KeyCode.RightArrow)) { colorIndex = (colorIndex + 1) == colors.Length ? 0 : colorIndex + 1; UpdateTitleColor(); actionFeedback = true; } else if (OVRInput.Get(OVRInput.Button.DpadLeft) || Input.GetKeyUp(KeyCode.LeftArrow)) { colorIndex = (colorIndex - 1) == -1 ? colors.Length - 1 : colorIndex - 1; UpdateTitleColor(); actionFeedback = true; } else if (OVRInput.Get(OVRInput.Button.DpadDown) || Input.GetKeyUp(KeyCode.DownArrow)) { lineCount = (lineCount - 1) <= 0 ? 1 : lineCount - 1; UpdateTitleCount(title, lineCount); actionFeedback = true; } else if (OVRInput.Get(OVRInput.Button.DpadUp) || Input.GetKeyUp(KeyCode.UpArrow)) { lineCount = (lineCount + 1) >= 6 ? 5 : lineCount + 1; UpdateTitleCount(title, lineCount); actionFeedback = true; } else if (OVRInput.GetUp(OVRInput.Button.PrimaryTouchpad) || Input.GetKeyUp(KeyCode.R)) { if (readyToGo) { AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(1); } } else if (OVRInput.Get(OVRInput.Touch.PrimaryTouchpad)) { touchPosition = OVRInput.Get(OVRInput.Axis2D.PrimaryTouchpad); } else if (OVRInput.GetUp(OVRInput.Touch.PrimaryTouchpad) || Input.GetKeyUp(KeyCode.S)) { outlineScale = .03f + (touchPosition.y + 1f) * .05f; outlineWiggle = (touchPosition.x + 1f) * 20f; } } else if (OVRInput.GetUp(OVRInput.Button.PrimaryTouchpad) || Input.GetKeyUp(KeyCode.R)) { if (Time.time < delayTime) { delayTime = Time.time > 3f ? Time.time : 3f; StopCoroutine(nextAction); nextAction = StartCoroutine(ScriptNext(delayTime)); } ChangeWarningToTitle(); } if (OVRInput.Get(OVRInput.Button.PrimaryIndexTrigger)) { titleText.transform.rotation = (OVRInput.GetLocalControllerRotation(OVRInput.GetActiveController())); } if (OVRInput.GetUp(OVRInput.Button.Back) || Input.GetKeyUp(KeyCode.Backspace)) { //Application.Quit(); instructionText.gameObject.SetActive(false); textContainer.SetActive(false); quitMenu.SetActive(true); quitMenuUp = true; } if (actionFeedback) { StartCoroutine(ActionFeedback()); actionFeedback = false; } if (titleUp) { titleText.outlineWidth = outlineScale * 2f + (Mathf.Sin(Time.time * outlineWiggle) + 1f) * outlineScale; } } }
// Update is called once per frame void Update() { OVRInput.Update(); left_rot = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch); left_pos = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch); if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > LabelToolManager.threshold) { left_rot = Quaternion.Euler(new Vector3(0.0f, left_rot.eulerAngles[1], 0.0f)); transform.rotation = Quaternion.Euler(new Vector3(0.0f, transform.rotation.eulerAngles[1], 0.0f)); } if (LabelToolManager.X_pressed) { transform.localScale = new Vector3(1.0f, 1.0f, 1.0f) * LabelToolManager.scaleFactors[LabelToolManager.current_scale_idx]; } if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > LabelToolManager.threshold && !hand_trigger_pushed) { left_pos_init = left_pos; //Debug.Log("Grabbed pcd"); tf_rel = Matrix4x4.Inverse( Matrix4x4.TRS(left_pos, left_rot, ones)) * Matrix4x4.TRS(transform.position, transform.rotation, ones); hand_trigger_pushed = true; } else if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) > LabelToolManager.threshold && hand_trigger_pushed) { if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) > LabelToolManager.threshold && !index_trigger_pushed) { tf_rel = Matrix4x4.Inverse( Matrix4x4.TRS(left_pos, left_rot, ones)) * Matrix4x4.TRS(transform.position, Quaternion.Euler(new Vector3(0.0f, transform.rotation.eulerAngles[1], 0.0f)), ones); index_trigger_pushed = true; } else if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger) < LabelToolManager.threshold && index_trigger_pushed) { tf_rel = Matrix4x4.Inverse( Matrix4x4.TRS(left_pos, left_rot, ones)) * Matrix4x4.TRS(transform.position, Quaternion.Euler(new Vector3(0.0f, transform.rotation.eulerAngles[1], 0.0f)), ones); index_trigger_pushed = false; } tf_pcd = Matrix4x4.TRS(left_pos, left_rot, new Vector3(1.0f, 1.0f, 1.0f)) * Matrix4x4.Translate((speed_mltplr) * (left_pos - left_pos_init)) * tf_rel; transform.rotation = QuaternionFromMatrix(tf_pcd); transform.position = PositionFromMatrix(tf_pcd); } else if (OVRInput.Get(OVRInput.Axis1D.PrimaryHandTrigger) == 0.0f && hand_trigger_pushed) { //Debug.Log("Released pcd"); hand_trigger_pushed = false; } }
private void Update() { Vector3 moveAxis = Vector3.zero; //Translation. Used by keyboard only. float inputRotation = 0f; //Applied rotation, between -1 and 1. Cumulative between keyboard and controllers. float inputScale = 0f; //Applied scale change, either -1, 0 or 1. Cumulative between keyboard and controllers. //Keyboard inputs. if (Input.GetKey(KeyCode.LeftArrow) || Input.GetKey(KeyCode.Q)) { inputRotation = -1 * (rotationSpeed * 360) * Time.deltaTime; } if (Input.GetKey(KeyCode.RightArrow) || Input.GetKey(KeyCode.E)) { inputRotation = 1 * (rotationSpeed * 360) * Time.deltaTime; } if (Input.GetKey(KeyCode.UpArrow) || Input.GetKey(KeyCode.W)) { moveAxis = Vector3.forward * movementSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.DownArrow) || Input.GetKey(KeyCode.S)) { moveAxis = Vector3.back * movementSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.A)) { moveAxis = Vector3.left * movementSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.D)) { moveAxis = Vector3.right * movementSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.R)) { moveAxis = Vector3.up * movementSpeed * Time.deltaTime; } if (Input.GetKey(KeyCode.F)) { moveAxis = Vector3.down * movementSpeed * Time.deltaTime; } Quaternion gravity = Quaternion.identity; if (moveAxis != Vector3.zero) { isMoving = true; if (motion == RelativeMotion.Itself) { transform.Translate(moveAxis.x, moveAxis.y, moveAxis.z); } else if (motion == RelativeMotion.Camera) { gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up); transform.localPosition += zedManager.GetLeftCameraTransform().right *moveAxis.x; transform.localPosition += zedManager.GetLeftCameraTransform().forward *moveAxis.z; transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveAxis.y; } } else { isMoving = false; } if (Input.GetKey(KeyCode.Mouse0)) { inputScale = 1f; } else if (Input.GetKey(KeyCode.Mouse1)) { inputScale = -1f; } if (zedManager) { #if ZED_OCULUS if (UnityEngine.VR.VRSettings.loadedDeviceName == "Oculus") { if (OVRInput.GetConnectedControllers().ToString() == "Touch") { Vector3 moveaxisoculus = new Vector3(); //Position change by controller. Added to keyboard version if both are applied. if (objectTrackers.Count > 0) { moveaxisoculus = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.RTouch); inputRotation += moveaxisoculus.x * rotationSpeed * 360 * Time.deltaTime; gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up); transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveaxisoculus.y *movementSpeed *Time.deltaTime; if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.RTouch) > 0.75f) { inputScale = 1f; } } if (objectTrackers.Count > 1) { moveaxisoculus = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick, OVRInput.Controller.LTouch); if (moveaxisoculus.x != 0 || moveaxisoculus.y != 0) { isMoving = true; gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up); transform.localPosition += zedManager.GetLeftCameraTransform().right *moveaxisoculus.x *movementSpeed *Time.deltaTime; transform.localPosition += gravity * zedManager.GetLeftCameraTransform().forward *moveaxisoculus.y *movementSpeed *Time.deltaTime; } else { isMoving = false; } if (OVRInput.Get(OVRInput.Axis1D.PrimaryIndexTrigger, OVRInput.Controller.LTouch) > 0.75f) { inputScale = -1f; } } } OVRInput.Update(); } #endif #if ZED_STEAM_VR if (UnityEngine.VR.VRSettings.loadedDeviceName == "OpenVR") { Vector3 moveaxissteamvr = new Vector3(); //Position change by controller. Added to keyboard version if both are applied. //Looks for any input from this controller through SteamVR. if (objectTrackers.Count > 0 && objectTrackers[0].index >= 0) { //moveaxissteamvr = SteamVR_Controller.Input((int)objectTrackers[0].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); moveaxissteamvr = objectTrackers[0].GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); inputRotation += moveaxissteamvr.x * rotationSpeed * 360f * Time.deltaTime; gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up); transform.localPosition += gravity * zedManager.GetLeftCameraTransform().up *moveaxissteamvr.y *movementSpeed *Time.deltaTime; //if (objectTrackers[0].index > 0 && SteamVR_Controller.Input((int)objectTrackers[0].index).GetHairTrigger()) if (objectTrackers[0].index > 0 && objectTrackers[0].GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x > 0.1f) { inputScale = 1f; } } if (objectTrackers.Count > 1 && objectTrackers[1].index >= 0) { //moveaxissteamvr = SteamVR_Controller.Input((int)objectTrackers[1].index).GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); moveaxissteamvr = objectTrackers[1].GetAxis(Valve.VR.EVRButtonId.k_EButton_Axis0); if (moveaxissteamvr.x != 0 || moveaxissteamvr.y != 0) { isMoving = true; gravity = Quaternion.FromToRotation(zedManager.GetZedRootTansform().up, Vector3.up); transform.localPosition += zedManager.GetLeftCameraTransform().right *moveaxissteamvr.x *movementSpeed *Time.deltaTime; transform.localPosition += gravity * zedManager.GetLeftCameraTransform().forward *moveaxissteamvr.y *movementSpeed *Time.deltaTime; } else { isMoving = false; } //if (objectTrackers[1].index > 0 && SteamVR_Controller.Input((int)objectTrackers[1].index).GetHairTrigger()) if (objectTrackers[1].index > 0 && objectTrackers[1].GetAxis(Valve.VR.EVRButtonId.k_EButton_SteamVR_Trigger).x > 0.1f) { inputScale = -1f; } } } #endif } //Rotation float h = inputRotation; if (invertRotation) { transform.Rotate(0, h, 0); } else { transform.Rotate(0, -h, 0); } //Scale float s = scaleSpeed * (inputScale * Time.deltaTime); transform.localScale = new Vector3(transform.localScale.x + s, transform.localScale.y + s, transform.localScale.z + s); if (transform.localScale.x > maxScale) { transform.localScale = new Vector3(maxScale, maxScale, maxScale); } else if (transform.localScale.x < minScale) { transform.localScale = new Vector3(minScale, minScale, minScale); } //Enable/disable light if moving. if (spotLight != null) { SetMovementLight(); } }
void Update() { OVRInput.Update(); }
private void Update() { #if !UNITY_EDITOR paused = !OVRPlugin.hasVrFocus; #endif if (OVRPlugin.shouldQuit) { Application.Quit(); } if (OVRPlugin.shouldRecenter) { OVRManager.display.RecenterPose(); } if (trackingOriginType != _trackingOriginType) { trackingOriginType = _trackingOriginType; } tracker.isEnabled = usePositionTracking; // Dispatch HMD events. isHmdPresent = OVRPlugin.hmdPresent; if (isHmdPresent) { OVRPlugin.queueAheadFraction = (queueAhead) ? 0.25f : 0f; } if (_wasHmdPresent && !isHmdPresent) { try { if (HMDLost != null) { HMDLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasHmdPresent && isHmdPresent) { try { if (HMDAcquired != null) { HMDAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHmdPresent = isHmdPresent; // Dispatch VR Focus events. hasVrFocus = OVRPlugin.hasVrFocus; if (_hadVrFocus && !hasVrFocus) { try { if (VrFocusLost != null) { VrFocusLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_hadVrFocus && hasVrFocus) { try { if (VrFocusAcquired != null) { VrFocusAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _hadVrFocus = hasVrFocus; // Dispatch Audio Device events. string audioOutId = OVRPlugin.audioOutId; if (!prevAudioOutIdIsCached) { prevAudioOutId = audioOutId; prevAudioOutIdIsCached = true; } else if (audioOutId != prevAudioOutId) { try { if (AudioOutChanged != null) { AudioOutChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioOutId = audioOutId; } string audioInId = OVRPlugin.audioInId; if (!prevAudioInIdIsCached) { prevAudioInId = audioInId; prevAudioInIdIsCached = true; } else if (audioInId != prevAudioInId) { try { if (AudioInChanged != null) { AudioInChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioInId = audioInId; } // Dispatch tracking events. if (wasPositionTracked && !tracker.isPositionTracked) { try { if (TrackingLost != null) { TrackingLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!wasPositionTracked && tracker.isPositionTracked) { try { if (TrackingAcquired != null) { TrackingAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } wasPositionTracked = tracker.isPositionTracked; // Dispatch HSW events. isHSWDisplayed = OVRPlugin.hswVisible; if (isHSWDisplayed && Input.anyKeyDown) { DismissHSWDisplay(); } if (!isHSWDisplayed && _wasHSWDisplayed) { try { if (HSWDismissed != null) { HSWDismissed(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHSWDisplayed = isHSWDisplayed; display.Update(); OVRInput.Update(); if (volumeController != null) { if (volumeControllerTransform == null) { if (gameObject.GetComponent <OVRCameraRig>() != null) { volumeControllerTransform = gameObject.GetComponent <OVRCameraRig>().centerEyeAnchor; } } volumeController.UpdatePosition(volumeControllerTransform); } }
void Update() { OVRInput.Update(); //Must be run each frame }
private void Update() { #if UNITY_EDITOR if (_scriptsReloaded) { _scriptsReloaded = false; instance = this; Initialize(); } #endif if (OVRPlugin.shouldQuit) { Application.Quit(); } if (AllowRecenter && OVRPlugin.shouldRecenter) { OVRManager.display.RecenterPose(); } if (trackingOriginType != _trackingOriginType) { trackingOriginType = _trackingOriginType; } tracker.isEnabled = usePositionTracking; OVRPlugin.rotation = useRotationTracking; OVRPlugin.useIPDInPositionTracking = useIPDInPositionTracking; // Dispatch HMD events. isHmdPresent = OVRPlugin.hmdPresent; if (useRecommendedMSAALevel && QualitySettings.antiAliasing != display.recommendedMSAALevel) { Debug.Log("The current MSAA level is " + QualitySettings.antiAliasing + ", but the recommended MSAA level is " + display.recommendedMSAALevel + ". Switching to the recommended level."); QualitySettings.antiAliasing = display.recommendedMSAALevel; } if (_wasHmdPresent && !isHmdPresent) { try { if (HMDLost != null) { HMDLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasHmdPresent && isHmdPresent) { try { if (HMDAcquired != null) { HMDAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHmdPresent = isHmdPresent; // Dispatch HMD mounted events. isUserPresent = OVRPlugin.userPresent; if (_wasUserPresent && !isUserPresent) { try { if (HMDUnmounted != null) { HMDUnmounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasUserPresent && isUserPresent) { try { if (HMDMounted != null) { HMDMounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasUserPresent = isUserPresent; // Dispatch VR Focus events. hasVrFocus = OVRPlugin.hasVrFocus; if (_hadVrFocus && !hasVrFocus) { try { if (VrFocusLost != null) { VrFocusLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_hadVrFocus && hasVrFocus) { try { if (VrFocusAcquired != null) { VrFocusAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _hadVrFocus = hasVrFocus; // Dispatch VR Input events. bool hasInputFocus = OVRPlugin.hasInputFocus; if (_hadInputFocus && !hasInputFocus) { try { if (InputFocusLost != null) { InputFocusLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_hadInputFocus && hasInputFocus) { try { if (InputFocusAcquired != null) { InputFocusAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _hadInputFocus = hasInputFocus; // Changing effective rendering resolution dynamically according performance #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) if (enableAdaptiveResolution) { #if UNITY_2017_2_OR_NEWER if (UnityEngine.XR.XRSettings.eyeTextureResolutionScale < maxRenderScale) { // Allocate renderScale to max to avoid re-allocation UnityEngine.XR.XRSettings.eyeTextureResolutionScale = maxRenderScale; } else { // Adjusting maxRenderScale in case app started with a larger renderScale value maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.XR.XRSettings.eyeTextureResolutionScale); } minRenderScale = Mathf.Min(minRenderScale, maxRenderScale); float minViewportScale = minRenderScale / UnityEngine.XR.XRSettings.eyeTextureResolutionScale; float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / UnityEngine.XR.XRSettings.eyeTextureResolutionScale; recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f); UnityEngine.XR.XRSettings.renderViewportScale = recommendedViewportScale; #else if (UnityEngine.VR.VRSettings.renderScale < maxRenderScale) { // Allocate renderScale to max to avoid re-allocation UnityEngine.VR.VRSettings.renderScale = maxRenderScale; } else { // Adjusting maxRenderScale in case app started with a larger renderScale value maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.VR.VRSettings.renderScale); } minRenderScale = Mathf.Min(minRenderScale, maxRenderScale); float minViewportScale = minRenderScale / UnityEngine.VR.VRSettings.renderScale; float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / UnityEngine.VR.VRSettings.renderScale; recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f); UnityEngine.VR.VRSettings.renderViewportScale = recommendedViewportScale; #endif } #endif // Dispatch Audio Device events. string audioOutId = OVRPlugin.audioOutId; if (!prevAudioOutIdIsCached) { prevAudioOutId = audioOutId; prevAudioOutIdIsCached = true; } else if (audioOutId != prevAudioOutId) { try { if (AudioOutChanged != null) { AudioOutChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioOutId = audioOutId; } string audioInId = OVRPlugin.audioInId; if (!prevAudioInIdIsCached) { prevAudioInId = audioInId; prevAudioInIdIsCached = true; } else if (audioInId != prevAudioInId) { try { if (AudioInChanged != null) { AudioInChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioInId = audioInId; } // Dispatch tracking events. if (wasPositionTracked && !tracker.isPositionTracked) { try { if (TrackingLost != null) { TrackingLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!wasPositionTracked && tracker.isPositionTracked) { try { if (TrackingAcquired != null) { TrackingAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } wasPositionTracked = tracker.isPositionTracked; display.Update(); OVRInput.Update(); #if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN if (enableMixedReality || prevEnableMixedReality) { Camera mainCamera = FindMainCamera(); if (Camera.main != null) { suppressDisableMixedRealityBecauseOfNoMainCameraWarning = false; if (enableMixedReality) { OVRMixedReality.Update(this.gameObject, mainCamera, compositionMethod, useDynamicLighting, capturingCameraDevice, depthQuality); } if (prevEnableMixedReality && !enableMixedReality) { OVRMixedReality.Cleanup(); } prevEnableMixedReality = enableMixedReality; } else { if (!suppressDisableMixedRealityBecauseOfNoMainCameraWarning) { Debug.LogWarning("Main Camera is not set, Mixed Reality disabled"); suppressDisableMixedRealityBecauseOfNoMainCameraWarning = true; } } } #endif }
private void Update() { #if UNITY_EDITOR if (_scriptsReloaded) { _scriptsReloaded = false; instance = this; Initialize(); } #endif if (OVRPlugin.shouldQuit) { Application.Quit(); } if (OVRPlugin.shouldRecenter) { OVRManager.display.RecenterPose(); } if (trackingOriginType != _trackingOriginType) { trackingOriginType = _trackingOriginType; } tracker.isEnabled = usePositionTracking; OVRPlugin.useIPDInPositionTracking = useIPDInPositionTracking; // Dispatch HMD events. isHmdPresent = OVRPlugin.hmdPresent; if (useRecommendedMSAALevel && QualitySettings.antiAliasing != display.recommendedMSAALevel) { Debug.Log("The current MSAA level is " + QualitySettings.antiAliasing + ", but the recommended MSAA level is " + display.recommendedMSAALevel + ". Switching to the recommended level."); QualitySettings.antiAliasing = display.recommendedMSAALevel; } if (_wasHmdPresent && !isHmdPresent) { try { if (HMDLost != null) { HMDLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasHmdPresent && isHmdPresent) { try { if (HMDAcquired != null) { HMDAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHmdPresent = isHmdPresent; // Dispatch HMD mounted events. isUserPresent = OVRPlugin.userPresent; if (_wasUserPresent && !isUserPresent) { try { if (HMDUnmounted != null) { HMDUnmounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasUserPresent && isUserPresent) { try { if (HMDMounted != null) { HMDMounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasUserPresent = isUserPresent; // Dispatch VR Focus events. hasVrFocus = OVRPlugin.hasVrFocus; if (_hadVrFocus && !hasVrFocus) { try { if (VrFocusLost != null) { VrFocusLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_hadVrFocus && hasVrFocus) { try { if (VrFocusAcquired != null) { VrFocusAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _hadVrFocus = hasVrFocus; // Changing effective rendering resolution dynamically according performance #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) && UNITY_5_4_OR_NEWER if (enableAdaptiveResolution) { if (UnityEngine.XR.XRSettings.eyeTextureResolutionScale < maxRenderScale) { // Allocate renderScale to max to avoid re-allocation UnityEngine.XR.XRSettings.eyeTextureResolutionScale = maxRenderScale; } else { // Adjusting maxRenderScale in case app started with a larger renderScale value maxRenderScale = Mathf.Max(maxRenderScale, UnityEngine.XR.XRSettings.eyeTextureResolutionScale); } float minViewportScale = minRenderScale / UnityEngine.XR.XRSettings.eyeTextureResolutionScale; float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / UnityEngine.XR.XRSettings.eyeTextureResolutionScale; recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f); UnityEngine.XR.XRSettings.renderViewportScale = recommendedViewportScale; } #endif // Dispatch Audio Device events. string audioOutId = OVRPlugin.audioOutId; if (!prevAudioOutIdIsCached) { prevAudioOutId = audioOutId; prevAudioOutIdIsCached = true; } else if (audioOutId != prevAudioOutId) { try { if (AudioOutChanged != null) { AudioOutChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioOutId = audioOutId; } string audioInId = OVRPlugin.audioInId; if (!prevAudioInIdIsCached) { prevAudioInId = audioInId; prevAudioInIdIsCached = true; } else if (audioInId != prevAudioInId) { try { if (AudioInChanged != null) { AudioInChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioInId = audioInId; } // Dispatch tracking events. if (wasPositionTracked && !tracker.isPositionTracked) { try { if (TrackingLost != null) { TrackingLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!wasPositionTracked && tracker.isPositionTracked) { try { if (TrackingAcquired != null) { TrackingAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } wasPositionTracked = tracker.isPositionTracked; display.Update(); OVRInput.Update(); }
private void Update() { #if !UNITY_EDITOR paused = !OVRPlugin.hasVrFocus; #endif if (OVRPlugin.shouldQuit) { Application.Quit(); } if (OVRPlugin.shouldRecenter) { OVRManager.display.RecenterPose(); } if (trackingOriginType != _trackingOriginType) { trackingOriginType = _trackingOriginType; } tracker.isEnabled = usePositionTracking; OVRPlugin.useIPDInPositionTracking = useIPDInPositionTracking; // Dispatch HMD events. isHmdPresent = OVRPlugin.hmdPresent; if (isHmdPresent) { OVRPlugin.queueAheadFraction = (queueAhead) ? 0.25f : 0f; } if (useRecommendedMSAALevel && QualitySettings.antiAliasing != display.recommendedMSAALevel) { QualitySettings.antiAliasing = display.recommendedMSAALevel; // Debug.Log ("MSAA level: " + QualitySettings.antiAliasing); } if (_wasHmdPresent && !isHmdPresent) { try { if (HMDLost != null) { HMDLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasHmdPresent && isHmdPresent) { try { if (HMDAcquired != null) { HMDAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHmdPresent = isHmdPresent; // Dispatch HMD mounted events. isUserPresent = OVRPlugin.userPresent; if (_wasUserPresent && !isUserPresent) { try { if (HMDUnmounted != null) { HMDUnmounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_wasUserPresent && isUserPresent) { try { if (HMDMounted != null) { HMDMounted(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasUserPresent = isUserPresent; // Dispatch VR Focus events. hasVrFocus = OVRPlugin.hasVrFocus; if (_hadVrFocus && !hasVrFocus) { try { if (VrFocusLost != null) { VrFocusLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!_hadVrFocus && hasVrFocus) { try { if (VrFocusAcquired != null) { VrFocusAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _hadVrFocus = hasVrFocus; // Changing effective rendering resolution dynamically according performance #if (UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN) && UNITY_5 && !(UNITY_5_0 || UNITY_5_1 || UNITY_5_2 || UNITY_5_3) if (enableAdaptiveResolution) { if (VR.VRSettings.renderScale < maxRenderScale) { // Allocate renderScale to max to avoid re-allocation VR.VRSettings.renderScale = maxRenderScale; } else { // Adjusting maxRenderScale in case app started with a larger renderScale value maxRenderScale = Mathf.Max(maxRenderScale, VR.VRSettings.renderScale); } float minViewportScale = minRenderScale / VR.VRSettings.renderScale; float recommendedViewportScale = OVRPlugin.GetEyeRecommendedResolutionScale() / VR.VRSettings.renderScale; recommendedViewportScale = Mathf.Clamp(recommendedViewportScale, minViewportScale, 1.0f); VR.VRSettings.renderViewportScale = recommendedViewportScale; } #endif // Dispatch Audio Device events. string audioOutId = OVRPlugin.audioOutId; if (!prevAudioOutIdIsCached) { prevAudioOutId = audioOutId; prevAudioOutIdIsCached = true; } else if (audioOutId != prevAudioOutId) { try { if (AudioOutChanged != null) { AudioOutChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioOutId = audioOutId; } string audioInId = OVRPlugin.audioInId; if (!prevAudioInIdIsCached) { prevAudioInId = audioInId; prevAudioInIdIsCached = true; } else if (audioInId != prevAudioInId) { try { if (AudioInChanged != null) { AudioInChanged(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } prevAudioInId = audioInId; } // Dispatch tracking events. if (wasPositionTracked && !tracker.isPositionTracked) { try { if (TrackingLost != null) { TrackingLost(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } if (!wasPositionTracked && tracker.isPositionTracked) { try { if (TrackingAcquired != null) { TrackingAcquired(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } wasPositionTracked = tracker.isPositionTracked; // Dispatch HSW events. isHSWDisplayed = OVRPlugin.hswVisible; if (isHSWDisplayed && Input.anyKeyDown) { DismissHSWDisplay(); } if (!isHSWDisplayed && _wasHSWDisplayed) { try { if (HSWDismissed != null) { HSWDismissed(); } } catch (Exception e) { Debug.LogError("Caught Exception: " + e); } } _wasHSWDisplayed = isHSWDisplayed; display.Update(); OVRInput.Update(); }
// Update is called once per frame void Update() { OVRInput.Update(); leftTouchActive = OVRInput.IsControllerConnected(OVRInput.Controller.LTouch); rightTouchActive = OVRInput.IsControllerConnected(OVRInput.Controller.RTouch); PoseManager.HandJoint joint = PoseManager.HandJoint.Max; if (Input.GetKeyUp(KeyCode.Alpha0)) { joint = PoseManager.HandJoint.ThumbTip; } else if (Input.GetKeyUp(KeyCode.Alpha1)) { joint = PoseManager.HandJoint.IndexTip; } else if (Input.GetKeyUp(KeyCode.Alpha2)) { joint = PoseManager.HandJoint.MiddleTip; } else if (Input.GetKeyUp(KeyCode.Alpha3)) { joint = PoseManager.HandJoint.RingTip; } else if (Input.GetKeyUp(KeyCode.Alpha4)) { joint = PoseManager.HandJoint.PinkyTip; } else if (Input.GetKeyUp(KeyCode.Alpha5)) { var thumb = poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Thumb); var finger = poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Fingers); var palm = poseManager.GetHandFrameVector(OvrAvatar.HandType.Right, PoseManager.HandFrame.Palm); var wrist = poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.Wrist); var indexBase = poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexBase); var indexTip = poseManager.GetHandTransform(OvrAvatar.HandType.Right, PoseManager.HandJoint.IndexTip); var indexFingerVec = wrist.InverseTransformVector(indexTip.position - indexBase.position).normalized; Debug.Log(indexFingerVec.ToString("F4")); } else if (Input.GetKeyUp(KeyCode.G)) { Debug.Log(GestureManager.RecognitionState); } if (joint < PoseManager.HandJoint.Max) { LogJointState(joint, OvrAvatar.HandType.Right); } // Ctrl-S to save current scene if (Input.GetKeyUp(KeyCode.S) #if UNITY_EDITOR ) #else && (Input.GetKey(KeyCode.RightControl) || Input.GetKey(KeyCode.LeftControl))) #endif { FileIOManager.TrySaveCurrentScene(); }
// Update is called once per frame void Update() { //OVR Input Checks OVRInput.Update();// ALWAYS call this if you want OVRInput.FixedUpdate(); SavePlayer(); //Start if (currentState == GameState.Start) { pauseGameController.enabled = false; // is pausing allowed in this state? for (int i = 0; i < loseEffect.Count; i++) //ensure game is not showing that it is failed { loseEffect[i].SetActive(false); } rb.isKinematic = true; if (startTime == 0f) { startTime = Time.time; } if (Time.time > startTime + StartDelay) { countDownComplete = true; } else { countDownComplete = false; } if (!countDownComplete) { rb.isKinematic = true; CountDownObject.SetActive(true); } if (countDownComplete) { currentState = GameState.Play; CountDownObject.SetActive(false); rb.isKinematic = false; GameStart(Vector3.zero, true); startTime = 0f; } } //Play if (currentState == GameState.Play) { pauseGameController.enabled = true; // is pausing allowed in this state? rb.isKinematic = false; Board.GetComponent <Rigidbody>().isKinematic = false; // check the box in the inspector if this is a build that is going on the Oculus Quest if (QuestBuild) { Height = transform.position.y - headset.transform.position.y; headsetRotateControls(); } else { keyboardRotateControls(); } if (Height >= heightBound && Height <= heightBound + 1) { float heightCurveY = this.heightCurve.Evaluate(Height - heightBound); rb.AddForce(transform.forward * -10 * heightCurveY); } // this is essentially my Air resistance, it keeps the player from going too fast if they are standing. //lockedRotation(); preventBackClimbing(); checkBounds(); clampSpeed(); jump(); } if (currentState == GameState.Lose) { pauseGameController.enabled = false;// is pausing allowed in this state? LoseGame(); } SceneSwitchOveride("q", "start3"); SceneSwitchOveride("e", "5"); }
void Update() { bool loadNextScene = false; bool loadPrevScene = false; bool loadReloadScene = false; OVRInput.Update(); if (Input.GetKeyDown(KeyCode.RightArrow)) { Debug.Log("Right arrow key was pressed."); loadNextScene = true; } if (Input.GetKeyDown(KeyCode.LeftArrow)) { Debug.Log("Left arrow key was pressed."); loadPrevScene = true; } if (Input.GetKeyDown(KeyCode.Space)) { Debug.Log("Space key was pressed."); loadReloadScene = true; } // Manually checking for keydown event on OVR Buttons as GetDown is currently broken bool currentFrame_ButtonOne_State = OVRInput.Get(OVRInput.Button.One, controller); bool currentFrame_ButtonTwo_State = OVRInput.Get(OVRInput.Button.Two, controller); bool currentFrame_ButtonMiddle_State = OVRInput.Get(OVRInput.Button.SecondaryThumbstick); if (currentFrame_ButtonOne_State && !lastFrame_ButtonOne_State) { // Change scene on Button One press Debug.Log("OVR Button One was pressed."); loadPrevScene = true; } if (currentFrame_ButtonTwo_State && !lastFrame_ButtonTwo_State) { // Change scene on Button One press Debug.Log("OVR Button Two was pressed."); loadNextScene = true; } if (currentFrame_ButtonMiddle_State && !lastFrame_ButtonMiddle_State) { // Change scene on Button One press Debug.Log("OVR Button Middle was pressed."); loadReloadScene = true; } lastFrame_ButtonOne_State = currentFrame_ButtonOne_State; lastFrame_ButtonTwo_State = currentFrame_ButtonTwo_State; lastFrame_ButtonMiddle_State = currentFrame_ButtonMiddle_State; if (loadNextScene) { NextScene(); } else if (loadPrevScene) { PreviousScene(); } else if (loadReloadScene) { ReloadScene(); } }
// Update is called once per frame void Update() { // Update position and rotation of the controller gameObject.transform.localPosition = OVRInput.GetLocalControllerPosition(handType); gameObject.transform.localRotation = OVRInput.GetLocalControllerRotation(handType); OVRInput.Update(); // Detect events #region Start button if (OVRInput.Get(OVRInput.Button.Start)) { Debug.Log("Start button pressed"); } #endregion #region Button A and X // Returns true if the primary button (typically “A”) was pressed this frame if (OVRInput.GetDown(OVRInput.Button.One, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button X Down"); } else { Debug.Log("Button A Down"); } } // Returns true if the primary button (typically “A”) is currently pressed if (OVRInput.Get(OVRInput.Button.One, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button X Pressed"); } else { Debug.Log("Button A Pressed"); } } // Returns true if the primary button (typically “A”) is released if (OVRInput.GetUp(OVRInput.Button.One, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button X up"); } else { Debug.Log("Button A up"); } } // Returns true if the primary button is touched if (OVRInput.Get(OVRInput.Touch.One, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button X touched"); } else { Debug.Log("Button A touched"); } } #endregion #region Button B and Y // Returns true if the secondary button (typically “B”) was pressed this frame if (OVRInput.GetDown(OVRInput.Button.Two, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button Y down"); } else { Debug.Log("Button B down"); } } // Returns true if the secondary button (typically “B”) is currently pressed if (OVRInput.Get(OVRInput.Button.Two, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button Y pressed"); } else { Debug.Log("Button B pressed"); } } // Returns true if the secondary button (typically “B”) is released if (OVRInput.GetUp(OVRInput.Button.Two, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button Y up"); } else { Debug.Log("Button B up"); } } // Returns true if the primary button is touched if (OVRInput.Get(OVRInput.Touch.Two, handType)) { if (handType == OVRInput.Controller.LTouch) { Debug.Log("Button Y touched"); } else { Debug.Log("Button B touched"); } } #endregion #region Triggers // Returns a float of the left index finger trigger’s current state. // (range of 0.0f to 1.0f) if (OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger) > 0f) { Debug.Log("Left index trigger: " + OVRInput.Get(OVRInput.RawAxis1D.LIndexTrigger)); } if (OVRInput.Get(OVRInput.RawAxis1D.LHandTrigger) > 0f) { Debug.Log("Left hand trigger: " + OVRInput.Get(OVRInput.RawAxis1D.LHandTrigger)); } if (OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger) > 0f) { Debug.Log("Right index trigger: " + OVRInput.Get(OVRInput.RawAxis1D.RIndexTrigger)); } if (OVRInput.Get(OVRInput.RawAxis1D.RHandTrigger) > 0f) { Debug.Log("Right hand trigger: " + OVRInput.Get(OVRInput.RawAxis1D.RHandTrigger)); } // Trigger touch if (OVRInput.Get(OVRInput.Touch.PrimaryIndexTrigger)) { Debug.Log("Left index trigger touched"); } if (OVRInput.Get(OVRInput.Touch.SecondaryIndexTrigger)) { Debug.Log("Right index trigger touched"); } #endregion #region Thumbsticks // Returns true if the primary thumbstick has been moved upwards more than halfway. // (Up/Down/Left/Right - Interpret the thumbstick as a D-pad). if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickDown)) { Debug.Log("Left thumbstick down"); } // Returns true if the primary thumbstick is currently pressed (clicked as a button) if (OVRInput.Get(OVRInput.Button.PrimaryThumbstick)) { Vector2 coordinates = OVRInput.Get(OVRInput.Axis2D.PrimaryThumbstick); Debug.Log("Left thumbstick pressed: x: " + coordinates.x + " / y: " + coordinates.y); } // Returns true if the primary thumbstick has been moved upwards more than halfway. // (Up/Down/Left/Right - Interpret the thumbstick as a D-pad). if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickUp)) { Debug.Log("Right thumbstick up"); } // Returns true if the secondary thumbstick has been moved upwards more than halfway. // (Up/Down/Left/Right - Interpret the thumbstick as a D-pad). if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickDown)) { Debug.Log("Right thumbstick down"); } // Returns true if the secondary thumbstick is currently pressed (clicked as a button) if (OVRInput.Get(OVRInput.Button.SecondaryThumbstick)) { Vector2 coordinates = OVRInput.Get(OVRInput.Axis2D.SecondaryThumbstick); Debug.Log("Right thumbstick pressed: x: " + coordinates.x + " / y: " + coordinates.y); } // Returns true if the secondary thumbstick has been moved upwards more than halfway. // (Up/Down/Left/Right - Interpret the thumbstick as a D-pad). if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickUp)) { Debug.Log("Right thumbstick up"); } // Thumbsticks touch if (OVRInput.Get(OVRInput.Touch.PrimaryThumbstick)) { Debug.Log("Left thumbstick touched"); } if (OVRInput.Get(OVRInput.Touch.SecondaryThumbstick)) { Debug.Log("Right thumbstick touched"); } #endregion #region Thumbrest // Thumb rest touch if (OVRInput.Get(OVRInput.Touch.PrimaryThumbRest)) { Debug.Log("Left thumb rest touched"); } if (OVRInput.Get(OVRInput.Touch.SecondaryThumbRest)) { Debug.Log("Right thumb rest touched"); } #endregion }
// Update is called once per frame void Update() { OVRInput.Update(); UpKeys.Clear(); if (!GetKey(ControllerInput.btn_touchpad) && CurrentKeys.Contains((int)ControllerInput.btn_touchpad)) { UpKeys.Add((int)ControllerInput.btn_touchpad); } if (!GetKey(ControllerInput.mouse) && CurrentKeys.Contains((int)ControllerInput.mouse)) { UpKeys.Add((int)ControllerInput.mouse); } if (!GetKey(ControllerInput.btn_back) && CurrentKeys.Contains((int)ControllerInput.btn_back)) { UpKeys.Add((int)ControllerInput.btn_back); } if (!GetKey(ControllerInput.btn_tigger) && CurrentKeys.Contains((int)ControllerInput.btn_tigger)) { UpKeys.Add((int)ControllerInput.btn_tigger); } DownKeys.Clear(); if (GetKey(ControllerInput.btn_touchpad) && !CurrentKeys.Contains((int)ControllerInput.btn_touchpad)) { DownKeys.Add((int)ControllerInput.btn_touchpad); } if (GetKey(ControllerInput.mouse) && !CurrentKeys.Contains((int)ControllerInput.mouse)) { DownKeys.Add((int)ControllerInput.mouse); } if (GetKey(ControllerInput.btn_back) && !CurrentKeys.Contains((int)ControllerInput.btn_back)) { DownKeys.Add((int)ControllerInput.btn_back); } if (GetKey(ControllerInput.btn_tigger) && !CurrentKeys.Contains((int)ControllerInput.btn_tigger)) { DownKeys.Add((int)ControllerInput.btn_tigger); } CurrentKeys.Clear(); if (GetKey(ControllerInput.btn_touchpad)) { CurrentKeys.Add((int)ControllerInput.btn_touchpad); } if (GetKey(ControllerInput.mouse)) { CurrentKeys.Add((int)ControllerInput.mouse); } if (GetKey(ControllerInput.btn_back)) { CurrentKeys.Add((int)ControllerInput.btn_back); } if (GetKey(ControllerInput.btn_tigger)) { CurrentKeys.Add((int)ControllerInput.btn_tigger); } }
void Update() { if (playerOne.Control.IsFinished() || playerTwo.Control.IsFinished()) { sphereOne.enabled = false; sphereTwo.enabled = false; interview.Control.Play(); interviewSphere.enabled = true; source3.Play(); } MediaPlayer currentPlayer = playerOne.Control.IsPlaying() ? playerOne : playerTwo; if (Mathf.Abs((safeTimers[safeTimerIndex].x * 1000) - currentPlayer.Control.GetCurrentTimeMs()) < MARGIN_OF_ERROR) { timerBar.value = 0; timerBar.maxValue = safeTimers[safeTimerIndex].y; timerBar.gameObject.SetActive(true); StartCoroutine(TimerBar()); allowSwitch = true; safeTimerIndex++; } if (!allowSwitch) { return; } OVRInput.Update(); if (acceptInput && OVRInput.Get(OVRInput.Button.One)) { acceptInput = false; if (playerOne.Control.IsPlaying() && !playerTwo.Control.IsFinished()) { float time = playerOne.Control.GetCurrentTimeMs(); playerOne.Control.Pause(); sphereOne.enabled = false; playerTwo.Control.SeekFast(time); playerTwo.Control.Play(); sphereTwo.enabled = true; source1.mute = true; source2.mute = false; } else if (playerTwo.Control.IsPlaying() && !playerOne.Control.IsFinished()) { float time = playerTwo.Control.GetCurrentTimeMs(); playerTwo.Control.Pause(); sphereTwo.enabled = false; playerOne.Control.SeekFast(time); playerOne.Control.Play(); sphereOne.enabled = true; source1.mute = false; source2.mute = true; } StartCoroutine(ResetInput()); } }
/// <summary> /// Update is called every frame. /// For SteamVR plugin this is where the device Index is set up. /// For Oculus plugin this is where the tracking is done. /// </summary> protected virtual void Update() { #if ZED_OCULUS //Used only if the Oculus Integration plugin is detected. //Check if the VR headset is connected. if (OVRManager.isHmdPresent && loadeddevice == "Oculus") { if (OVRInput.GetConnectedControllers().ToString().ToLower().Contains("touch")) { //Depending on which tracked device we are looking for, start tracking it. if (deviceToTrack == Devices.LeftController) //Track the Left Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch)); } if (deviceToTrack == Devices.RightController) //Track the Right Oculus Controller. { RegisterPosition(1, OVRInput.GetLocalControllerPosition(OVRInput.Controller.RTouch), OVRInput.GetLocalControllerRotation(OVRInput.Controller.RTouch)); } if (deviceToTrack == Devices.Hmd) //Track the Oculus Hmd. { RegisterPosition(1, InputTracking.GetLocalPosition(XRNode.CenterEye), InputTracking.GetLocalRotation(XRNode.CenterEye)); } //Use our saved positions to apply a delay before assigning it to this object's Transform. if (poseData.Count > 0) { sl.Pose p; //Delay the saved values inside GetValuePosition() by a factor of latencyCompensation in milliseconds. p = GetValuePosition(1, (float)(latencyCompensation / 1000.0f)); transform.position = p.translation; //Assign new delayed Position transform.rotation = p.rotation; //Assign new delayed Rotation. } } } //Enable updating the internal state of OVRInput. OVRInput.Update(); #endif #if ZED_STEAM_VR UpdateControllerState(); //Get the button states so we can check if buttons are down or not. timerSteamVR += Time.deltaTime; //Increment timer for checking on devices if (timerSteamVR <= timerMaxSteamVR) { return; } timerSteamVR = 0f; //Checks if a device has been assigned if (index == EIndex.None && loadeddevice == "OpenVR") { //We look for any device that has "tracker" in its 3D model mesh name. //We're doing this since the device ID changes based on how many devices are connected to SteamVR. //This way, if there's no controllers or just one, it's going to get the right ID for the Tracker. if (deviceToTrack == Devices.ViveTracker) { var error = ETrackedPropertyError.TrackedProp_Success; for (uint i = 0; i < 16; i++) { var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty(i, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { index = (EIndex)i; break; //We break out of the loop, but we can use this to set up multiple Vive Trackers if we want to. } } } //Looks for a device with the role of a Right Hand. if (deviceToTrack == Devices.RightController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.RightHand); } //Looks for a device with the role of a Left Hand. if (deviceToTrack == Devices.LeftController) { index = (EIndex)OpenVR.System.GetTrackedDeviceIndexForControllerRole(ETrackedControllerRole.LeftHand); } //Assigns the HMD. if (deviceToTrack == Devices.Hmd) { index = EIndex.Hmd; } //Display a warning if there was supposed to be a calibration file, and none was found. if (SNHolder.Equals("NONE")) { UnityEngine.Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_NOT_FOUND)); } else if (SNHolder != null && index != EIndex.None) // { //If the Serial number of the Calibrated device isn't the same as the current tracked device by this script... var snerror = ETrackedPropertyError.TrackedProp_Success; var snresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_SerialNumber_String, snresult, 64, ref snerror); if (!snresult.ToString().Contains(SNHolder)) { UnityEngine.Debug.LogWarning(ZEDLogMessage.Error2Str(ZEDLogMessage.ERROR.PAD_CAMERA_CALIBRATION_MISMATCH) + " Serial Number: " + SNHolder); //... then look for that device through all the connected devices. for (int i = 0; i < 16; i++) { //If a device with the same Serial Number is found, then change the device to track of this script. var chsnresult = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)i, ETrackedDeviceProperty.Prop_SerialNumber_String, chsnresult, 64, ref snerror); if (snresult.ToString().Contains(SNHolder)) { index = (EIndex)i; string deviceRole = OpenVR.System.GetControllerRoleForTrackedDeviceIndex((uint)index).ToString(); if (deviceRole.Equals("RightHand")) { deviceToTrack = Devices.RightController; } else if (deviceRole.Equals("LeftHand")) { deviceToTrack = Devices.LeftController; } else if (deviceRole.Equals("Invalid")) { var error = ETrackedPropertyError.TrackedProp_Success; var result = new System.Text.StringBuilder((int)64); OpenVR.System.GetStringTrackedDeviceProperty((uint)index, ETrackedDeviceProperty.Prop_RenderModelName_String, result, 64, ref error); if (result.ToString().Contains("tracker")) { deviceToTrack = Devices.ViveTracker; } } UnityEngine.Debug.Log("A connected device with the correct Serial Number was found, and assigned to " + this + " the correct device to track."); break; } } } } oldDevice = deviceToTrack; } if (deviceToTrack != oldDevice) { index = EIndex.None; } #endif }
// Update is called once per frame void Update() { Matrix4x4 localToWorld = trackingSpace.localToWorldMatrix; // Get the current orientation of the left controller Quaternion orientation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch); // Get the orientation a litle bit forward in a raycast from the controller Vector3 worldOrientation = localToWorld.MultiplyVector(orientation * Vector3.forward); // Get the current position of the left controller Vector3 position = OVRInput.GetLocalControllerPosition(OVRInput.Controller.LTouch); Vector3 worldStartPoint = localToWorld.MultiplyPoint(position); Vector3 maxPoint = worldStartPoint + worldOrientation * 500; // Move centerpoint of globe further away from controller if we scale up the globe. float distance = 0.065f + (transform.localScale.x * 1000); //Key line of this file to make it feal natural that you're actually holding the globe. The globe is positioned in a ray away from the controller. When we scale the globe, the centerpoint // of the globe will also be further away to not overlap the controller. transform.localPosition = Vector3.MoveTowards(worldStartPoint + worldOrientation * 0.01f, maxPoint, distance); // Rotate left and right; if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickRight)) { currentRotation += 1.3f; } if (OVRInput.Get(OVRInput.Button.PrimaryThumbstickLeft)) { currentRotation -= 1.3f; } // We can rotate with the joysticks but we can also move with natural hand movements. For this we have to add the currentRotation of the joysticks to the // rotation of the left controller Quaternion rotation = OVRInput.GetLocalControllerRotation(OVRInput.Controller.LTouch); rotation *= Quaternion.Euler(0, currentRotation, 0); transform.localRotation = rotation; // Scale up and down OVRInput.Update(); // Call before checking the input if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickUp)) { if (transform.localScale.x < 0.0004f) { transform.localScale += new Vector3(0.000002f, 0.000002f, 0.000002f); } } if (OVRInput.Get(OVRInput.Button.SecondaryThumbstickDown)) { if (transform.localScale.x > 0.0001f) { transform.localScale -= new Vector3(0.000002f, 0.000002f, 0.000002f); } } // If we guessed the location by holding the button we can draw the guessed and to be guessed positions on the globe. if (RayPointer.hasGuessed) { GameObject pinpoint = GameObject.Find("pinpoint"); var instance = GameObject.CreatePrimitive(PrimitiveType.Cylinder); instance.transform.position = _globeTransform.TransformPoint(Conversions.GeoToWorldGlobePosition(RayPointer.pinpointLocation, _globeFactory.Radius)); instance.transform.localScale = Vector3.one * .008f; instance.transform.LookAt(_globeTransform); //Flip the cilinders so they are standing straight on the globe, half of the cilinder is in the globe then, is no problem. instance.transform.localRotation *= Quaternion.Euler(90, 0, 0); instance.transform.SetParent(transform); instance.name = "pinpoint"; Renderer rend = instance.GetComponent <Renderer>(); rend.material.color = new Color(20, 0, 255); if (pinpoint != null) { Destroy(pinpoint); } GameObject result_pinpoint = GameObject.Find("result_pinpoint"); var result_instance = GameObject.CreatePrimitive(PrimitiveType.Cylinder); Vector2d currentlocation = new Vector2d(GeoguessVRGame.currentLocation.Lat, GeoguessVRGame.currentLocation.Long); result_instance.transform.position = _globeTransform.TransformPoint(Conversions.GeoToWorldGlobePosition(currentlocation, _globeFactory.Radius)); result_instance.transform.localScale = Vector3.one * .008f; result_instance.transform.LookAt(_globeTransform); //Flip the cilinders so they are standing straight on the globe, half of the cilinder is in the globe then, is no problem. result_instance.transform.localRotation *= Quaternion.Euler(90, 0, 0); result_instance.transform.SetParent(transform); result_instance.name = "result_pinpoint"; Renderer rend1 = result_instance.GetComponent <Renderer>(); rend1.material.color = new Color(0, 255, 20); if (result_pinpoint != null) { Destroy(result_pinpoint); } } else { GameObject pinpoint = GameObject.Find("result_pinpoint"); if (pinpoint != null) { Destroy(pinpoint); } } }
void FixedUpdate() { OVRInput.Update(); if (OVRInput.Get(handTrigger) > 0) { grabbing = true; //Debug.Log(OVRInput.Get( OVRInput.Axis1D.PrimaryHandTrigger) +" ; "+OVRInput.Get( OVRInput.Axis1D.SecondaryHandTrigger)); if (grabbedObject == null) { Collider[] colObjects = Physics.OverlapSphere(transform.position, col.radius, mask); //Debug.Log("Amount: "+colObjects.Length); GrabableObject script; for (int i = 0; i < colObjects.Length; i++) { script = colObjects[i].attachedRigidbody.GetComponent <GrabableObject>(); if (script.fixedJoint == null) { script.OnGrab(myRigid); grabbedObject = colObjects[i].attachedRigidbody.gameObject; break; } } } } else { grabbing = false; if (grabbedObject != null) { grabbedObject.GetComponent <GrabableObject>().Release(); grabbedObject = null; } } if (hand == Hands.RightHand) { if (OVRInput.GetDown(OVRInput.RawButton.A)) { Debug.Log("Button 1 pressed"); CastRayForMarkable(); } if (OVRInput.GetDown(OVRInput.RawButton.B)) { Debug.Log("Button 2 pressed"); CastRayForMarkable(); } } else { if (OVRInput.GetDown(OVRInput.RawButton.X)) { Debug.Log("Button 3 pressed"); CastRayForMarkable(); } if (OVRInput.GetDown(OVRInput.RawButton.Y)) { Debug.Log("Button 4 pressed"); CastRayForMarkable(); } } }
// Update is called once per frame void Update() { OVRInput.Update(); checkInput(); }
// Update is called once per frame void Update() { OVRInput.Update(); log("->Update()!"); Transform root_anchor = camera_rig.trackingSpace; Transform centerEyeAnchor = camera_rig.centerEyeAnchor; Transform leftHandAnchor = camera_rig.leftHandAnchor; Transform rightHandAnchor = camera_rig.rightHandAnchor; Vector3 eye_P_right_hand = rightHandAnchor.position; // - center_eye_anchor.position; Quaternion rightHandQuat = rightHandAnchor.rotation; Quaternion leftHandQuat = leftHandAnchor.rotation; Quaternion headQuat = centerEyeAnchor.rotation; string msg; msg = string.Format("{0:N5}", -headQuat[2]) + ',' + string.Format("{0:N5}", headQuat[0]) + ',' + string.Format("{0:N5}", -headQuat[1]) + ',' + string.Format("{0:N5}", headQuat[3]); //msg = string.Format("{0:N5}", eye_P_right_hand[2]) + ',' + string.Format("{0:N5}", -eye_P_right_hand[0]) + ',' + string.Format("{0:N5}", eye_P_right_hand[1]) + ','; //msg += string.Format("{0:N5}", rightHandQuat[2]) + ',' + string.Format("{0:N5}", rightHandQuat[0]) + ',' + string.Format("{0:N5}", rightHandQuat[1]) + ',' + string.Format("{0:N5}", rightHandQuat[3]); //msg += string.Format("{0:N5}", -right_hand_quat[2]) + ',' + string.Format("{0:N5}", right_hand_quat[3]) + ',' + string.Format("{0:N5}", right_hand_quat[1]) + ',' + string.Format("{0:N5}", right_hand_quat[0]); log(msg); if (connectTCP) { //Debug.Log("tcp"); //Debug.Log(msg); tcp.writeSocket(msg); //String str = tcp.readSocket(); //Debug.Log(str); //Debug.Log(str.Length); //if (str.Equals("end")) { // Debug.Log("End"); // string data = string.Join("", dataList.ToArray()); // dataList.Clear(); // total = 0; // Debug.Log("Total length: "); // Debug.Log(data.Length); //} else { // if (str.Length != 0) { // total += str.Length; // Debug.Log(total); // dataList.Add(str); // } //} } //String s = tcpImage.readThread(); //if (s.Length != 0) { // Debug.Log("Length of image received: " + s.Length); // //Debug.Log("First letters: " + s.Substring(0, 20)); //} //if (connectUDP) { // string data = udp.readSocket(); // Debug.Log(data.Length); //} // haptics // WARNING: To get it working, you have to wear the headset or activate its proximity sensor!! if (OVRInput.Get(OVRInput.Button.One)) { Debug.Log("Button A pressed!"); haptics.Vibrate(VibrationForce.Light); } if (OVRInput.Get(OVRInput.Button.Two)) { Debug.Log("Button B pressed!"); haptics.Vibrate(VibrationForce.Medium); } if (OVRInput.Get(OVRInput.Button.Three)) { Debug.Log("Button X pressed!"); haptics.Vibrate(VibrationForce.Hard); } log(" Update()->"); }
void Update() { OVRInput.Update(); OVRInput.FixedUpdate(); if ((Input.GetKeyDown(Constants.interactionKey) || OVRInput.GetDown(OVRInput.Button.One)) && !finished) { Debug.Log("button pressed"); // Get buttons pressed for (int i = 0; i < triggers.Length; i++) { if (triggers[i].highlighted) { if (i < 10) { current += i; } else { current = current.Substring(0, current.Length - 1); } } } //Debug.Log("Current"); // Compare current if (current.Length == 4) { finished = true; } if (CodeSolved) { Debug.Log("CodeSolved!"); } } if (finished) { timer += Time.deltaTime; } if (timer >= DELAY) { finished = false; timer = 0; Clear(); } for (int i = 0; i < triggers.Length; i++) { int num = current.LastIndexOf(i.ToString()); //Debug.Log(this.histcolor[0]); Renderer rend = triggers[i].transform.parent.GetComponentInParent <Renderer>(); if (num != -1) { rend.material.SetColor("_Color", histcolor[num]); } else { rend.material.SetColor("_Color", Color.white); } if (finished && timer > DELAY / 2) { if ((int)(timer / BLINK) % 2 == 0) { rend.material.SetColor("_Color", Color.white); } else { if (current.Equals(CORRECT)) { rend.material.SetColor("_Color", Color.green); } else { rend.material.SetColor("_Color", Color.red); } } } } }
void Update() { if (_canUseScript || currentMode == null) { return; } // When the scenario is playing if (_timeSystem.IsRunning) { // Update the input OVRInput.Update(); // Get btn values bool btn_trigger = OVRInput.Get(OVRInput.Button.SecondaryIndexTrigger); bool btn_xbtn = OVRInput.Get(OVRInput.Button.One); // Find the end position of the pointer endPosition = transform.position + (lineMaxLength * transform.forward); // When taking a break during the modes in which the system takes a break if (currentMode is ModePlayerstop || currentMode is ModeSystemstop) { // Enable line during break if (_timeSystem.IsTakingBreak) { lineRenderer.enabled = true; } // Disable line outside of break else { lineRenderer.enabled = false; } } // If taking a break button is used, take a break in the right mode, when not taking a break if (btn_xbtn) { if (currentMode is ModePlayerstop && !_timeSystem.IsTakingBreak) { _timeSystem.StartBreak(); } } // If select button is used if (btn_trigger) { // When taking break in certain modes if ((currentMode is ModePlayerstop || currentMode is ModeSystemstop) && _timeSystem.IsTakingBreak) { SelectHitbox(); } // In other modes else if (currentMode is ModeNonStop) { SelectHitbox(); } } // Draw line in scene lineRenderer.SetPosition(0, transform.position); lineRenderer.SetPosition(1, endPosition); } else { // Disable line outside of scenario lineRenderer.enabled = false; } }