GetMainGameViewTargetSize() static private method

static private GetMainGameViewTargetSize ( ) : Vector2
return Vector2
Beispiel #1
0
 public virtual void OnOverlayGUI(UnityEngine.Object target, SceneView sceneView)
 {
     if (!(target == null))
     {
         Camera  camera = (Camera)target;
         Vector2 mainGameViewTargetSize = GameView.GetMainGameViewTargetSize();
         if (mainGameViewTargetSize.x < 0f)
         {
             mainGameViewTargetSize.x = sceneView.position.width;
             mainGameViewTargetSize.y = sceneView.position.height;
         }
         Rect rect = camera.rect;
         mainGameViewTargetSize.x *= Mathf.Max(rect.width, 0f);
         mainGameViewTargetSize.y *= Mathf.Max(rect.height, 0f);
         if (mainGameViewTargetSize.x > 0f && mainGameViewTargetSize.y > 0f)
         {
             float num = mainGameViewTargetSize.x / mainGameViewTargetSize.y;
             mainGameViewTargetSize.y = 0.2f * sceneView.position.height;
             mainGameViewTargetSize.x = mainGameViewTargetSize.y * num;
             if (mainGameViewTargetSize.y > sceneView.position.height * 0.5f)
             {
                 mainGameViewTargetSize.y = sceneView.position.height * 0.5f;
                 mainGameViewTargetSize.x = mainGameViewTargetSize.y * num;
             }
             if (mainGameViewTargetSize.x > sceneView.position.width * 0.5f)
             {
                 mainGameViewTargetSize.x = sceneView.position.width * 0.5f;
                 mainGameViewTargetSize.y = mainGameViewTargetSize.x / num;
             }
             Rect rect2 = GUILayoutUtility.GetRect(mainGameViewTargetSize.x, mainGameViewTargetSize.y);
             if (Event.current.type == EventType.Repaint)
             {
                 this.previewCamera.CopyFrom(camera);
                 Skybox component = this.previewCamera.GetComponent <Skybox>();
                 if (component)
                 {
                     Skybox component2 = camera.GetComponent <Skybox>();
                     if (component2 && component2.enabled)
                     {
                         component.enabled  = true;
                         component.material = component2.material;
                     }
                     else
                     {
                         component.enabled = false;
                     }
                 }
                 RenderTexture previewTextureWithSize = this.GetPreviewTextureWithSize((int)rect2.width, (int)rect2.height);
                 previewTextureWithSize.antiAliasing = QualitySettings.antiAliasing;
                 this.previewCamera.targetTexture    = previewTextureWithSize;
                 this.previewCamera.pixelRect        = new Rect(0f, 0f, rect2.width, rect2.height);
                 Handles.EmitGUIGeometryForCamera(camera, this.previewCamera);
                 GL.sRGBWrite = (QualitySettings.activeColorSpace == ColorSpace.Linear);
                 this.previewCamera.Render();
                 GL.sRGBWrite = false;
                 Graphics.DrawTexture(rect2, previewTextureWithSize, new Rect(0f, 0f, 1f, 1f), 0, 0, 0, 0, GUI.color, EditorGUIUtility.GUITextureBlit2SRGBMaterial);
             }
         }
     }
 }
        public virtual void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }
            var c = (Camera)target;

            if (!CameraEditorUtils.IsViewportRectValidToRender(c.rect))
            {
                return;
            }

            Vector2 currentMainGameViewTargetSize = GameView.GetMainGameViewTargetSize();

            if (s_PreviousMainGameViewTargetSize != currentMainGameViewTargetSize)
            {
                // a gameView size change can affect horizontal FOV, refresh the inspector when that happens.
                Repaint();
                s_PreviousMainGameViewTargetSize = currentMainGameViewTargetSize;
            }
            SceneViewOverlay.Window(EditorGUIUtility.TrTextContent("Camera Preview"), OnOverlayGUI, (int)SceneViewOverlay.Ordering.Camera, target, SceneViewOverlay.WindowDisplayOption.OneWindowPerTarget);

            CameraEditorUtils.HandleFrustum(c, referenceTargetIndex);
        }
Beispiel #3
0
 public void OnOverlayGUI(UnityEngine.Object target, SceneView sceneView)
 {
     if (!(target == null))
     {
         Camera  camera = (Camera)target;
         Vector2 mainGameViewTargetSize = GameView.GetMainGameViewTargetSize();
         if (mainGameViewTargetSize.x < 0f)
         {
             mainGameViewTargetSize.x = sceneView.position.width;
             mainGameViewTargetSize.y = sceneView.position.height;
         }
         Rect rect = camera.rect;
         mainGameViewTargetSize.x *= Mathf.Max(rect.width, 0f);
         mainGameViewTargetSize.y *= Mathf.Max(rect.height, 0f);
         if (mainGameViewTargetSize.x > 0f && mainGameViewTargetSize.y > 0f)
         {
             float num = mainGameViewTargetSize.x / mainGameViewTargetSize.y;
             mainGameViewTargetSize.y = 0.2f * sceneView.position.height;
             mainGameViewTargetSize.x = mainGameViewTargetSize.y * num;
             if (mainGameViewTargetSize.y > sceneView.position.height * 0.5f)
             {
                 mainGameViewTargetSize.y = sceneView.position.height * 0.5f;
                 mainGameViewTargetSize.x = mainGameViewTargetSize.y * num;
             }
             if (mainGameViewTargetSize.x > sceneView.position.width * 0.5f)
             {
                 mainGameViewTargetSize.x = sceneView.position.width * 0.5f;
                 mainGameViewTargetSize.y = mainGameViewTargetSize.x / num;
             }
             Rect rect2 = GUILayoutUtility.GetRect(mainGameViewTargetSize.x, mainGameViewTargetSize.y);
             rect2   = EditorGUIUtility.PointsToPixels(rect2);
             rect2.y = (sceneView.position.height + 1f) * EditorGUIUtility.pixelsPerPoint - rect2.y - rect2.height;
             if (Event.current.type == EventType.Repaint)
             {
                 this.previewCamera.CopyFrom(camera);
                 Skybox component = this.previewCamera.GetComponent <Skybox>();
                 if (component)
                 {
                     Skybox component2 = camera.GetComponent <Skybox>();
                     if (component2 && component2.enabled)
                     {
                         component.enabled  = true;
                         component.material = component2.material;
                     }
                     else
                     {
                         component.enabled = false;
                     }
                 }
                 this.previewCamera.targetTexture = null;
                 this.previewCamera.pixelRect     = rect2;
                 Handles.EmitGUIGeometryForCamera(camera, this.previewCamera);
                 this.previewCamera.Render();
             }
         }
     }
 }
Beispiel #4
0
        private static float GetGameViewAspectRatio()
        {
            Vector2 mainGameViewTargetSize = GameView.GetMainGameViewTargetSize();

            if (mainGameViewTargetSize.x < 0f)
            {
                mainGameViewTargetSize.x = (float)Screen.width;
                mainGameViewTargetSize.y = (float)Screen.height;
            }
            return(mainGameViewTargetSize.x / mainGameViewTargetSize.y);
        }
        internal static float GetGameViewAspectRatio()
        {
            Vector2 gameViewSize = GameView.GetMainGameViewTargetSize();

            if (gameViewSize.x < 0f)
            {
                // Fallback to Scene View of not a valid game view size
                gameViewSize.x = Screen.width;
                gameViewSize.y = Screen.height;
            }

            return(gameViewSize.x / gameViewSize.y);
        }
Beispiel #6
0
 private static void GetMainGameViewTargetSizeNoBox(out Vector2 result)
 {
     result = GameView.GetMainGameViewTargetSize();
 }
Beispiel #7
0
 internal static Vector2 GetSizeOfMainGameView()
 {
     return(GameView.GetMainGameViewTargetSize());
 }
        public virtual void OnOverlayGUI(Object target, SceneView sceneView)
        {
            if (target == null)
            {
                return;
            }

            // cache some deep values
            var c = (Camera)target;

            Vector2 previewSize = c.targetTexture ? new Vector2(c.targetTexture.width, c.targetTexture.height) : GameView.GetMainGameViewTargetSize();

            if (previewSize.x < 0f)
            {
                // Fallback to Scene View of not a valid game view size
                previewSize.x = sceneView.position.width;
                previewSize.y = sceneView.position.height;
            }

            // Apply normalizedviewport rect of camera
            Rect normalizedViewPortRect = c.rect;

            previewSize.x *= Mathf.Max(normalizedViewPortRect.width, 0f);
            previewSize.y *= Mathf.Max(normalizedViewPortRect.height, 0f);

            // Prevent using invalid previewSize
            if (previewSize.x < 1f || previewSize.y < 1f)
            {
                return;
            }

            float aspect = previewSize.x / previewSize.y;

            // Scale down (fit to scene view)
            previewSize.y = kPreviewNormalizedSize * sceneView.position.height;
            previewSize.x = previewSize.y * aspect;
            if (previewSize.y > sceneView.position.height * 0.5f)
            {
                previewSize.y = sceneView.position.height * 0.5f;
                previewSize.x = previewSize.y * aspect;
            }
            if (previewSize.x > sceneView.position.width * 0.5f)
            {
                previewSize.x = sceneView.position.width * 0.5f;
                previewSize.y = previewSize.x / aspect;
            }

            // Get and reserve rect
            Rect cameraRect = GUILayoutUtility.GetRect(previewSize.x, previewSize.y);

            if (Event.current.type == EventType.Repaint)
            {
                // setup camera and render
                previewCamera.CopyFrom(c);
                // also make sure to sync any Skybox component on the preview camera
                var dstSkybox = previewCamera.GetComponent <Skybox>();
                if (dstSkybox)
                {
                    var srcSkybox = c.GetComponent <Skybox>();
                    if (srcSkybox && srcSkybox.enabled)
                    {
                        dstSkybox.enabled  = true;
                        dstSkybox.material = srcSkybox.material;
                    }
                    else
                    {
                        dstSkybox.enabled = false;
                    }
                }


                var previewTexture = GetPreviewTextureWithSize((int)cameraRect.width, (int)cameraRect.height);
                previewTexture.antiAliasing = Mathf.Max(1, QualitySettings.antiAliasing);
                previewCamera.targetTexture = previewTexture;
                previewCamera.pixelRect     = new Rect(0, 0, cameraRect.width, cameraRect.height);

                Handles.EmitGUIGeometryForCamera(c, previewCamera);

                GL.sRGBWrite = QualitySettings.activeColorSpace == ColorSpace.Linear;

                if (c.usePhysicalProperties)
                {
                    // when sensor size is reduced, the previous frame is still visible behing so we need to clear the texture before rendering.
                    RenderTexture rt = RenderTexture.active;
                    RenderTexture.active = previewTexture;
                    GL.Clear(false, true, Color.clear);
                    RenderTexture.active = rt;
                }

                previewCamera.Render();
                GL.sRGBWrite = false;
                Graphics.DrawTexture(cameraRect, previewTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, EditorGUIUtility.GUITextureBlit2SRGBMaterial);
            }
        }