public LeiaView(GameObject root, UnityCameraParams cameraParams) { this.Debug("ctor()"); var rootCamera = root.GetComponent <Camera>(); for (int i = 0; i < rootCamera.transform.childCount; i++) { var child = rootCamera.transform.GetChild(i); if (child.name == DISABLED_NAME) { child.name = ENABLED_NAME; child.hideFlags = HideFlags.None; _camera = child.GetComponent <Camera>(); _camera.enabled = true; #if UNITY_5_6_OR_NEWER _camera.allowHDR = cameraParams.AllowHDR; #else _camera.hdr = cameraParams.AllowHDR; #endif break; } } if (_camera == null) { _camera = new GameObject(ENABLED_NAME).AddComponent <Camera>(); } _camera.transform.parent = root.transform; _camera.transform.localPosition = Vector3.zero; _camera.transform.localRotation = Quaternion.identity; _camera.clearFlags = cameraParams.ClearFlags; _camera.cullingMask = cameraParams.CullingMask; _camera.depth = cameraParams.Depth; _camera.backgroundColor = cameraParams.BackgroundColor; _camera.fieldOfView = cameraParams.FieldOfView; _camera.depthTextureMode = DepthTextureMode.None; _camera.hideFlags = HideFlags.None; _camera.orthographic = cameraParams.Orthographic; _camera.orthographicSize = cameraParams.OrthographicSize; ViewRect = rootCamera.rect; #if UNITY_5_6_OR_NEWER _camera.allowHDR = cameraParams.AllowHDR; #else _camera.hdr = cameraParams.AllowHDR; #endif }
/// <summary> /// Asks LeiaDisplay to update all LeiaViews if required (if something changed in params) /// </summary> private void Update() { CheckMissingOrInactiveLeiaviews(); UnityCameraParams currentUnityCameraParams = GetUnityCameraParams(); bool camOrthoMatch = true; if (!currentUnityCameraParams.Equals(_previousUnityCameraParams)) { camOrthoMatch = _previousUnityCameraParams.Orthographic == currentUnityCameraParams.Orthographic; _previousUnityCameraParams = currentUnityCameraParams; _isDirty = true; UpdateRenderCameraDepth(); } if (Math.Abs(_convergenceDistance - _previousConvergenceDistance) > 1e-6) { _isDirty = true; _previousConvergenceDistance = _convergenceDistance; } if (Math.Abs(_disparityScaling - _previousDisparityScaling) > 1e-6) { _isDirty = true; _previousDisparityScaling = _disparityScaling; } if (_isDirty) { this.Debug("IsDirty detected"); LeiaDisplay.Instance.UpdateViews(this); // while most LeiaCamera properties require just a view update when a camera param changes, // when Camera switches ortho <-> perspective, this requires a LeiaState / interlacing update if (!camOrthoMatch) { LeiaDisplay.Instance.ForceLeiaStateUpdate(); } RefreshViewsParams(); _isDirty = false; } }
/// <summary> /// Gets parameters from root camera /// </summary> public void RefreshParameters(UnityCameraParams cameraParams) { if (IsCameraNull) { return; } _camera.clearFlags = cameraParams.ClearFlags; _camera.cullingMask = cameraParams.CullingMask; _camera.depth = cameraParams.Depth; _camera.backgroundColor = cameraParams.BackgroundColor; _camera.orthographic = cameraParams.Orthographic; _camera.orthographicSize = cameraParams.OrthographicSize; _camera.fieldOfView = cameraParams.FieldOfView; ViewRect = cameraParams.ViewportRect; #if UNITY_5_6_OR_NEWER _camera.allowHDR = cameraParams.AllowHDR; #else _camera.hdr = cameraParams.AllowHDR; #endif _camera.renderingPath = cameraParams.RenderingPath; }
/// <summary> /// Memorize previous parameters, subscribe to LeiaDisplay's StateChanged event /// </summary> private void Awake() { _camera = GetComponent <Camera>(); _previousUnityCameraParams = GetUnityCameraParams(); if (Instance == null) { Instance = this; } LeiaDisplay.Instance.StateChanged -= OnStateChanged; LeiaDisplay.Instance.StateChanged += OnStateChanged; _camera.enabled = false; if (_renderObject == null) { CreateRenderObject(); UpdateRenderCameraDepth(); } }