static internal void InitPlaymodeLayout()
        {
            m_PlayModeView = WindowLayout.ShowAppropriateViewOnEnterExitPlaymode(true) as PlayModeView;
            if (m_PlayModeView == null)
            {
                return;
            }

            if (m_PlayModeView.maximizeOnPlay)
            {
                DockArea da = m_PlayModeView.m_Parent as DockArea;

                if (da != null)
                {
                    m_MaximizePending = WindowLayout.MaximizePrepare(da.actualView);
                }
            }

            // Mark this PlayModeView window as the start view so the backend
            // can set size and mouseoffset properly for this view
            m_PlayModeView.m_Parent.SetAsStartView();
            m_PlayModeView.m_Parent.SetAsLastPlayModeView();

            Toolbar.RepaintToolbar();
        }
        public virtual void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }
            var c = (Camera)target;

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

            Vector2 currentMainPlayModeViewTargetSize = PlayModeView.GetMainPlayModeViewTargetSize();

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

            CameraEditorUtils.HandleFrustum(c, referenceTargetIndex);
        }
        static PlayModeView GetOrCreateWindow()
        {
            var view = PlayModeView.GetMainPlayModeView();

            if (view == null)
            {
                return(EditorWindow.CreateWindow <GameView>());
            }

            return(view);
        }
Example #4
0
        protected void SwapMainWindow(Type type)
        {
            if (type.BaseType != typeof(PlayModeView))
            {
                throw new ArgumentException("Type should derive from " + typeof(PlayModeView).Name);
            }
            if (type.Name != GetType().Name)
            {
                var serializedViews = ListsToDictionary(m_SerializedViewNames, m_SerializedViewValues);

                // Clear serialized views so they wouldn't be serialized again
                m_SerializedViewNames.Clear();
                m_SerializedViewValues.Clear();

                var guid = GUID.Generate();
                var serializedViewPath = Path.GetFullPath(Path.Combine(m_ViewsCache, guid.ToString()));
                if (!Directory.Exists(m_ViewsCache))
                {
                    Directory.CreateDirectory(m_ViewsCache);
                }

                InternalEditorUtility.SaveToSerializedFileAndForget(new[] { this }, serializedViewPath, true);
                serializedViews.Add(GetTypeName(), serializedViewPath);

                PlayModeView window = null;
                if (serializedViews.ContainsKey(type.ToString()))
                {
                    var path = serializedViews[type.ToString()];
                    serializedViews.Remove(type.ToString());
                    if (File.Exists(path))
                    {
                        window = InternalEditorUtility.LoadSerializedFileAndForget(path)[0] as PlayModeView;
                        File.Delete(path);
                    }
                }

                if (!window)
                {
                    window = CreateInstance(type) as PlayModeView;
                }

                window.autoRepaintOnSceneChange = true;

                window.SetSerializedViews(serializedViews);

                var da = m_Parent as DockArea;
                if (da)
                {
                    da.AddTab(window);
                    da.RemoveTab(this);
                    DestroyImmediate(this, true);
                }
            }
        }
        void PollSplashState()
        {
            // Force the GameViews to repaint whilst showing the splash(1166664)
            PlayModeView.RepaintAll();

            // When the splash screen is playing we need to keep track so that we can update the preview button when it has finished.
            if (SplashScreen.isFinished)
            {
                m_Owner.Repaint();
                EditorApplication.update -= PollSplashState;
            }
        }
Example #6
0
        internal static float GetGameViewAspectRatio()
        {
            Vector2 gameViewSize = PlayModeView.GetMainPlayModeViewTargetSize();

            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);
        }
Example #7
0
        void PollSplashState()
        {
            // Force the GameViews to repaint whilst showing the splash(1166664)
            PlayModeView.RepaintAll();

            // When the splash screen is playing we need to keep track so that we can update the preview button when it has finished.
            if (SplashScreen.isFinished)
            {
                var window = SettingsWindow.FindWindowByScope(SettingsScope.Project);
                window?.Repaint();
                EditorApplication.update -= PollSplashState;
            }
        }
        internal static PlayModeView GetMainPlayModeView()
        {
            if (s_LastFocused == null && s_PlayModeViews != null)
            {
                RemoveDisabledWindows();
                if (s_PlayModeViews.Count > 0)
                {
                    s_LastFocused = s_PlayModeViews[0];
                }
            }

            return(s_LastFocused);
        }
Example #9
0
 protected void SetFocus(bool focused)
 {
     if (!focused && s_LastFocused == this)
     {
         InternalEditorUtility.OnGameViewFocus(false);
     }
     else if (focused)
     {
         InternalEditorUtility.OnGameViewFocus(true);
         m_Parent.SetAsLastPlayModeView();
         s_LastFocused = this;
         Repaint();
     }
 }
        internal void ClickEnableFrameDebugger()
        {
            bool isEnabled       = FrameDebugger.enabled;
            bool enablingLocally = !isEnabled && m_AttachToPlayerState.connectedToTarget == ConnectionTarget.Editor;

            if (enablingLocally && !FrameDebuggerUtility.locallySupported)
            {
                return;
            }

            // pause play mode if needed
            if (enablingLocally)
            {
                if (EditorApplication.isPlaying && !EditorApplication.isPaused)
                {
                    EditorApplication.isPaused = true;
                }
            }

            if (!isEnabled)
            {
                FrameDebuggerUtility.SetEnabled(true, ProfilerDriver.connectedProfiler);
            }
            else
            {
                FrameDebuggerUtility.SetEnabled(false, FrameDebuggerUtility.GetRemotePlayerGUID());
            }

            // Make sure game view is visible when enabling frame debugger locally
            if (FrameDebugger.IsLocalEnabled())
            {
                PlayModeView playModeView = PlayModeView.GetMainPlayModeView();
                if (playModeView)
                {
                    playModeView.ShowTab();
                }
            }
        }
        void InitEffectUI()
        {
            if (!m_IsVisible)
            {
                return;
            }

            // Use locked particle system if set otherwise check selected gameobject
            ParticleSystem target = ParticleSystemEditorUtils.lockedParticleSystem;

            if (target == null && Selection.activeGameObject != null)
            {
                target = Selection.activeGameObject.GetComponent <ParticleSystem>();
            }

            m_Target = target;
            if (m_Target != null)
            {
                if (m_ParticleEffectUI == null)
                {
                    m_ParticleEffectUI = new ParticleEffectUI(this);
                }

                if (m_ParticleEffectUI.InitializeIfNeeded(new ParticleSystem[] { m_Target }))
                {
                    Repaint();
                }
            }

            // Cleanup if needed
            if (m_Target == null && m_ParticleEffectUI != null)
            {
                Clear();
                Repaint();
                SceneView.RepaintAll();
                PlayModeView.RepaintAll();
            }
        }
        static void CopyPlacementShortcut()
        {
            // if we are interacting with a game view, copy the main camera placement
            var playView = PlayModeView.GetLastFocusedPlayModeView();

            if (playView != null && (EditorWindow.focusedWindow == playView || EditorWindow.mouseOverWindow == playView))
            {
                var cam = Camera.main;
                if (cam != null)
                {
                    Clipboard.SetCustomValue(new TransformWorldPlacement(cam.transform));
                }
            }
            // otherwise copy the last active scene view placement
            else
            {
                var sceneView = SceneView.lastActiveSceneView;
                if (sceneView != null)
                {
                    CopyPlacement(sceneView);
                }
            }
        }
        private void UpdateAssociatedPlayModeView()
        {
            for (var i = 0; i < m_maxDisplays; ++i)
            {
                var view = PlayModeView.GetAssociatedViewForTargetDisplay(i);
                if (m_views[i] == view)
                {
                    continue;
                }

                m_views[i] = view;
                if (view != null)
                {
                    EditorDisplayUtility.AddVirtualDisplay(i, (int)view.targetSize.x, (int)view.targetSize.y);
                }
                else
                {
                    EditorDisplayUtility.RemoveVirtualDisplay(i);
                }
            }

            UpdateDisplayList(false);
        }
Example #14
0
        public virtual void OnSceneGUI()
        {
            if (!target)
            {
                return;
            }
            var c = (Camera)target;

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

            Vector2 currentMainPlayModeViewTargetSize = PlayModeView.GetMainPlayModeViewTargetSize();

            if (s_PreviousMainPlayModeViewTargetSize != currentMainPlayModeViewTargetSize)
            {
                // a gameView size change can affect horizontal FOV, refresh the inspector when that happens.
                Repaint();
                s_PreviousMainPlayModeViewTargetSize = currentMainPlayModeViewTargetSize;
            }

            CameraEditorUtils.HandleFrustum(c, referenceTargetIndex);
        }
Example #15
0
        public virtual void OnOverlayGUI(Object target, SceneView sceneView)
        {
            if (target == null)
            {
                return;
            }

            var c = (Camera)target;

            // Do not render the Camera Preview overlay if the target camera GameObject is not part of the objects the SceneView is rendering
            if (!sceneView.IsGameObjectInThisSceneView(c.gameObject))
            {
                return;
            }

            Vector2 previewSize = c.targetTexture ? new Vector2(c.targetTexture.width, c.targetTexture.height) : PlayModeView.GetMainPlayModeViewTargetSize();

            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;

            // clamp normalized rect in [0,1]
            normalizedViewPortRect.xMin = Math.Max(normalizedViewPortRect.xMin, 0f);
            normalizedViewPortRect.yMin = Math.Max(normalizedViewPortRect.yMin, 0f);
            normalizedViewPortRect.xMax = Math.Min(normalizedViewPortRect.xMax, 1f);
            normalizedViewPortRect.yMax = Math.Min(normalizedViewPortRect.yMax, 1f);

            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);

            cameraRect.width = Mathf.Floor(cameraRect.width);

            if (Event.current.type == EventType.Repaint)
            {
                Graphics.DrawTexture(cameraRect, Texture2D.whiteTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, Color.black);
            }

            var properWidth = cameraRect.height * aspect;

            cameraRect.x    += (cameraRect.width - properWidth) * 0.5f;
            cameraRect.width = properWidth;


            if (Event.current.type == EventType.Repaint)
            {
                // setup camera and render
                previewCamera.CopyFrom(c);

                // make sure the preview camera is rendering the same stage as the SceneView is
                if (sceneView.overrideSceneCullingMask != 0)
                {
                    previewCamera.overrideSceneCullingMask = sceneView.overrideSceneCullingMask;
                }
                else
                {
                    previewCamera.scene = sceneView.customScene;
                }

                // 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);

                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();
                Graphics.DrawTexture(cameraRect, previewTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, EditorGUIUtility.GUITextureBlit2SRGBMaterial);
            }
        }
Example #16
0
        private void CommandBufferGUI()
        {
            // Command buffers are not serialized data, so can't get to them through
            // serialized property (hence no multi-edit).
            if (targets.Length != 1)
            {
                return;
            }
            var cam = target as Camera;

            if (cam == null)
            {
                return;
            }
            int count = cam.commandBufferCount;

            if (count == 0)
            {
                return;
            }

            m_CommandBuffersShown = GUILayout.Toggle(m_CommandBuffersShown, GUIContent.Temp(count + " command buffers"), EditorStyles.foldout);
            if (!m_CommandBuffersShown)
            {
                return;
            }
            EditorGUI.indentLevel++;
            foreach (CameraEvent ce in (CameraEvent[])System.Enum.GetValues(typeof(CameraEvent)))
            {
                CommandBuffer[] cbs = cam.GetCommandBuffers(ce);
                foreach (CommandBuffer cb in cbs)
                {
                    using (new GUILayout.HorizontalScope())
                    {
                        // row with event & command buffer information label
                        Rect rowRect = GUILayoutUtility.GetRect(GUIContent.none, EditorStyles.miniLabel);
                        rowRect.xMin += EditorGUI.indent;
                        Rect minusRect = GetRemoveButtonRect(rowRect);
                        rowRect.xMax = minusRect.x;
                        GUI.Label(rowRect, string.Format("{0}: {1} ({2})", ce, cb.name, EditorUtility.FormatBytes(cb.sizeInBytes)), EditorStyles.miniLabel);
                        // and a button to remove it
                        if (GUI.Button(minusRect, Styles.iconRemove, Styles.invisibleButton))
                        {
                            cam.RemoveCommandBuffer(ce, cb);
                            SceneView.RepaintAll();
                            PlayModeView.RepaintAll();
                            GUIUtility.ExitGUI();
                        }
                    }
                }
            }
            // "remove all" button
            using (new GUILayout.HorizontalScope())
            {
                GUILayout.FlexibleSpace();
                if (GUILayout.Button("Remove all", EditorStyles.miniButton))
                {
                    cam.RemoveAllCommandBuffers();
                    SceneView.RepaintAll();
                    PlayModeView.RepaintAll();
                }
            }
            EditorGUI.indentLevel--;
        }
Example #17
0
 internal static void GetMainPlayModeViewSize(out Vector2 size)
 {
     size = PlayModeView.GetMainPlayModeViewTargetSize();
 }
 internal static void RepaintAll()
 {
     PlayModeView.RepaintAll();
 }
Example #19
0
 public RenderingView(PlayModeView playModeView)
 {
     PlayModeView.s_RenderingView = playModeView;
 }
Example #20
0
 static void RepaintSceneAndGameViews()
 {
     SceneView.RepaintAll();
     PlayModeView.RepaintAll();
 }
 static private void Clear()
 {
     m_MaximizePending = false;
     m_PlayModeView    = null;
 }
Example #22
0
        private void BuiltinCustomSplashScreenGUI()
        {
            EditorGUILayout.LabelField(k_Texts.splashTitle, EditorStyles.boldLabel);

            using (new EditorGUI.DisabledScope(!licenseAllowsDisabling))
            {
                EditorGUILayout.PropertyField(m_ShowUnitySplashScreen, k_Texts.showSplash);
                if (!m_ShowUnitySplashScreen.boolValue)
                {
                    return;
                }
            }

            GUIContent buttonLabel       = SplashScreen.isFinished ? k_Texts.previewSplash : k_Texts.cancelPreviewSplash;
            Rect       previewButtonRect = GUILayoutUtility.GetRect(buttonLabel, "button");

            previewButtonRect = EditorGUI.PrefixLabel(previewButtonRect, new GUIContent(" "));
            if (GUI.Button(previewButtonRect, buttonLabel))
            {
                if (SplashScreen.isFinished)
                {
                    SplashScreen.Begin();
                    PlayModeView.RepaintAll();
                    var playModeView = PlayModeView.GetMainPlayModeView();
                    if (playModeView)
                    {
                        playModeView.Focus();
                    }
                    EditorApplication.update += PollSplashState;
                }
                else
                {
                    SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
                    EditorApplication.update -= PollSplashState;
                }

                GameView.RepaintAll();
            }

            EditorGUILayout.PropertyField(m_SplashScreenLogoStyle, k_Texts.splashStyle);

            // Animation
            EditorGUILayout.PropertyField(m_SplashScreenAnimation, k_Texts.animate);
            m_ShowAnimationControlsAnimator.target = m_SplashScreenAnimation.intValue == (int)PlayerSettings.SplashScreen.AnimationMode.Custom;

            if (EditorGUILayout.BeginFadeGroup(m_ShowAnimationControlsAnimator.faded))
            {
                EditorGUI.indentLevel++;
                EditorGUILayout.Slider(m_SplashScreenLogoAnimationZoom, 0.0f, 1.0f, k_Texts.logoZoom);
                EditorGUILayout.Slider(m_SplashScreenBackgroundAnimationZoom, 0.0f, 1.0f, k_Texts.backgroundZoom);
                EditorGUI.indentLevel--;
            }
            EditorGUILayout.EndFadeGroup();

            EditorGUILayout.Space();

            // Logos
            EditorGUILayout.LabelField(k_Texts.logosTitle, EditorStyles.boldLabel);
            using (new EditorGUI.DisabledScope(!Application.HasProLicense()))
            {
                EditorGUI.BeginChangeCheck();
                EditorGUILayout.PropertyField(m_ShowUnitySplashLogo, k_Texts.showLogo);
                if (EditorGUI.EndChangeCheck())
                {
                    if (!m_ShowUnitySplashLogo.boolValue)
                    {
                        RemoveUnityLogoFromLogosList();
                    }
                    else if (m_SplashScreenDrawMode.intValue == (int)PlayerSettings.SplashScreen.DrawMode.AllSequential)
                    {
                        AddUnityLogoToLogosList();
                    }
                }

                m_ShowLogoControlsAnimator.target = m_ShowUnitySplashLogo.boolValue;
            }

            if (EditorGUILayout.BeginFadeGroup(m_ShowLogoControlsAnimator.faded))
            {
                EditorGUI.BeginChangeCheck();
                var oldDrawmode = m_SplashScreenDrawMode.intValue;
                EditorGUILayout.PropertyField(m_SplashScreenDrawMode, k_Texts.drawMode);
                if (oldDrawmode != m_SplashScreenDrawMode.intValue)
                {
                    if (m_SplashScreenDrawMode.intValue == (int)PlayerSettings.SplashScreen.DrawMode.UnityLogoBelow)
                    {
                        RemoveUnityLogoFromLogosList();
                    }
                    else
                    {
                        AddUnityLogoToLogosList();
                    }
                }
            }
            EditorGUILayout.EndFadeGroup();

            using (var vertical = new EditorGUILayout.VerticalScope())
                using (new EditorGUI.PropertyScope(vertical.rect, GUIContent.none, m_SplashScreenLogos))
                {
                    m_LogoList.DoLayoutList();
                }


            EditorGUILayout.Space();

            // Background
            EditorGUILayout.LabelField(k_Texts.backgroundTitle, EditorStyles.boldLabel);
            EditorGUILayout.Slider(m_SplashScreenOverlayOpacity, Application.HasProLicense() ? k_MinProEditionOverlayOpacity : k_MinPersonalEditionOverlayOpacity, 1.0f, k_Texts.overlayOpacity);
            m_ShowBackgroundColorAnimator.target = m_SplashScreenBackgroundLandscape.objectReferenceValue == null;
            if (EditorGUILayout.BeginFadeGroup(m_ShowBackgroundColorAnimator.faded))
            {
                EditorGUILayout.PropertyField(m_SplashScreenBackgroundColor, k_Texts.backgroundColor);
            }
            EditorGUILayout.EndFadeGroup();

            EditorGUILayout.PropertyField(m_SplashScreenBlurBackground, k_Texts.blurBackground);
            EditorGUI.BeginChangeCheck();
            ObjectReferencePropertyField <Sprite>(m_SplashScreenBackgroundLandscape, k_Texts.backgroundImage);
            if (EditorGUI.EndChangeCheck() && m_SplashScreenBackgroundLandscape.objectReferenceValue == null)
            {
                m_SplashScreenBackgroundPortrait.objectReferenceValue = null;
            }

            using (new EditorGUI.DisabledScope(m_SplashScreenBackgroundLandscape.objectReferenceValue == null))
            {
                ObjectReferencePropertyField <Sprite>(m_SplashScreenBackgroundPortrait, k_Texts.backgroundPortraitImage);
            }
        }
        private void OnGUI()
        {
            FrameDebuggerEvent[] descs = FrameDebuggerUtility.GetFrameEvents();
            Initialize(descs);

            int oldLimit = FrameDebuggerUtility.limit;

            Profiler.BeginSample("DrawToolbar");
            bool repaint = m_Toolbar.DrawToolbar(this, m_AttachToPlayerState);

            Profiler.EndSample();

            if (IsDisabledInEditor)
            {
                GUI.enabled = true;
                if (!FrameDebuggerUtility.locallySupported)
                {
                    string warningMessage = (FrameDebuggerHelper.IsOnLinuxOpenGL) ? FrameDebuggerStyles.EventDetails.warningLinuxOpenGLMsg : FrameDebuggerStyles.EventDetails.warningMultiThreadedMsg;
                    EditorGUILayout.HelpBox(warningMessage, MessageType.Warning, true);
                }

                EditorGUILayout.HelpBox(FrameDebuggerStyles.EventDetails.descriptionString, MessageType.Info, true);
            }
            else
            {
                if (FrameDebugger.IsLocalEnabled())
                {
                    PlayModeView playModeView = PlayModeView.GetMainPlayModeView();
                    if (playModeView)
                    {
                        playModeView.ShowTab();
                    }
                }

                // captured frame event contents have changed, rebuild the tree data
                if (HasEventHashChanged)
                {
                    m_TreeView.m_DataSource.SetEvents(descs);
                    m_FrameEventsHash = FrameDebuggerUtility.eventsHash;
                }

                float toolbarHeight = EditorStyles.toolbar.fixedHeight;

                Rect dragRect = new Rect(m_TreeWidth, toolbarHeight, FrameDebuggerStyles.Window.k_ResizerWidth, position.height - toolbarHeight);
                dragRect    = EditorGUIUtility.HandleHorizontalSplitter(dragRect, position.width, FrameDebuggerStyles.Window.k_MinTreeWidth, FrameDebuggerStyles.Window.k_MinDetailsWidth);
                m_TreeWidth = dragRect.x;

                // Search area
                m_SearchRect       = EditorGUILayout.GetControlRect();
                m_SearchRect.width = m_TreeWidth - 5;
                DrawSearchField(m_SearchString);

                Rect listRect = new Rect(
                    0,
                    toolbarHeight + m_SearchRect.y,
                    m_TreeWidth,
                    position.height - toolbarHeight - m_SearchRect.height - 5
                    );

                Rect currentEventRect = new Rect(
                    m_TreeWidth,
                    toolbarHeight,
                    position.width - m_TreeWidth,
                    position.height - toolbarHeight
                    );

                Profiler.BeginSample("DrawTree");
                m_TreeView.m_TreeView.searchString = m_SearchString;
                m_TreeView.DrawTree(listRect);
                Profiler.EndSample();

                EditorGUIUtility.DrawHorizontalSplitter(dragRect);

                Profiler.BeginSample("DrawEvent");
                m_EventDetailsView.DrawEvent(currentEventRect, descs, m_AttachToPlayerState.connectedToTarget == ConnectionTarget.Editor);
                Profiler.EndSample();
            }

            if (repaint || oldLimit != FrameDebuggerUtility.limit)
            {
                RepaintOnLimitChange();
            }

            if (m_RepaintFrames > 0)
            {
                m_TreeView.SelectFrameEventIndex(FrameDebuggerUtility.limit);
                RepaintAllNeededThings();
                --m_RepaintFrames;
            }
        }
        public override void OnGUI()
        {
            UpdateSize();

            imguiContainer.style.minWidth        = collapsed ? new StyleLength(240) : new StyleLength(StyleKeyword.Auto);
            imguiContainer.style.minHeight       = collapsed ? new StyleLength(135) : new StyleLength(StyleKeyword.Auto);
            imguiContainer.parent.style.flexGrow = 1;
            imguiContainer.style.flexGrow        = 1;

            if (selectedCamera == null)
            {
                GUILayout.Label("No camera selected", EditorStyles.centeredGreyMiniLabel);
                return;
            }

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

            var sceneView = SceneView.lastActiveSceneView;

            // Do not render the Camera Preview overlay if the target camera GameObject is not part of the objects the
            // SceneView is rendering
            if (!sceneView.IsGameObjectInThisSceneView(selectedCamera.gameObject))
            {
                return;
            }

            var cameraRect = imguiContainer.rect;

            cameraRect.width = Mathf.Floor(cameraRect.width);

            if (cameraRect.width < 1 || cameraRect.height < 1)
            {
                return;
            }

            if (Event.current.type == EventType.Repaint)
            {
                Graphics.DrawTexture(cameraRect, Texture2D.whiteTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, Color.black);

                // setup camera and render
                previewCamera.CopyFrom(selectedCamera);

                // make sure the preview camera is rendering the same stage as the SceneView is
                if (sceneView.overrideSceneCullingMask != 0)
                {
                    previewCamera.overrideSceneCullingMask = sceneView.overrideSceneCullingMask;
                }
                else
                {
                    previewCamera.scene = sceneView.customScene;
                }

                // also make sure to sync any Skybox component on the preview camera
                var dstSkybox = previewCamera.GetComponent <Skybox>();
                if (dstSkybox)
                {
                    var srcSkybox = selectedCamera.GetComponent <Skybox>();
                    if (srcSkybox && srcSkybox.enabled)
                    {
                        dstSkybox.enabled  = true;
                        dstSkybox.material = srcSkybox.material;
                    }
                    else
                    {
                        dstSkybox.enabled = false;
                    }
                }

                Vector2 previewSize = selectedCamera.targetTexture
                    ? new Vector2(selectedCamera.targetTexture.width, selectedCamera.targetTexture.height)
                    : PlayModeView.GetMainPlayModeViewTargetSize();

                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;
                }

                float rectAspect    = cameraRect.width / cameraRect.height;
                float previewAspect = previewSize.x / previewSize.y;
                Rect  previewRect   = cameraRect;
                if (rectAspect > previewAspect)
                {
                    float stretch = previewAspect / rectAspect;
                    previewRect = new Rect(cameraRect.xMin + cameraRect.width * (1.0f - stretch) * .5f, cameraRect.yMin, stretch * cameraRect.width, cameraRect.height);
                }
                else
                {
                    float stretch = rectAspect / previewAspect;
                    previewRect = new Rect(cameraRect.xMin, cameraRect.yMin + cameraRect.height * (1.0f - stretch) * .5f, cameraRect.width, stretch * cameraRect.height);
                }

                var previewTexture = GetPreviewTextureWithSizeAndAA((int)previewRect.width, (int)previewRect.height);
                previewCamera.targetTexture = previewTexture;
                previewCamera.pixelRect     = new Rect(0, 0, previewRect.width, previewRect.height);

                Handles.EmitGUIGeometryForCamera(selectedCamera, previewCamera);

                if (selectedCamera.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();

                Graphics.DrawTexture(previewRect, previewTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, EditorGUIUtility.GUITextureBlit2SRGBMaterial);
            }
        }