private void SceneManagerOnActiveSceneChanged(Scene arg0, Scene scene) { var pointer = Resources.FindObjectsOfTypeAll <VRPointer>().FirstOrDefault(); if (pointer == null) { return; } ReflectionUtil.CopyComponent(pointer, typeof(CameraMoverPointer), pointer.gameObject); DestroyImmediate(pointer); }
private void Awake() { SceneManager.activeSceneChanged += SceneManagerOnActiveSceneChanged; SceneManagerOnActiveSceneChanged(new Scene(), new Scene()); GameObject newCameraObject = Instantiate(MainCamera.gameObject); newCameraObject.SetActive(false); newCameraObject.name = "Camera Plus"; newCameraObject.tag = "Untagged"; while (newCameraObject.transform.childCount > 0) { DestroyImmediate(newCameraObject.transform.GetChild(0).gameObject); } DestroyImmediate(newCameraObject.GetComponent("CameraRenderCallbacksManager")); DestroyImmediate(newCameraObject.GetComponent("AudioListener")); DestroyImmediate(newCameraObject.GetComponent("MeshCollider")); if (SteamVRCompatibility.IsAvailable) { DestroyImmediate(newCameraObject.GetComponent(SteamVRCompatibility.SteamVRCamera)); DestroyImmediate(newCameraObject.GetComponent(SteamVRCompatibility.SteamVRFade)); } _cameraComp = newCameraObject.GetComponent <Camera>(); _cameraComp.stereoTargetEye = StereoTargetEyeMask.None; _cameraComp.targetTexture = null; _cameraComp.depth += 100; newCameraObject.SetActive(true); Transform cameraTransform = MainCamera.transform; transform.position = cameraTransform.position; transform.rotation = cameraTransform.rotation; newCameraObject.transform.parent = transform; newCameraObject.transform.localPosition = Vector3.zero; newCameraObject.transform.localRotation = Quaternion.identity; newCameraObject.transform.localScale = Vector3.one; var cameraCube = GameObject.CreatePrimitive(PrimitiveType.Cube); cameraCube.SetActive(ThirdPerson); _cameraCube = cameraCube.transform; _cameraCube.localScale = new Vector3(0.15f, 0.15f, 0.22f); _cameraCube.name = "CameraCube"; ReadIni(); if (m_UsePreviewCamera) { _previewCam = Instantiate(_cameraComp.gameObject, _cameraCube).GetComponent <Camera>(); if (_renderTexture == null && _previewMaterial == null) { _renderTexture = new RenderTexture(Width, (int)(Width / _cameraComp.aspect), 24); _previewMaterial = new Material(Shader.Find("Hidden/BlitCopyWithDepth")); _previewMaterial.SetTexture("_MainTex", _renderTexture); } _previewCam.targetTexture = _renderTexture; var quad = GameObject.CreatePrimitive(PrimitiveType.Quad); DestroyImmediate(quad.GetComponent <Collider>()); quad.GetComponent <MeshRenderer>().material = _previewMaterial; quad.transform.parent = _cameraCube; quad.transform.localPosition = new Vector3(-1f * ((_cameraComp.aspect - 1) / 2 + 1), 0, 0.22f); quad.transform.localEulerAngles = new Vector3(0, 180, 0); quad.transform.localScale = new Vector3(-1 * _cameraComp.aspect, 1, 1); } if (m_MoveCameraInGame) { var pointer = Resources.FindObjectsOfTypeAll <VRPointer>().FirstOrDefault(); if (pointer == null) { return; } ReflectionUtil.CopyComponent(pointer, typeof(CameraMoverPointer), pointer.gameObject); DestroyImmediate(pointer); } }