// Helper to copy camera settings from the controller's mono camera. // Used in OnPreCull and the custom editor for StereoController. // The parameters parx and pary, if not left at default, should come from a // projection matrix returned by the SDK. // They affect the apparent depth of the camera's window. See OnPreCull(). public void CopyCameraAndMakeSideBySide(StereoController controller, float parx = 0, float pary = 0) { var camera = GetComponent <Camera>(); // Sync the camera properties. camera.CopyFrom(controller.GetComponent <Camera>()); // Reset transform, which was clobbered by the CopyFrom() call. // Since we are a child of the mono camera, we inherit its // transform already. // Use nominal IPD for the editor. During play, OnPreCull() will // compute a real value. float ipd = Cardboard.NOMINAL_IPD * controller.stereoMultiplier; transform.localPosition = (eye == Cardboard.Eye.Left ? -ipd / 2 : ipd / 2) * Vector3.right; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; // Set up side-by-side stereo. // Note: The code is written this way so that non-fullscreen cameras // (PIP: picture-in-picture) still work in stereo. Even if the PIP's content is // not going to be in stereo, the PIP itself still has to be rendered in both eyes. Rect rect = camera.rect; // Move away from edges if padding requested. Some HMDs make the edges of the // screen a bit hard to see. Vector2 center = rect.center; center.x = Mathf.Lerp(center.x, 0.5f, Mathf.Clamp01(controller.stereoPaddingX)); center.y = Mathf.Lerp(center.y, 0.5f, Mathf.Clamp01(controller.stereoPaddingY)); rect.center = center; // Semi-hacky aspect ratio adjustment because the screen is only half as wide due // to side-by-side stereo, to make sure the PIP width fits. float width = Mathf.SmoothStep(-0.5f, 0.5f, (rect.width + 1) / 2); rect.x += (rect.width - width) / 2; rect.width = width; // Divide the outside region of window proportionally in each half of the screen. rect.x *= (0.5f - rect.width) / (1 - rect.width); if (eye == Cardboard.Eye.Right) { rect.x += 0.5f; // Move to right half of the screen. } // Adjust the window for requested parallax. This affects the apparent depth of the // window in the main camera's screen. Useful for PIP windows only, where rect.width < 1. float parallax = Mathf.Clamp01(controller.screenParallax); if (controller.GetComponent <Camera>().rect.width < 1 && parallax > 0) { // Note: parx and pary are signed, with opposite signs in each eye. rect.x -= parx / 4 * parallax; // Extra factor of 1/2 because of side-by-side stereo. rect.y -= pary / 2 * parallax; } camera.rect = rect; }
public void Start() { cardboard = gameObject.GetComponent <CardboardControl>(); StereoController stereoController = Camera.main.GetComponent <StereoController>(); head = stereoController.Head; }
void Start() { var eye = GetComponent<CardboardEye>(); if (eye != null) { controller = eye.Controller; } }
private void ModifyCamera(GameObject cameraObject) { // Select the camera object in the editor. Selection.activeObject = cameraObject; // Register object for undo. //Undo.RegisterCompleteObjectUndo(cameraObject, "Added Cardboard support"); // Attempt finding existing controller. StereoController stereoController = cameraObject.GetComponent <StereoController>(); // Otherwise, if (stereoController == null) { // Add a stereo controller. stereoController = cameraObject.AddComponent <StereoController>(); } // Add the stereo setup. stereoController.AddStereoRig(); // Add reticle support. AddReticleSupport(cameraObject); }
public void ResetZoom() { GameObject mCamera = GameObject.FindGameObjectWithTag("MainCamera"); StereoController sCon = mCamera.GetComponent <StereoController> (); sCon.matchMonoFOV = 0; }
void Start() { var eye = GetComponent <CardboardEye>(); if (eye != null) { controller = eye.Controller; } }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("CardboardEye must be child of a StereoController."); enabled = false; } // Save reference to the found controller. controller = ctlr; }
// Helper to copy camera settings from the controller's mono camera. // Used in OnPreCull and the custom editor for StereoController. // The parameters parx and pary, if not left at default, should come from a // projection matrix returned by the SDK. // They affect the apparent depth of the camera's window. See OnPreCull(). public void CopyCameraAndMakeSideBySide(StereoController controller, float parx = 0, float pary = 0) { var camera = GetComponent<Camera>(); // Sync the camera properties. camera.CopyFrom(controller.GetComponent<Camera>()); camera.cullingMask ^= toggleCullingMask.value; // Reset transform, which was clobbered by the CopyFrom() call. // Since we are a child of the mono camera, we inherit its // transform already. // Use nominal IPD for the editor. During play, OnPreCull() will // compute a real value. float ipd = CardboardProfile.Default.device.lenses.separation * controller.stereoMultiplier; transform.localPosition = (eye == Cardboard.Eye.Left ? -ipd/2 : ipd/2) * Vector3.right; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; // Set up side-by-side stereo. // Note: The code is written this way so that non-fullscreen cameras // (PIP: picture-in-picture) still work in stereo. Even if the PIP's content is // not going to be in stereo, the PIP itself still has to be rendered in both eyes. Rect rect = camera.rect; // Move away from edges if padding requested. Some HMDs make the edges of the // screen a bit hard to see. Vector2 center = rect.center; center.x = Mathf.Lerp(center.x, 0.5f, Mathf.Clamp01(controller.stereoPaddingX)); center.y = Mathf.Lerp(center.y, 0.5f, Mathf.Clamp01(controller.stereoPaddingY)); rect.center = center; // Semi-hacky aspect ratio adjustment because the screen is only half as wide due // to side-by-side stereo, to make sure the PIP width fits. float width = Mathf.SmoothStep(-0.5f, 0.5f, (rect.width + 1) / 2); rect.x += (rect.width - width) / 2; rect.width = width; // Divide the outside region of window proportionally in each half of the screen. rect.x *= (0.5f - rect.width) / (1 - rect.width); if (eye == Cardboard.Eye.Right) { rect.x += 0.5f; // Move to right half of the screen. } // Adjust the window for requested parallax. This affects the apparent depth of the // window in the main camera's screen. Useful for PIP windows only, where rect.width < 1. float parallax = Mathf.Clamp01(controller.screenParallax); if (controller.GetComponent<Camera>().rect.width < 1 && parallax > 0) { // Note: parx and pary are signed, with opposite signs in each eye. rect.x -= parx / 4 * parallax; // Extra factor of 1/2 because of side-by-side stereo. rect.y -= pary / 2 * parallax; } camera.rect = rect; }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("CardboardEye must be child of a StereoController."); enabled = false; } // Save reference to the found controller. controller = ctlr; }
void LateUpdate() { StereoController controller = Cardboard.Controller; CardboardHead head = controller ? controller.Head : null; if (head == null) // Pointer not being controlled by user's head, so we bail. { pointerVisible = true; // Draw pointer wherever Unity thinks the mouse is. return; } if (!CardboardOnGUI.IsGUIVisible) { pointerVisible = false; // No GUI == no pointer to worry about. return; } // Find which CardboardOnGUIWindow the user's gaze intersects first, if any. Ray ray = head.Gaze; CardboardOnGUIWindow hitWindow = null; float minDist = Mathf.Infinity; Vector2 pos = Vector2.zero; foreach (var guiWindow in GetComponentsInChildren <CardboardOnGUIWindow>()) { RaycastHit hit; if (guiWindow.GetComponent <Collider>().Raycast(ray, out hit, Mathf.Infinity) && hit.distance < minDist) { minDist = hit.distance; hitWindow = guiWindow; pos = hit.textureCoord; } } if (hitWindow == null) { // Don't draw the pointer unless the user is looking at a pixel of the GUI screen. pointerVisible = false; return; } // Convert from the intersected window's texture coordinates to screen coordinates. pos.x = hitWindow.rect.xMin + hitWindow.rect.width * pos.x; pos.y = hitWindow.rect.yMin + hitWindow.rect.height * pos.y; pointerX = (int)(pos.x * Screen.width); pointerY = (int)(pos.y * Screen.height); // Move the mouse/touch point to the determined screen point. // Unity GUI Y-coordinates ascend top-to-bottom, as do the quad's texture coordinates, // while screen Y-coordinates ascend bottom-to-top. Cardboard.SDK.SetTouchCoordinates(pointerX, Screen.height - pointerY); // OK to draw the pointer image. pointerVisible = true; }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("CardboardEye must be child of a StereoController."); enabled = false; return; } // Save reference to the found controller and it's camera. controller = ctlr; monoCamera = controller.GetComponent <Camera>(); UpdateStereoValues(); }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("GvrEye must be child of a StereoController."); enabled = false; return; } // Save reference to the found controller and it's camera. controller = ctlr; monoCamera = controller.GetComponent <Camera>(); SetupStereo(/*forceUpdate=*/ true); }
// Use this for initialization void Start() { if (StereoController3D == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { StereoController sc = mcTransform.GetComponent <StereoController> (); if (sc != null) { StereoController3D = sc; } } } } if (StereoController3D == null) { Debug.LogError("找不到StereoController3D"); } if (LookCamera == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { LookCamera = mcTransform.GetComponent <Camera>(); } } } if (LookCamera == null) { Debug.LogError("找不到Camera3D"); } //SetGazedAt(false); Color notForceColor = CanControl ? CanControlColor : DontControlColor; GetComponent <Renderer>().material.color = notForceColor; DebugSystem.AddLogSystem(SystemName); }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("CardboardEye must be child of a StereoController."); enabled = false; } // Save reference to the found controller. controller = ctlr; // Add an image effect when playing in the editor to preview the distortion correction, since // native distortion corrrection is only available on the phone. if (Application.isEditor && Application.isPlaying && Cardboard.SDK.nativeDistortionCorrection && SystemInfo.supportsRenderTextures) { var effect = GetComponent<RadialUndistortionEffect>(); if (effect == null) { effect = gameObject.AddComponent<RadialUndistortionEffect>(); } } }
// Use this for initialization void Start () { if (StereoController3D == null) { GameObject cardboard3dGo = GameObject.Find ("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild ("Head/Main Camera"); if (mcTransform != null) { StereoController sc = mcTransform.GetComponent<StereoController> (); if (sc != null) { StereoController3D = sc; } } } } if (StereoController3D == null) { Debug.LogError ("找不到StereoController3D"); } if (LookCamera == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { LookCamera = mcTransform.GetComponent<Camera>(); } } } if (LookCamera == null) { Debug.LogError("找不到Camera3D"); } //SetGazedAt(false); Color notForceColor = CanControl ? CanControlColor : DontControlColor; GetComponent<Renderer>().material.color = notForceColor; DebugSystem.AddLogSystem (SystemName); }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("GvrEye must be child of a StereoController."); enabled = false; return; } // Save reference to the found controller and it's camera. controller = ctlr; monoCamera = controller.GetComponent <Camera>(); SetupStereo(/*forceUpdate=*/ true); //disable stereo effect default stereoEffect = GetComponent <StereoRenderEffect>(); if (stereoEffect) { stereoEffect.enabled = false; } }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("CardboardEye must be child of a StereoController."); enabled = false; } // Save reference to the found controller. controller = ctlr; // Add an image effect when playing in the editor to preview the distortion correction, since // native distortion corrrection is only available on the phone. if (Application.isPlaying && !Cardboard.SDK.NativeDistortionCorrectionSupported && SystemInfo.supportsRenderTextures) { var effect = GetComponent <RadialUndistortionEffect>(); if (effect == null) { effect = gameObject.AddComponent <RadialUndistortionEffect>(); } } }
void Awake() { instance = this; controller = GetComponent <StereoController>(); }
/// Helper to copy camera settings from the controller's mono camera. Used in SetupStereo() and /// in the custom editor for StereoController. The parameters parx and pary, if not left at /// default, should come from a projection matrix returned by the SDK. They affect the apparent /// depth of the camera's window. See SetupStereo(). public void CopyCameraAndMakeSideBySide(StereoController controller, float parx = 0, float pary = 0) { #if UNITY_EDITOR // Member variable 'cam' not always initialized when this method called in Editor. // So, we'll just make a local of the same name. var cam = GetComponent <Camera>(); #endif // Same for controller's camera, but it can happen at runtime too (via AddStereoRig on // StereoController). var monoCamera = controller == this.controller ? this.monoCamera : controller.GetComponent <Camera>(); float ipd = CardboardProfile.Default.device.lenses.separation * controller.stereoMultiplier; Vector3 localPosition = Application.isPlaying ? transform.localPosition : (eye == Cardboard.Eye.Left ? -ipd / 2 : ipd / 2) * Vector3.right;; // Sync the camera properties. cam.CopyFrom(monoCamera); cam.cullingMask ^= toggleCullingMask.value; // Not sure why we have to do this, but if we don't then switching between drawing to // the main screen or to the stereo rendertexture acts very strangely. cam.depth = monoCamera.depth; // Reset transform, which was clobbered by the CopyFrom() call. // Since we are a child of the mono camera, we inherit its transform already. transform.localPosition = localPosition; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; Skybox monoCameraSkybox = monoCamera.GetComponent <Skybox>(); Skybox customSkybox = GetComponent <Skybox>(); if (monoCameraSkybox != null) { if (customSkybox == null) { customSkybox = gameObject.AddComponent <Skybox>(); } customSkybox.material = monoCameraSkybox.material; } else if (customSkybox != null) { Destroy(customSkybox); } // Set up side-by-side stereo. // Note: The code is written this way so that non-fullscreen cameras // (PIP: picture-in-picture) still work in stereo. Even if the PIP's content is // not going to be in stereo, the PIP itself still has to be rendered in both eyes. Rect rect = cam.rect; // Move away from edges if padding requested. Some HMDs make the edges of the // screen a bit hard to see. Vector2 center = rect.center; center.x = Mathf.Lerp(center.x, 0.5f, Mathf.Clamp01(controller.stereoPaddingX)); center.y = Mathf.Lerp(center.y, 0.5f, Mathf.Clamp01(controller.stereoPaddingY)); rect.center = center; // Semi-hacky aspect ratio adjustment because the screen is only half as wide due // to side-by-side stereo, to make sure the PIP width fits. float width = Mathf.SmoothStep(-0.5f, 0.5f, (rect.width + 1) / 2); rect.x += (rect.width - width) / 2; rect.width = width; // Divide the outside region of window proportionally in each half of the screen. rect.x *= (0.5f - rect.width) / (1 - rect.width); if (eye == Cardboard.Eye.Right) { rect.x += 0.5f; // Move to right half of the screen. } // Adjust the window for requested parallax. This affects the apparent depth of the // window in the main camera's screen. Useful for PIP windows only, where rect.width < 1. float parallax = Mathf.Clamp01(controller.screenParallax); if (monoCamera.rect.width < 1 && parallax > 0) { // Note: parx and pary are signed, with opposite signs in each eye. rect.x -= parx / 4 * parallax; // Extra factor of 1/2 because of side-by-side stereo. rect.y -= pary / 2 * parallax; } cam.rect = rect; }
// Use this for initialization void Start() { try { GameObject uiGO = GameObject.Find("UI"); if(uiGO!=null) { UICreator uic = uiGO.GetComponent<UICreator>(); if(uic!=null) { creator = uic; } } } catch(System.Exception e) { } if (StereoController3D == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { StereoController sc = mcTransform.GetComponent<StereoController>(); if (sc != null) { StereoController3D = sc; } } } } if (StereoController3D == null) { Debug.LogError("找不到StereoController3D"); } if (LookCamera == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { LookCamera = mcTransform.GetComponent<Camera>(); } } } if (LookCamera == null) { Debug.LogError("找不到Camera3D"); } //SetGazedAt(false); // Color notForceColor = CanControl ? CanControlColor : DontControlColor; // GetComponent<Renderer>().material.color = notForceColor; DebugSystem.AddLogSystem(SystemName); }
// Use this for initialization void Start () { if (DebugInfoText == null) { GameObject debugPanelGo = GameObject.Find ("DebugInfoPanel"); if (debugPanelGo != null) { Transform debugTextTransform = debugPanelGo.transform.FindChild ("Info"); if (debugTextTransform != null) { Text logtext = debugTextTransform.GetComponent<Text> (); if (logtext != null) { DebugInfoText = logtext; } } } } if (DebugInfoText == null) Debug.LogError ("無法找到顯示訊息物件"); if (DebugFovText == null) { GameObject debugPanelGo = GameObject.Find ("DebugInfoPanel"); if (debugPanelGo != null) { Transform debugTextTransform = debugPanelGo.transform.FindChild ("Fov"); if (debugTextTransform != null) { Text logtext = debugTextTransform.GetComponent<Text> (); if (logtext != null) { DebugFovText = logtext; } } } } if (DebugFovText == null) Debug.LogError ("無法找到顯示鏡頭焦距訊息物件"); if (StereoController3D == null) { GameObject cardboard3dGo = GameObject.Find ("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild ("Head/Main Camera"); if (mcTransform != null) { StereoController sc = mcTransform.GetComponent<StereoController> (); if (sc != null) { StereoController3D = sc; } } } } if (StereoController3D == null) { Debug.LogError ("找不到StereoController3D"); } }
// Use this for initialization void Start() { if (DebugInfoText == null) { GameObject debugPanelGo = GameObject.Find("DebugInfoPanel"); if (debugPanelGo != null) { Transform debugTextTransform = debugPanelGo.transform.FindChild("Info"); if (debugTextTransform != null) { Text logtext = debugTextTransform.GetComponent <Text> (); if (logtext != null) { DebugInfoText = logtext; } } } } if (DebugInfoText == null) { Debug.LogError("無法找到顯示訊息物件"); } if (DebugFovText == null) { GameObject debugPanelGo = GameObject.Find("DebugInfoPanel"); if (debugPanelGo != null) { Transform debugTextTransform = debugPanelGo.transform.FindChild("Fov"); if (debugTextTransform != null) { Text logtext = debugTextTransform.GetComponent <Text> (); if (logtext != null) { DebugFovText = logtext; } } } } if (DebugFovText == null) { Debug.LogError("無法找到顯示鏡頭焦距訊息物件"); } if (StereoController3D == null) { GameObject cardboard3dGo = GameObject.Find("CardboardMain 3D"); if (cardboard3dGo != null) { Transform mcTransform = cardboard3dGo.transform.FindChild("Head/Main Camera"); if (mcTransform != null) { StereoController sc = mcTransform.GetComponent <StereoController> (); if (sc != null) { StereoController3D = sc; } } } } if (StereoController3D == null) { Debug.LogError("找不到StereoController3D"); } }
void Awake() { instance = this; controller = GetComponent<StereoController>(); }
/// Helper to copy camera settings from the controller's mono camera. Used in SetupStereo() and /// in the custom editor for StereoController. The parameters parx and pary, if not left at /// default, should come from a projection matrix returned by the SDK. They affect the apparent /// depth of the camera's window. See SetupStereo(). public void CopyCameraAndMakeSideBySide(StereoController controller, float parx = 0, float pary = 0) { #if UNITY_EDITOR // Member variable 'cam' not always initialized when this method called in Editor. // So, we'll just make a local of the same name. var cam = GetComponent<Camera>(); #endif // Same for controller's camera, but it can happen at runtime too (via AddStereoRig on // StereoController). var monoCamera = controller == this.controller ? this.monoCamera : controller.GetComponent<Camera>(); float ipd = GvrProfile.Default.viewer.lenses.separation * controller.stereoMultiplier; Vector3 localPosition = Application.isPlaying ? transform.localPosition : (eye == GvrViewer.Eye.Left ? -ipd/2 : ipd/2) * Vector3.right;; // Sync the camera properties. cam.CopyFrom(monoCamera); cam.cullingMask ^= toggleCullingMask.value; // Not sure why we have to do this, but if we don't then switching between drawing to // the main screen or to the stereo rendertexture acts very strangely. cam.depth = monoCamera.depth; // Reset transform, which was clobbered by the CopyFrom() call. // Since we are a child of the mono camera, we inherit its transform already. transform.localPosition = localPosition; transform.localRotation = Quaternion.identity; transform.localScale = Vector3.one; Skybox monoCameraSkybox = monoCamera.GetComponent<Skybox>(); Skybox customSkybox = GetComponent<Skybox>(); if(monoCameraSkybox != null) { if (customSkybox == null) { customSkybox = gameObject.AddComponent<Skybox>(); } customSkybox.material = monoCameraSkybox.material; } else if (customSkybox != null) { Destroy(customSkybox); } // Set up side-by-side stereo. // Note: The code is written this way so that non-fullscreen cameras // (PIP: picture-in-picture) still work in stereo. Even if the PIP's content is // not going to be in stereo, the PIP itself still has to be rendered in both eyes. Rect rect = cam.rect; // Move away from edges if padding requested. Some HMDs make the edges of the // screen a bit hard to see. Vector2 center = rect.center; center.x = Mathf.Lerp(center.x, 0.5f, Mathf.Clamp01(controller.stereoPaddingX)); center.y = Mathf.Lerp(center.y, 0.5f, Mathf.Clamp01(controller.stereoPaddingY)); rect.center = center; // Semi-hacky aspect ratio adjustment because the screen is only half as wide due // to side-by-side stereo, to make sure the PIP width fits. float width = Mathf.SmoothStep(-0.5f, 0.5f, (rect.width + 1) / 2); rect.x += (rect.width - width) / 2; rect.width = width; // Divide the outside region of window proportionally in each half of the screen. rect.x *= (0.5f - rect.width) / (1 - rect.width); if (eye == GvrViewer.Eye.Right) { rect.x += 0.5f; // Move to right half of the screen. } // Adjust the window for requested parallax. This affects the apparent depth of the // window in the main camera's screen. Useful for PIP windows only, where rect.width < 1. float parallax = Mathf.Clamp01(controller.screenParallax); if (monoCamera.rect.width < 1 && parallax > 0) { // Note: parx and pary are signed, with opposite signs in each eye. rect.x -= parx / 4 * parallax; // Extra factor of 1/2 because of side-by-side stereo. rect.y -= pary / 2 * parallax; } cam.rect = rect; }
public void Start() { StereoController stereoController = Camera.main.GetComponent <StereoController>(); head = stereoController.Head; }
void Start() { var ctlr = Controller; if (ctlr == null) { Debug.LogError("GvrEye must be child of a StereoController."); enabled = false; return; } // Save reference to the found controller and it's camera. controller = ctlr; monoCamera = controller.GetComponent<Camera>(); UpdateStereoValues(); }
// Start is called before the first frame update void Start() { stereo = FindObjectOfType <StereoController>(); }