// ShowGeometry public void ShowGeometry(bool show) { // Load up the prefab if (GeometryReference == null) { GeometryReference = GameObject.Instantiate(Resources.Load("OVRMagReference")) as GameObject; GeometryReferenceMarkMat = GeometryReference.transform.Find("Mark").renderer.material; } if (GeometryReference != null) { GeometryReference.SetActive(show); AttachGeometryToCamera(show, ref GeometryReference); OVRUtils.SetLocalTransformIdentity(ref GeometryReference); } // Load up the prefab if (GeometryCompass == null) { GeometryCompass = GameObject.Instantiate(Resources.Load("OVRMagCompass")) as GameObject; } if (GeometryCompass != null) { GeometryCompass.SetActive(show); AttachGeometryToCamera(show, ref GeometryCompass); OVRUtils.SetLocalTransformIdentity(ref GeometryCompass); } }
private void TrySetHandActive(VRAvatarLimbType limbType) { var isLimbConnected = OVRUtils.IsLimbConnected(limbType); var limb = mAvatar.GetLimb(limbType); limb.SetActive(isLimbConnected); }
private OVRInput.Controller ActiveController() { OVRInput.Controller controller = OVRInput.GetActiveController(); if (OVRUtils.IsQuestControllerConnected) { controller = OVRUtils.GetControllerType(mLimbType); } return(controller); }
private void TrySetHandsActive(bool active) { if (mAvatar != null) { if (OVRUtils.IsGearVRHeadset()) { if (OVRInput.GetActiveController() == OVRInput.Controller.Touchpad) { active = false; } } mAvatar.SetHandsActive(active); } }
/// <summary> /// Start this instance. /// </summary> void Start () { if(CameraController != null) { // Set the GUI target VisionGuide = GameObject.Instantiate(Resources.Load("OVRVisionGuideMessage")) as GameObject; // Grab transform of GUI object Transform t = VisionGuide.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref VisionGuide); // Reset the transform values OVRUtils.SetLocalTransform(ref VisionGuide, ref t); // Deactivate the object VisionGuide.SetActive(false); // Set layer on object VisionGuide.layer = LayerMask.NameToLayer(LayerName); } }
/// <summary> /// Attachs the geometry to camera. /// </summary> /// <param name="attach">If set to <c>true</c> attach.</param> /// <param name="go">Go.</param> public void AttachGeometryToCamera(bool attach, ref GameObject go) { if (CameraController != null) { if (attach == true) { CameraController.AttachGameObjectToCamera(ref go); OVRUtils.SetLocalTransformIdentity(ref go); Vector3 lp = go.transform.localPosition; // we will move the position of everything over to the left, so get // IPD / 2 and position camera towards negative X float ipd = 0.0f; CameraController.GetIPD(ref ipd); lp.x -= ipd * 0.5f; go.transform.localPosition = lp; } } }
/// <summary> /// Start this instance. /// </summary> void Start() { if (CameraController != null) { // Set the GUI target VisionGuide = GameObject.Instantiate(Resources.Load("OVRVisionGuideMessage")) as GameObject; // Grab transform of GUI object Transform t = VisionGuide.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref VisionGuide); // Reset the transform values OVRUtils.SetLocalTransform(ref VisionGuide, ref t); // Deactivate the object VisionGuide.SetActive(false); // Set layer on object VisionGuide.layer = LayerMask.NameToLayer(LayerName); // Set initial location of offset to be the players center eye location Vector3 eyeOffset = Vector3.zero; CameraController.GetEyeCenterPosition(ref eyeOffset); OVRCamera.SetCameraPositionOffset(ref eyeOffset); } }
private void AttachControllerVisual(VRAvatarController avatarController) { var limb = avatarController.GetComponentInParent <IVRAvatarLimb>(); var prefab = VRAvatarHelper.EnsureLoadPrefab <VRControllerVisual>(ControllerVisualPrefabName); prefab.gameObject.SetActive(false); // Create controller instance var instance = Instantiate(prefab); instance.name = prefab.name; instance.transform.SetParentAndIdentity(avatarController.transform); // Make sure the OVRGearVrController component exists... var trackedRemote = instance.gameObject.GetComponent <OVRControllerHelper>(); if (trackedRemote == null) { trackedRemote = instance.gameObject.AddComponent <OVRControllerHelper>(); } avatarController.ControllerVisual = instance; mRemotes.Add(trackedRemote); // Assign the correct controller based on the limb type the controller is attached to OVRInput.Controller controllerType = GetControllerTypeForLimb(limb); trackedRemote.m_controller = controllerType; trackedRemote.m_modelGearVrController.SetActive(true); // Activate the controller // TODO Do we need to set active here? var active = OVRUtils.IsLimbConnected(limb.LimbType); instance.gameObject.SetActive(active); Debug.Log($"Attached Controller: {limb.LimbType} and SetActive: {active} Controller Type set to: {controllerType}"); }
// Start void Start() { AlphaFadeValue = 1.0f; CurrentLevel = 0; PrevStartDown = false; PrevHatDown = false; PrevHatUp = false; ShowVRVars = false; OldSpaceHit = false; strFPS = "FPS: 0"; LoadingLevel = false; ScenesVisible = false; // Ensure that camera controller variables have been properly // initialized before we start reading them if (CameraController != null) { CameraController.InitCameraControllerVariables(); GuiHelper.SetCameraController(ref CameraController); } // Set the GUI target GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject; if (GUIRenderObject != null) { if (GUIRenderTexture == null) { int w = Screen.width; int h = Screen.height; if (CameraController.PortraitMode == true) { int t = h; h = w; w = t; } GUIRenderTexture = new RenderTexture(w, h, 24); GuiHelper.SetPixelResolution(w, h); GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution); } } // Attach GUI texture to GUI object and GUI object to Camera if (GUIRenderTexture != null && GUIRenderObject != null) { GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture; if (CameraController != null) { // Grab transform of GUI object Transform t = GUIRenderObject.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref GUIRenderObject); // Reset the transform values (we will be maintaining state of the GUI object // in local state) OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t); // Deactivate object until we have completed the fade-in // Also, we may want to deactive the render object if there is nothing being rendered // into the UI // we will move the position of everything over to the left, so get // IPD / 2 and position camera towards negative X Vector3 lp = GUIRenderObject.transform.localPosition; float ipd = 0.0f; CameraController.GetIPD(ref ipd); lp.x -= ipd * 0.5f; GUIRenderObject.transform.localPosition = lp; GUIRenderObject.SetActive(false); } } // Save default values initially StoreSnapshot("DEFAULT"); // Make sure to hide cursor if (Application.isEditor == false) { Screen.showCursor = false; Screen.lockCursor = true; } // Add delegates to update; useful for ordering menu tasks, if required UpdateFunctions += UpdateFPS; // CameraController updates if (CameraController != null) { UpdateFunctions += UpdateIPD; UpdateFunctions += UpdatePrediction; UpdateFunctions += UpdateFOV; UpdateFunctions += UpdateDistortionCoefs; UpdateFunctions += UpdateEyeHeightOffset; } // PlayerController updates if (PlayerController != null) { UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier; UpdateFunctions += UpdatePlayerControllerMovement; } // MainMenu updates UpdateFunctions += UpdateSelectCurrentLevel; UpdateFunctions += UpdateHandleSnapshots; // Device updates UpdateFunctions += UpdateDeviceDetection; UpdateFunctions += UpdateResetOrientation; OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback); // Mag Yaw-Drift correction UpdateFunctions += MagCal.UpdateMagYawDriftCorrection; MagCal.SetOVRCameraController(ref CameraController); // Crosshair functionality Crosshair.Init(); Crosshair.SetCrosshairTexture(ref CrosshairImage); Crosshair.SetOVRCameraController(ref CameraController); Crosshair.SetOVRPlayerController(ref PlayerController); UpdateFunctions += Crosshair.UpdateCrosshair; // Check for HMD and sensor CheckIfRiftPresent(); // Init static members ScenesVisible = false; }
// Start void Start() { AlphaFadeValue = 1.0f; CurrentLevel = 0; PrevStartDown = false; PrevHatDown = false; PrevHatUp = false; ShowVRVars = false; OldSpaceHit = false; strFPS = "FPS: 0"; LoadingLevel = false; sShowLevels = false; // Ensure that camera controller variables have been properly // initialized before we start reading them if (CameraController != null) { CameraController.InitCameraControllerVariables(); } // Attach GUI texture to GUI object and GUI object to Camera if (GUIRenderTexture != null && GUIRenderObject != null) { GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture; if (CameraController != null) { // Grab transform of GUI object Transform t = GUIRenderObject.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref GUIRenderObject); // Reset the transform values (we will be maintaining state of the GUI object // in local state) OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t); // Deactivate object until we have completed the fade-in // Also, we may want to deactive the render object if there is nothing being rendered // into the UI GUIRenderObject.SetActive(false); } } // Save default values initially StoreSnapshot("DEFAULT"); // Make sure to hide cursor //Screen.showCursor = false; //Screen.lockCursor = true; // Add delegates to update; useful for ordering menu tasks, if required UpdateFunctions += UpdateFPS; // CameraController updates if (CameraController != null) { UpdateFunctions += UpdateIPD; UpdateFunctions += UpdatePrediction; UpdateFunctions += UpdateFOV; UpdateFunctions += UpdateDistortionCoefs; UpdateFunctions += UpdateHeightOffset; } // PlayerController updates if (PlayerController != null) { UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier; } // MainMenu updates UpdateFunctions += UpdateSelectCurrentLevel; UpdateFunctions += UpdateHandleSnapshots; // Device updates UpdateFunctions += UpdateDeviceDetection; UpdateFunctions += UpdateResetOrientation; OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback); // Mag Yaw-Drift correction UpdateFunctions += MagCal.UpdateMagYawDriftCorrection; MagCal.SetOVRCameraController(ref CameraController); // Check for HMD and sensor CheckIfRiftPresent(); // Init static members sShowLevels = false; }
/// <summary> /// Start this instance. /// </summary> void Start() { AlphaFadeValue = 1.0f; CurrentLevel = 0; PrevStartDown = false; PrevHatDown = false; PrevHatUp = false; ShowVRVars = false; OldSpaceHit = false; strFPS = "FPS: 0"; LoadingLevel = false; ScenesVisible = false; // Ensure that camera controller variables have been properly // initialized before we start reading them if (CameraController != null) { CameraController.InitCameraControllerVariables(); } // Set the GUI target GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject; if (GUIRenderObject != null) { // Chnge the layer GUIRenderObject.layer = LayerMask.NameToLayer(LayerName); if (GUIRenderTexture == null) { int w = Screen.width; int h = Screen.height; // We don't need a depth buffer on this texture GUIRenderTexture = new RenderTexture(w, h, 0); GuiHelper.SetPixelResolution(w, h); // NOTE: All GUI elements are being written with pixel values based // from DK1 (1280x800). These should change to normalized locations so // that we can scale more cleanly with varying resolutions //GuiHelper.SetDisplayResolution(OVRDevice.HResolution, // OVRDevice.VResolution); GuiHelper.SetDisplayResolution(1280.0f, 800.0f); } } // Attach GUI texture to GUI object and GUI object to Camera if (GUIRenderTexture != null && GUIRenderObject != null) { GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture; if (CameraController != null) { // Grab transform of GUI object Transform t = GUIRenderObject.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref GUIRenderObject); // Reset the transform values (we will be maintaining state of the GUI object // in local state) OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t); // Deactivate object until we have completed the fade-in // Also, we may want to deactive the render object if there is nothing being rendered // into the UI // we will move the position of everything over to the left, so get // IPD / 2 and position camera towards negative X Vector3 lp = GUIRenderObject.transform.localPosition; float ipd = 0.0f; CameraController.GetIPD(ref ipd); lp.x -= ipd * 0.5f; GUIRenderObject.transform.localPosition = lp; GUIRenderObject.SetActive(false); } } // Save default values initially StoreSnapshot("DEFAULT"); // Make sure to hide cursor if (Application.isEditor == false) { Screen.showCursor = false; Screen.lockCursor = true; } // Add delegates to update; useful for ordering menu tasks, if required UpdateFunctions += UpdateFPS; // CameraController updates if (CameraController != null) { UpdateFunctions += UpdateIPD; UpdateFunctions += UpdatePrediction; // Set LPM on by default UpdateFunctions += UpdateLowPersistanceMode; OVRDevice.SetLowPersistanceMode(LowPersistanceMode); UpdateFunctions += UpdateVisionMode; UpdateFunctions += UpdateFOV; UpdateFunctions += UpdateEyeHeightOffset; // Add a GridCube component to this object GridCube = gameObject.AddComponent <OVRGridCube>(); GridCube.SetOVRCameraController(ref CameraController); // Add a VisionGuide component to this object VisionGuide = gameObject.AddComponent <OVRVisionGuide>(); VisionGuide.SetOVRCameraController(ref CameraController); VisionGuide.SetFadeTexture(ref FadeInTexture); VisionGuide.SetVisionGuideLayer(ref LayerName); } // PlayerController updates if (PlayerController != null) { UpdateFunctions += UpdateSpeedAndRotationScaleMultiplier; UpdateFunctions += UpdatePlayerControllerMovement; } // MainMenu updates UpdateFunctions += UpdateSelectCurrentLevel; UpdateFunctions += UpdateHandleSnapshots; // Device updates UpdateFunctions += UpdateDeviceDetection; // Add a callback to detect device detection OVRMessenger.AddListener <Device, bool>("Sensor_Attached", UpdateDeviceDetectionMsgCallback); // Mag Yaw-Drift correction // We will test to see if we are already calibrated by the // Calibration tool MagCal.SetInitialCalibarationState(); UpdateFunctions += MagCal.UpdateMagYawDriftCorrection; MagCal.SetOVRCameraController(ref CameraController); // Crosshair functionality Crosshair.Init(); Crosshair.SetCrosshairTexture(ref CrosshairImage); Crosshair.SetOVRCameraController(ref CameraController); Crosshair.SetOVRPlayerController(ref PlayerController); UpdateFunctions += Crosshair.UpdateCrosshair; // Check for HMD and sensor CheckIfRiftPresent(); // Reset tracker position. // We assume that the CameraController is at the desired neck location Vector3 eyeOffset = Vector3.zero; if (CameraController != null) { CameraController.GetEyeCenterPosition(ref eyeOffset); } OVRCamera.ResetCameraPositionOrientation(ref eyeOffset, true, false, false); }
// Use this for initialization void Start() { // Set the GUI target GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject; // Find camera controller OVRCameraController[] CameraControllers; CameraControllers = FindObjectsOfType(typeof(OVRCameraController)) as OVRCameraController[]; if (CameraControllers.Length == 0) { Debug.LogWarning("OVRMainMenu: No OVRCameraController attached."); } else if (CameraControllers.Length > 1) { Debug.LogWarning("OVRMainMenu: More then 1 OVRCameraController attached."); } else { CameraController = CameraControllers[0]; } if (GUIRenderObject != null) { if (GUIRenderTexture == null) // TODO: *** Screen.width from RUISDisplayManager { int w = Screen.width; int h = Screen.height; if (CameraController.PortraitMode == true) { int t = h; h = w; w = t; } GUIRenderTexture = new RenderTexture(w, h, 24); GuiHelper.SetPixelResolution(w, h); GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution); } } // Attach GUI texture to GUI object and GUI object to Camera if (GUIRenderTexture != null && GUIRenderObject != null) { GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture; if (CameraController != null) { // Grab transform of GUI object Transform t = GUIRenderObject.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref GUIRenderObject); // Reset the transform values (we will be maintaining state of the GUI object // in local state) OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t); // Deactivate object until we have completed the fade-in // Also, we may want to deactive the render object if there is nothing being rendered // into the UI // we will move the position of everything over to the left, so get // IPD / 2 and position camera towards negative X Vector3 lp = GUIRenderObject.transform.localPosition; float ipd = 0.0f; CameraController.GetIPD(ref ipd); lp.x -= ipd * 0.5f; GUIRenderObject.transform.localPosition = lp; GUIRenderObject.SetActive(false); } } // Mag Yaw-Drift correction magCal.SetOVRCameraController(ref CameraController); }
// Use this for initialization void Start() { GameObject gl = GameObject.Find("Global"); globalObj = gl.GetComponent <Level1_Global>(); healthString = (globalObj.currentHealth) + "/" + (globalObj.maxHealth); staminaString = (int)(globalObj.currentStamina) + "/" + (globalObj.maxStamina); scoreString = globalObj.score + ""; healthBarLength = 100.0f * (float)((float)globalObj.currentHealth / (float)globalObj.maxHealth); staminaBarLength = 100.0f * (float)((float)globalObj.currentStamina / (float)globalObj.maxStamina); healthPUStored = globalObj.storedHealthPU; staminaPUstored = globalObj.storedStaminaPU; bubbleNum = globalObj.bubblesLeft; timer = globalObj.timer; int minutes = (int)(timer / 60); int seconds = (int)(timer % 60); timeString = string.Format("{0:00}:{1:00}", minutes, seconds); // Ensure that camera controller variables have been properly // initialized before we start reading them if (CameraController != null) { CameraController.InitCameraControllerVariables(); GuiHelper.SetCameraController(ref CameraController); } // Set the GUI target GUIRenderObject = GameObject.Instantiate(Resources.Load("OVRGUIObjectMain")) as GameObject; if (GUIRenderObject != null) { if (GUIRenderTexture == null) { int w = Screen.width; int h = Screen.height; if (CameraController.PortraitMode == true) { int t = h; h = w; w = t; } // We don't need a depth buffer on this texture GUIRenderTexture = new RenderTexture(w, h, 0); GuiHelper.SetPixelResolution(w, h); GuiHelper.SetDisplayResolution(OVRDevice.HResolution, OVRDevice.VResolution); } } // Attach GUI texture to GUI object and GUI object to Camera if (GUIRenderTexture != null && GUIRenderObject != null) { GUIRenderObject.renderer.material.mainTexture = GUIRenderTexture; if (CameraController != null) { // Grab transform of GUI object Transform t = GUIRenderObject.transform; // Attach the GUI object to the camera CameraController.AttachGameObjectToCamera(ref GUIRenderObject); // Reset the transform values (we will be maintaining state of the GUI object // in local state) OVRUtils.SetLocalTransform(ref GUIRenderObject, ref t); // Deactivate object until we have completed the fade-in // Also, we may want to deactive the render object if there is nothing being rendered // into the UI // we will move the position of everything over to the left, so get // IPD / 2 and position camera towards negative X Vector3 lp = GUIRenderObject.transform.localPosition; float ipd = 0.0f; CameraController.GetIPD(ref ipd); lp.x -= ipd * 0.5f; GUIRenderObject.transform.localPosition = lp; GUIRenderObject.SetActive(false); } } }
#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member /// <summary> /// Create a GearVR device /// </summary> public GearVRDevice() { Headset = OVRUtils.IsGearVRHeadset() ? new GearVRHeadset() : GenericHeadset(); OVRInput.Update(); UpdateConnectedControllers(); }
private void UpdateConnectedControllers() { var allControllers = new List <IVRInputDevice>(); var disconnectedList = new List <IVRInputDevice>(); var connectedList = new List <IVRInputDevice>(); var ctrlMask = OVRInput.GetConnectedControllers(); // NOTE: Controller tests here are in order of priority. Active hand controllers take priority over headset #region Controller var leftHandConnected = OVRUtils.IsLimbConnected(VRAvatarLimbType.LeftHand); var rightHandConnected = OVRUtils.IsLimbConnected(VRAvatarLimbType.RightHand); Debug.Log($"Left Hand Connected: {leftHandConnected}"); Debug.Log($"Right Hand Connected: {rightHandConnected}"); // The order the controllers are added currently determines the PrimaryInput however, // It does not seem to determine the primary pointer. if (rightHandConnected) { mPrimaryController = mPrimaryController ?? new GearVRController(VRInputDeviceHand.Right); if (!mInputDevices.Contains(mPrimaryController)) { connectedList.Add(mPrimaryController); } allControllers.Add(mPrimaryController); } else { disconnectedList.Add(mPrimaryController); } if (leftHandConnected) { mSecondaryController = mSecondaryController ?? new GearVRController(VRInputDeviceHand.Left); if (!mInputDevices.Contains(mSecondaryController)) { connectedList.Add(mSecondaryController); } allControllers.Add(mSecondaryController); } else { disconnectedList.Add(mSecondaryController); } #endregion #region Headset (Swipe-pad) if (Headset is GearVRHeadset) { var gearVRHeadset = Headset as GearVRHeadset; if ((ctrlMask & OVRInput.Controller.Touchpad) != 0) { if (!mHeadsetInputConnected) { connectedList.Add(gearVRHeadset); mHeadsetInputConnected = true; } allControllers.Add(gearVRHeadset); } else if (Headset != null) { disconnectedList.Add(gearVRHeadset); mHeadsetInputConnected = false; } } #endregion // Update internal state mInputDevices = allControllers.ToArray(); mConnectedControllerMask = ctrlMask; foreach (var device in disconnectedList) { InputDeviceDisconnected?.Invoke(this, device); } foreach (var device in connectedList) { InputDeviceConnected?.Invoke(this, device); } // Force an update of input devices UpdateInputDevices(); }
public GearVRController(VRInputDeviceHand hand) : base(OVRUtils.GetControllerType(hand)) { _hand = hand; }