示例#1
0
        public static void GameViewStatsGUI()
        {
            GUI.skin  = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
            GUI.color = new Color(1f, 1f, 1f, 0.75f);
            float width  = 300f;
            float height = 204f;
            int   length = Network.connections.Length;

            if (length != 0)
            {
                height += 220f;
            }
            GUILayout.BeginArea(new Rect((float)((double)GUIView.current.position.width - (double)width - 10.0), 27f, width, height), "Statistics", GUI.skin.window);
            GUILayout.Label("Audio:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            StringBuilder stringBuilder1 = new StringBuilder(400);
            float         audioLevel     = UnityStats.audioLevel;

            stringBuilder1.Append("  Level: " + GameViewGUI.FormatDb(audioLevel) + (!EditorUtility.audioMasterMute ? "\n" : " (MUTED)\n"));
            stringBuilder1.Append(string.Format("  Clipping: {0:F1}%", (object)(float)(100.0 * (double)UnityStats.audioClippingAmount)));
            GUILayout.Label(stringBuilder1.ToString());
            GUI.Label(new Rect(170f, 40f, 120f, 20f), string.Format("DSP load: {0:F1}%", (object)(float)(100.0 * (double)UnityStats.audioDSPLoad)));
            GUI.Label(new Rect(170f, 53f, 120f, 20f), string.Format("Stream load: {0:F1}%", (object)(float)(100.0 * (double)UnityStats.audioStreamLoad)));
            GUILayout.Label("Graphics:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            GameViewGUI.UpdateFrameTime();
            GUI.Label(new Rect(170f, 75f, 120f, 20f), string.Format("{0:F1} FPS ({1:F1}ms)", (object)(float)(1.0 / (double)Mathf.Max(GameViewGUI.m_MaxFrameTime, 1E-05f)), (object)(float)((double)GameViewGUI.m_MaxFrameTime * 1000.0)));
            int           screenBytes    = UnityStats.screenBytes;
            int           num1           = UnityStats.dynamicBatchedDrawCalls - UnityStats.dynamicBatches;
            int           num2           = UnityStats.staticBatchedDrawCalls - UnityStats.staticBatches;
            StringBuilder stringBuilder2 = new StringBuilder(400);

            if ((double)GameViewGUI.m_ClientFrameTime > (double)GameViewGUI.m_RenderFrameTime)
            {
                stringBuilder2.Append(string.Format("  CPU: main <b>{0:F1}</b>ms  render thread {1:F1}ms\n", (object)(float)((double)GameViewGUI.m_ClientFrameTime * 1000.0), (object)(float)((double)GameViewGUI.m_RenderFrameTime * 1000.0)));
            }
            else
            {
                stringBuilder2.Append(string.Format("  CPU: main {0:F1}ms  render thread <b>{1:F1}</b>ms\n", (object)(float)((double)GameViewGUI.m_ClientFrameTime * 1000.0), (object)(float)((double)GameViewGUI.m_RenderFrameTime * 1000.0)));
            }
            stringBuilder2.Append(string.Format("  Batches: <b>{0}</b> \tSaved by batching: {1}\n", (object)UnityStats.batches, (object)(num1 + num2)));
            stringBuilder2.Append(string.Format("  Tris: {0} \tVerts: {1} \n", (object)GameViewGUI.FormatNumber(UnityStats.triangles), (object)GameViewGUI.FormatNumber(UnityStats.vertices)));
            stringBuilder2.Append(string.Format("  Screen: {0} - {1}\n", (object)UnityStats.screenRes, (object)EditorUtility.FormatBytes(screenBytes)));
            stringBuilder2.Append(string.Format("  SetPass calls: {0} \tShadow casters: {1} \n", (object)UnityStats.setPassCalls, (object)UnityStats.shadowCasters));
            stringBuilder2.Append(string.Format("  Visible skinned meshes: {0}  Animations: {1}", (object)UnityStats.visibleSkinnedMeshes, (object)UnityStats.visibleAnimations));
            GUILayout.Label(stringBuilder2.ToString(), GameViewGUI.labelStyle, new GUILayoutOption[0]);
            if (length != 0)
            {
                GUILayout.Label("Network:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
                GUILayout.BeginHorizontal();
                for (int i = 0; i < length; ++i)
                {
                    GUILayout.Label(UnityStats.GetNetworkStats(i));
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.Label("Network: (no players connected)", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            }
            GUILayout.EndArea();
        }
示例#2
0
        private void OnGUI()
        {
            if (position.size * EditorGUIUtility.pixelsPerPoint != m_LastWindowPixelSize) // pixelsPerPoint only reliable in OnGUI()
            {
                UpdateZoomAreaAndParent();
            }

            if (showToolbar)
            {
                DoToolbarGUI();
            }

            // This isn't ideal. Custom Cursors set by editor extensions for other windows can leak into the game view.
            // To fix this we should probably stop using the global custom cursor (intended for runtime) for custom editor cursors.
            // This has been noted for Cursors tech debt.
            EditorGUIUtility.AddCursorRect(viewInWindow, MouseCursor.CustomCursor);

            EventType type = Event.current.type;

            // Gain mouse lock when clicking on game view content
            if (type == EventType.MouseDown && viewInWindow.Contains(Event.current.mousePosition))
            {
                AllowCursorLockAndHide(true);
            }
            // Lose mouse lock when pressing escape
            else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                AllowCursorLockAndHide(false);
            }

            // We hide sliders when playing, and also when we are zoomed out beyond canvas edges
            var playing = EditorApplication.isPlaying && !EditorApplication.isPaused;
            var targetInContentCached = targetInContent;

            m_ZoomArea.hSlider          = !playing && m_ZoomArea.shownArea.width < targetInContentCached.width;
            m_ZoomArea.vSlider          = !playing && m_ZoomArea.shownArea.height < targetInContentCached.height;
            m_ZoomArea.enableMouseInput = !playing;
            ConfigureZoomArea();

            // We don't want controls inside the GameView (e.g. the toolbar) to have keyboard focus while playing.
            // The game should get the keyboard events.
            if (playing)
            {
                EditorGUIUtility.keyboardControl = 0;
            }

            GUI.color = Color.white; // Get rid of play mode tint

            var originalEventType = Event.current.type;

            m_ZoomArea.BeginViewGUI();

            // Window size might change on Layout event
            if (type == EventType.Layout)
            {
                targetSize = targetRenderSize;
            }

            // Setup game view dimensions, so that player loop can use it for input
            var gameViewTarget = GUIClip.UnclipToWindow(m_ZoomArea.drawRect);

            if (m_Parent)
            {
                var zoomedTarget = new Rect(targetInView.position + gameViewTarget.position, targetInView.size);
                SetParentGameViewDimensions(zoomedTarget, gameViewTarget, targetRenderSize);
            }

            var editorMousePosition = Event.current.mousePosition;
            var gameMousePosition   = (editorMousePosition + gameMouseOffset) * gameMouseScale;

            if (type == EventType.Repaint)
            {
                GUI.Box(m_ZoomArea.drawRect, GUIContent.none, Styles.gameViewBackgroundStyle);

                Vector2 oldOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState oldState = SavedGUIState.Create();


                var clearTexture = m_ClearInEditMode && !EditorApplication.isPlaying;

                var currentTargetDisplay = 0;
                if (ModuleManager.ShouldShowMultiDisplayOption())
                {
                    // Display Targets can have valid targets from 0 to 7.
                    System.Diagnostics.Debug.Assert(targetDisplay < 8, "Display Target is Out of Range");
                    currentTargetDisplay = targetDisplay;
                }

                targetDisplay = currentTargetDisplay;
                targetSize    = targetRenderSize;
                showGizmos    = m_Gizmos;
                clearColor    = kClearBlack;
                renderIMGUI   = true;

                if (!EditorApplication.isPlaying || (EditorApplication.isPlaying && Time.frameCount % OnDemandRendering.renderFrameInterval == 0))
                {
                    m_RenderTexture = RenderView(gameMousePosition, clearTexture);
                }

                if (m_TargetClamped)
                {
                    Debug.LogWarningFormat("GameView reduced to a reasonable size for this system ({0}x{1})", targetSize.x, targetSize.y);
                }
                EditorGUIUtility.SetupWindowSpaceAndVSyncInternal(GUIClip.Unclip(viewInWindow));

                if (m_RenderTexture != null && m_RenderTexture.IsCreated())
                {
                    oldState.ApplyAndForget();
                    GUIUtility.s_EditorScreenPointOffset = oldOffset;

                    GUI.BeginGroup(m_ZoomArea.drawRect);
                    // Actually draw the game view to the screen, without alpha blending
                    Rect drawRect = deviceFlippedTargetInView;
                    drawRect.x = Mathf.Round(drawRect.x);
                    drawRect.y = Mathf.Round(drawRect.y);
                    Graphics.DrawTexture(drawRect, m_RenderTexture, new Rect(0, 0, 1, 1), 0, 0, 0, 0, GUI.color, GUI.blitMaterial);
                    GUI.EndGroup();
                }
            }
            else if (type != EventType.Layout && type != EventType.Used)
            {
                if (Event.current.isKey && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }

                bool mousePosInGameViewRect = viewInWindow.Contains(Event.current.mousePosition);

                // MouseDown events outside game view rect are not send to scripts but MouseUp events are (see below)
                if (Event.current.rawType == EventType.MouseDown && !mousePosInGameViewRect)
                {
                    return;
                }

                var originalDisplayIndex = Event.current.displayIndex;

                // Transform events into local space, so the mouse position is correct
                // Then queue it up for playback during playerloop
                Event.current.mousePosition = gameMousePosition;
                Event.current.displayIndex  = targetDisplay;

                EditorGUIUtility.QueueGameViewInputEvent(Event.current);

                // Do not use mouse UP event if mousepos is outside game view rect (fix for case 380995: Gameview tab's context menu is not appearing on right click)
                // Placed after event queueing above to ensure scripts can react on mouse up events.
                bool useEvent = !(Event.current.rawType == EventType.MouseUp && !mousePosInGameViewRect);

                // Don't use command events, or they won't be sent to other views.
                if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                {
                    useEvent = false;
                }

                if (useEvent)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = editorMousePosition;
                }

                // Reset display index
                Event.current.displayIndex = originalDisplayIndex;
            }

            m_ZoomArea.EndViewGUI();

            if (originalEventType == EventType.ScrollWheel && Event.current.type == EventType.Used)
            {
                EditorApplication.update -= SnapZoomDelayed;
                EditorApplication.update += SnapZoomDelayed;
                s_LastScrollTime          = EditorApplication.timeSinceStartup;
            }

            EnforceZoomAreaConstraints();

            if (m_RenderTexture)
            {
                if (m_ZoomArea.scale.y < 1f)
                {
                    m_RenderTexture.filterMode = FilterMode.Bilinear;
                }
                else
                {
                    m_RenderTexture.filterMode = FilterMode.Point;
                }
            }

            if (m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(targetDisplay))
            {
                GUI.Label(warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                var displayName   = ModuleManager.ShouldShowMultiDisplayOption() ? DisplayUtility.GetDisplayNames()[targetDisplay].text : string.Empty;
                var cameraWarning = string.Format("{0}\nNo cameras rendering", displayName);
                EditorGUI.DoDropShadowLabel(warningPosition, EditorGUIUtility.TempContent(cameraWarning), EditorStyles.notificationText, .3f);
            }

            if (m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#3
0
        private void OnGUI()
        {
            if (base.position.size * EditorGUIUtility.pixelsPerPoint != this.m_LastWindowPixelSize)
            {
                this.UpdateZoomAreaAndParent();
            }
            this.DoToolbarGUI();
            this.CopyDimensionsToParentView();
            EditorGUIUtility.AddCursorRect(this.viewInWindow, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if (type == EventType.MouseDown && this.viewInWindow.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                this.AllowCursorLockAndHide(false);
            }
            bool flag = EditorApplication.isPlaying && !EditorApplication.isPaused;

            this.m_ZoomArea.hSlider          = (!flag && this.m_ZoomArea.shownArea.width < this.targetInContent.width);
            this.m_ZoomArea.vSlider          = (!flag && this.m_ZoomArea.shownArea.height < this.targetInContent.height);
            this.m_ZoomArea.enableMouseInput = !flag;
            this.ConfigureZoomArea();
            if (flag)
            {
                GUIUtility.keyboardControl = 0;
            }
            Vector2 mousePosition  = Event.current.mousePosition;
            Vector2 mousePosition2 = this.WindowToGameMousePosition(mousePosition);

            GUI.color = Color.white;
            EventType type2 = Event.current.type;

            this.m_ZoomArea.BeginViewGUI();
            if (type == EventType.Repaint)
            {
                GUI.Box(this.m_ZoomArea.drawRect, GUIContent.none, GameView.Styles.gameViewBackgroundStyle);
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                this.ConfigureTargetTexture((int)this.targetSize.x, (int)this.targetSize.y);
                if (this.m_ClearInEditMode && !EditorApplication.isPlaying)
                {
                    this.ClearTargetTexture();
                }
                int targetDisplay = 0;
                if (ModuleManager.ShouldShowMultiDisplayOption())
                {
                    targetDisplay = this.m_TargetDisplay;
                }
                if (this.m_TargetTexture.IsCreated())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(this.m_TargetTexture, targetDisplay, GUIClip.Unclip(this.viewInWindow), mousePosition2, this.m_Gizmos);
                    savedGUIState.ApplyAndForget();
                    GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset;
                    GUI.BeginGroup(this.m_ZoomArea.drawRect);
                    Graphics.DrawTexture(this.deviceFlippedTargetInView, this.m_TargetTexture, new Rect(0f, 0f, 1f, 1f), 0, 0, 0, 0, GUI.color, GUI.blitMaterial);
                    GUI.EndGroup();
                }
            }
            else if (type != EventType.Layout && type != EventType.Used)
            {
                if (WindowLayout.s_MaximizeKey.activated)
                {
                    if (!EditorApplication.isPlaying || EditorApplication.isPaused)
                    {
                        return;
                    }
                }
                bool flag2 = this.viewInWindow.Contains(Event.current.mousePosition);
                if (Event.current.rawType == EventType.MouseDown && !flag2)
                {
                    return;
                }
                int displayIndex = Event.current.displayIndex;
                Event.current.mousePosition = mousePosition2;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if (Event.current.rawType == EventType.MouseUp && !flag2)
                {
                    flag3 = false;
                }
                if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                {
                    flag3 = false;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
                Event.current.displayIndex = displayIndex;
            }
            this.m_ZoomArea.EndViewGUI();
            if (type2 == EventType.ScrollWheel && Event.current.type == EventType.Used)
            {
                EditorApplication.update  = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                EditorApplication.update  = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                GameView.s_LastScrollTime = EditorApplication.timeSinceStartup;
            }
            this.EnforceZoomAreaConstraints();
            if (this.m_TargetTexture)
            {
                if (this.m_ZoomArea.scale.y < 1f)
                {
                    this.m_TargetTexture.filterMode = FilterMode.Bilinear;
                }
                else
                {
                    this.m_TargetTexture.filterMode = FilterMode.Point;
                }
            }
            if (this.m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay))
            {
                GUI.Label(this.warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                string arg = (!ModuleManager.ShouldShowMultiDisplayOption()) ? string.Empty : DisplayUtility.GetDisplayNames()[this.m_TargetDisplay].text;
                string t   = string.Format("{0}\nNo cameras rendering", arg);
                EditorGUI.DoDropShadowLabel(this.warningPosition, EditorGUIUtility.TempContent(t), EditorStyles.notificationText, 0.3f);
            }
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
        private void OnGUI()
        {
            if (GameView.s_GizmoButtonStyle == null)
            {
                GameView.s_GizmoButtonStyle                 = "GV Gizmo DropDown";
                GameView.s_ResolutionWarningStyle           = new GUIStyle("PreOverlayLabel");
                GameView.s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft;
                GameView.s_ResolutionWarningStyle.padding   = new RectOffset(6, 6, 1, 1);
            }
            this.DoToolbarGUI();
            Rect gameViewRenderRect = this.gameViewRenderRect;
            Rect renderRect         = EditorGUIUtility.PointsToPixels(gameViewRenderRect);
            bool fitsInsideRect;
            Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(renderRect, this.selectedSizeIndex, out fitsInsideRect);
            Rect rect       = EditorGUIUtility.PixelsToPoints(constrainedGameViewRenderRect);
            Rect rect2      = GUIClip.Unclip(rect);
            Rect cameraRect = EditorGUIUtility.PointsToPixels(rect2);

            base.SetInternalGameViewRect(rect2);
            EditorGUIUtility.AddCursorRect(rect, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if (type == EventType.MouseDown && gameViewRenderRect.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
            {
                Unsupported.SetAllowCursorLock(false);
            }
            if (type == EventType.Repaint)
            {
                bool flag = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay);
                if (!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera() || !flag)
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                    if (!InternalEditorUtility.HasFullscreenCamera())
                    {
                        float[] array = new float[]
                        {
                            30f,
                            gameViewRenderRect.height / 2f - 10f,
                            gameViewRenderRect.height - 10f
                        };
                        for (int i = 0; i < array.Length; i++)
                        {
                            int num = (int)array[i];
                            GUI.Label(new Rect(gameViewRenderRect.width / 2f - 100f, (float)num, 300f, 20f), "Scene is missing a fullscreen camera", "WhiteLargeLabel");
                        }
                    }
                }
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                if (this.ShouldShowMultiDisplayOption())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(cameraRect, 0, this.m_Gizmos, true);
                }
                GL.sRGBWrite = false;
                savedGUIState.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset;
            }
            else if (type != EventType.Layout && type != EventType.Used)
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag2 = rect.Contains(Event.current.mousePosition);
                if (Event.current.rawType == EventType.MouseDown && !flag2)
                {
                    return;
                }
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 vector        = mousePosition - rect.position;
                vector = EditorGUIUtility.PointsToPixels(vector);
                Event.current.mousePosition = vector;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if (Event.current.rawType == EventType.MouseUp && !flag2)
                {
                    flag3 = false;
                }
                if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                {
                    flag3 = false;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), fitsInsideRect, constrainedGameViewRenderRect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#5
0
        private void OnGUI()
        {
            if ((base.position.size * EditorGUIUtility.pixelsPerPoint) != this.m_LastWindowPixelSize)
            {
                this.UpdateZoomAreaAndParent();
            }
            this.DoToolbarGUI();
            this.CopyDimensionsToParentView();
            EditorGUIUtility.AddCursorRect(this.viewInWindow, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if ((type == EventType.MouseDown) && this.viewInWindow.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if ((type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape))
            {
                Unsupported.SetAllowCursorLock(false);
            }
            bool flag = EditorApplication.isPlaying && !EditorApplication.isPaused;

            this.m_ZoomArea.hSlider          = !flag && (this.m_ZoomArea.shownArea.width < this.targetInContent.width);
            this.m_ZoomArea.vSlider          = !flag && (this.m_ZoomArea.shownArea.height < this.targetInContent.height);
            this.m_ZoomArea.enableMouseInput = !flag;
            this.ConfigureZoomArea();
            if (flag)
            {
                GUIUtility.keyboardControl = 0;
            }
            Vector2 mousePosition = Event.current.mousePosition;
            Vector2 vector2       = this.WindowToGameMousePosition(mousePosition);

            GUI.color = Color.white;
            EventType type2 = Event.current.type;

            this.m_ZoomArea.BeginViewGUI();
            switch (type)
            {
            case EventType.Layout:
            case EventType.Used:
                break;

            case EventType.Repaint:
            {
                GUI.Box(this.m_ZoomArea.drawRect, GUIContent.none, Styles.gameViewBackgroundStyle);
                Vector2 vector3 = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState state = SavedGUIState.Create();
                this.ConfigureTargetTexture((int)this.targetSize.x, (int)this.targetSize.y);
                if (this.m_ClearInEditMode && !EditorApplication.isPlaying)
                {
                    this.ClearTargetTexture();
                }
                int targetDisplay = 0;
                if (this.ShouldShowMultiDisplayOption())
                {
                    targetDisplay = this.m_TargetDisplay;
                }
                if (this.m_TargetTexture.IsCreated())
                {
                    EditorGUIUtility.RenderGameViewCamerasInternal(this.m_TargetTexture, targetDisplay, GUIClip.Unclip(this.viewInWindow), vector2, this.m_Gizmos);
                    state.ApplyAndForget();
                    GUIUtility.s_EditorScreenPointOffset = vector3;
                    GUI.BeginGroup(this.m_ZoomArea.drawRect);
                    GL.sRGBWrite = this.m_CurrentColorSpace == ColorSpace.Linear;
                    GUI.DrawTexture(this.deviceFlippedTargetInView, this.m_TargetTexture, ScaleMode.StretchToFill, false);
                    GL.sRGBWrite = false;
                    GUI.EndGroup();
                }
                break;
            }

            default:
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag2 = this.viewInWindow.Contains(Event.current.mousePosition);
                if ((Event.current.rawType == EventType.MouseDown) && !flag2)
                {
                    return;
                }
                Event.current.mousePosition = vector2;
                Event.current.displayIndex  = this.m_TargetDisplay;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag3 = true;
                if ((Event.current.rawType == EventType.MouseUp) && !flag2)
                {
                    flag3 = false;
                }
                switch (type)
                {
                case EventType.ExecuteCommand:
                case EventType.ValidateCommand:
                    flag3 = false;
                    break;
                }
                if (flag3)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
                break;
            }
            }
            this.m_ZoomArea.EndViewGUI();
            if ((type2 == EventType.ScrollWheel) && (Event.current.type == EventType.Used))
            {
                EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Remove(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                EditorApplication.update = (EditorApplication.CallbackFunction)Delegate.Combine(EditorApplication.update, new EditorApplication.CallbackFunction(this.SnapZoomDelayed));
                s_LastScrollTime         = EditorApplication.timeSinceStartup;
            }
            this.EnforceZoomAreaConstraints();
            if (this.m_TargetTexture != null)
            {
                if (this.m_ZoomArea.scale.y < 1f)
                {
                    this.m_TargetTexture.filterMode = UnityEngine.FilterMode.Bilinear;
                }
                else
                {
                    this.m_TargetTexture.filterMode = UnityEngine.FilterMode.Point;
                }
            }
            if (this.m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay))
            {
                GUI.Label(this.warningPosition, GUIContent.none, EditorStyles.notificationBackground);
                string str = !this.ShouldShowMultiDisplayOption() ? string.Empty : DisplayUtility.GetDisplayNames()[this.m_TargetDisplay].text;
                string t   = $"{str}
No cameras rendering";
                EditorGUI.DoDropShadowLabel(this.warningPosition, EditorGUIUtility.TempContent(t), EditorStyles.notificationText, 0.3f);
            }
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#6
0
        public static void GameViewStatsGUI()
        {
            GUI.skin  = EditorGUIUtility.GetBuiltinSkin(EditorSkin.Scene);
            GUI.color = new Color(1f, 1f, 1f, 0.75f);
            float num  = 300f;
            float num2 = 204f;
            int   num3 = Network.connections.Length;

            if (num3 != 0)
            {
                num2 += 220f;
            }
            GUILayout.BeginArea(new Rect(GUIView.current.position.width - num - 10f, 27f, num, num2), "Statistics", GUI.skin.window);
            GUILayout.Label("Audio:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            StringBuilder stringBuilder = new StringBuilder(400);
            float         audioLevel    = UnityStats.audioLevel;

            stringBuilder.Append("  Level: " + GameViewGUI.FormatDb(audioLevel) + ((!EditorUtility.audioMasterMute) ? "\n" : " (MUTED)\n"));
            stringBuilder.Append(string.Format("  Clipping: {0:F1}%", 100f * UnityStats.audioClippingAmount));
            GUILayout.Label(stringBuilder.ToString(), new GUILayoutOption[0]);
            GUI.Label(new Rect(170f, 40f, 120f, 20f), string.Format("DSP load: {0:F1}%", 100f * UnityStats.audioDSPLoad));
            GUI.Label(new Rect(170f, 53f, 120f, 20f), string.Format("Stream load: {0:F1}%", 100f * UnityStats.audioStreamLoad));
            GUILayout.Label("Graphics:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            GameViewGUI.UpdateFrameTime();
            string text = string.Format("{0:F1} FPS ({1:F1}ms)", 1f / Mathf.Max(GameViewGUI.m_MaxFrameTime, 1E-05f), GameViewGUI.m_MaxFrameTime * 1000f);

            GUI.Label(new Rect(170f, 75f, 120f, 20f), text);
            int           screenBytes    = UnityStats.screenBytes;
            int           num4           = UnityStats.dynamicBatchedDrawCalls - UnityStats.dynamicBatches;
            int           num5           = UnityStats.staticBatchedDrawCalls - UnityStats.staticBatches;
            int           num6           = UnityStats.instancedBatchedDrawCalls - UnityStats.instancedBatches;
            StringBuilder stringBuilder2 = new StringBuilder(400);

            if (GameViewGUI.m_ClientFrameTime > GameViewGUI.m_RenderFrameTime)
            {
                stringBuilder2.Append(string.Format("  CPU: main <b>{0:F1}</b>ms  render thread {1:F1}ms\n", GameViewGUI.m_ClientFrameTime * 1000f, GameViewGUI.m_RenderFrameTime * 1000f));
            }
            else
            {
                stringBuilder2.Append(string.Format("  CPU: main {0:F1}ms  render thread <b>{1:F1}</b>ms\n", GameViewGUI.m_ClientFrameTime * 1000f, GameViewGUI.m_RenderFrameTime * 1000f));
            }
            stringBuilder2.Append(string.Format("  Batches: <b>{0}</b> \tSaved by batching: {1}\n", UnityStats.batches, num4 + num5 + num6));
            stringBuilder2.Append(string.Format("  Tris: {0} \tVerts: {1} \n", GameViewGUI.FormatNumber(UnityStats.trianglesLong), GameViewGUI.FormatNumber(UnityStats.verticesLong)));
            stringBuilder2.Append(string.Format("  Screen: {0} - {1}\n", UnityStats.screenRes, EditorUtility.FormatBytes(screenBytes)));
            stringBuilder2.Append(string.Format("  SetPass calls: {0} \tShadow casters: {1} \n", UnityStats.setPassCalls, UnityStats.shadowCasters));
            stringBuilder2.Append(string.Format("  Visible skinned meshes: {0}  Animations: {1}", UnityStats.visibleSkinnedMeshes, UnityStats.visibleAnimations));
            GUILayout.Label(stringBuilder2.ToString(), GameViewGUI.labelStyle, new GUILayoutOption[0]);
            if (num3 != 0)
            {
                GUILayout.Label("Network:", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
                GUILayout.BeginHorizontal(new GUILayoutOption[0]);
                for (int i = 0; i < num3; i++)
                {
                    GUILayout.Label(UnityStats.GetNetworkStats(i), new GUILayoutOption[0]);
                }
                GUILayout.EndHorizontal();
            }
            else
            {
                GUILayout.Label("Network: (no players connected)", GameViewGUI.sectionHeaderStyle, new GUILayoutOption[0]);
            }
            GUILayout.EndArea();
        }
示例#7
0
        private void OnGUI()
        {
            if (GameView.s_GizmoButtonStyle == null)
            {
                GameView.s_GizmoButtonStyle                 = "GV Gizmo DropDown";
                GameView.s_ResolutionWarningStyle           = new GUIStyle("PreOverlayLabel");
                GameView.s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft;
                GameView.s_ResolutionWarningStyle.padding   = new RectOffset(6, 6, 1, 1);
            }
            this.DoToolbarGUI();
            Rect gameViewRenderRect = this.gameViewRenderRect;
            bool fitsInsideRect;
            Rect constrainedGameViewRenderRect = GameView.GetConstrainedGameViewRenderRect(gameViewRenderRect, this.selectedSizeIndex, out fitsInsideRect);
            Rect rect = GUIClip.Unclip(constrainedGameViewRenderRect);

            base.SetInternalGameViewRect(rect);
            EditorGUIUtility.AddCursorRect(constrainedGameViewRenderRect, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if (type == EventType.MouseDown && gameViewRenderRect.Contains(Event.current.mousePosition))
            {
                Unsupported.SetAllowCursorLock(true);
                Unsupported.SetAllowCursorHide(true);
            }
            else
            {
                if (type == EventType.KeyDown && Event.current.keyCode == KeyCode.Escape)
                {
                    Unsupported.SetAllowCursorLock(false);
                }
            }
            if (type == EventType.Repaint)
            {
                if (!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera())
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                }
                Vector2 s_EditorScreenPointOffset = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState savedGUIState = SavedGUIState.Create();
                if (Display.MultiDisplayLicense())
                {
                    EditorGUIUtility.RenderGameViewCameras(rect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCameras(rect, 0, this.m_Gizmos, true);
                }
                savedGUIState.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = s_EditorScreenPointOffset;
            }
            else
            {
                if (type != EventType.Layout && type != EventType.Used)
                {
                    if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                    {
                        return;
                    }
                    bool flag = constrainedGameViewRenderRect.Contains(Event.current.mousePosition);
                    if (Event.current.rawType == EventType.MouseDown && !flag)
                    {
                        return;
                    }
                    Event.current.mousePosition = new Vector2(Event.current.mousePosition.x - constrainedGameViewRenderRect.x, Event.current.mousePosition.y - constrainedGameViewRenderRect.y);
                    EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                    bool flag2 = true;
                    if (Event.current.rawType == EventType.MouseUp && !flag)
                    {
                        flag2 = false;
                    }
                    if (type == EventType.ExecuteCommand || type == EventType.ValidateCommand)
                    {
                        flag2 = false;
                    }
                    if (flag2)
                    {
                        Event.current.Use();
                    }
                    else
                    {
                        Event.current.mousePosition = new Vector2(Event.current.mousePosition.x + constrainedGameViewRenderRect.x, Event.current.mousePosition.y + constrainedGameViewRenderRect.y);
                    }
                }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), fitsInsideRect, constrainedGameViewRenderRect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }
示例#8
0
        private void OnGUI()
        {
            bool flag;

            if (s_GizmoButtonStyle == null)
            {
                s_GizmoButtonStyle                 = "GV Gizmo DropDown";
                s_ResolutionWarningStyle           = new GUIStyle("PreOverlayLabel");
                s_ResolutionWarningStyle.alignment = TextAnchor.UpperLeft;
                s_ResolutionWarningStyle.padding   = new RectOffset(6, 6, 1, 1);
            }
            this.DoToolbarGUI();
            Rect gameViewRenderRect = this.gameViewRenderRect;
            Rect rect       = GetConstrainedGameViewRenderRect(EditorGUIUtility.PointsToPixels(gameViewRenderRect), this.selectedSizeIndex, out flag);
            Rect rect4      = EditorGUIUtility.PixelsToPoints(rect);
            Rect rect5      = GUIClip.Unclip(rect4);
            Rect cameraRect = EditorGUIUtility.PointsToPixels(rect5);

            base.SetInternalGameViewRect(rect5);
            EditorGUIUtility.AddCursorRect(rect4, MouseCursor.CustomCursor);
            EventType type = Event.current.type;

            if ((type == EventType.MouseDown) && gameViewRenderRect.Contains(Event.current.mousePosition))
            {
                this.AllowCursorLockAndHide(true);
            }
            else if ((type == EventType.KeyDown) && (Event.current.keyCode == KeyCode.Escape))
            {
                Unsupported.SetAllowCursorLock(false);
            }
            switch (type)
            {
            case EventType.Layout:
            case EventType.Used:
                break;

            case EventType.Repaint:
            {
                bool flag2 = EditorGUIUtility.IsDisplayReferencedByCameras(this.m_TargetDisplay);
                if ((!this.currentGameViewSize.isFreeAspectRatio || !InternalEditorUtility.HasFullscreenCamera()) || !flag2)
                {
                    GUI.Box(gameViewRenderRect, GUIContent.none, "GameViewBackground");
                    if (!flag2)
                    {
                        GUI.Label(new Rect((gameViewRenderRect.width / 2f) - 50f, (gameViewRenderRect.height / 2f) - 10f, 200f, 50f), "No camera");
                    }
                }
                Vector2 vector = GUIUtility.s_EditorScreenPointOffset;
                GUIUtility.s_EditorScreenPointOffset = Vector2.zero;
                SavedGUIState state = SavedGUIState.Create();
                if (this.ShouldShowMultiDisplayOption())
                {
                    EditorGUIUtility.RenderGameViewCameras(cameraRect, this.m_TargetDisplay, this.m_Gizmos, true);
                }
                else
                {
                    EditorGUIUtility.RenderGameViewCameras(cameraRect, 0, this.m_Gizmos, true);
                }
                GL.sRGBWrite = false;
                state.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = vector;
                break;
            }

            default:
            {
                if (WindowLayout.s_MaximizeKey.activated && (!EditorApplication.isPlaying || EditorApplication.isPaused))
                {
                    return;
                }
                bool flag3 = rect4.Contains(Event.current.mousePosition);
                if ((Event.current.rawType == EventType.MouseDown) && !flag3)
                {
                    return;
                }
                Vector2 mousePosition = Event.current.mousePosition;
                Vector2 position      = mousePosition - rect4.position;
                position = EditorGUIUtility.PointsToPixels(position);
                Event.current.mousePosition = position;
                EditorGUIUtility.QueueGameViewInputEvent(Event.current);
                bool flag4 = true;
                if ((Event.current.rawType == EventType.MouseUp) && !flag3)
                {
                    flag4 = false;
                }
                switch (type)
                {
                case EventType.ExecuteCommand:
                case EventType.ValidateCommand:
                    flag4 = false;
                    break;
                }
                if (flag4)
                {
                    Event.current.Use();
                }
                else
                {
                    Event.current.mousePosition = mousePosition;
                }
                break;
            }
            }
            this.ShowResolutionWarning(new Rect(gameViewRenderRect.x, gameViewRenderRect.y, 200f, 20f), flag, rect.size);
            if (this.m_Stats)
            {
                GameViewGUI.GameViewStatsGUI();
            }
        }