ApplyAndForget() private method

private ApplyAndForget ( ) : void
return void
示例#1
0
        void MakeModal()
        {
            // If we already have modal window up we don't need to setup another modal message loop
            if (ContainerWindow.s_Modal)
            {
                return;
            }

            try
            {
                ContainerWindow.s_Modal = true;

                SavedGUIState guiState = SavedGUIState.Create();
                // TODO need to promote this outside of UIE
                UnityEngine.UIElements.EventDispatcher.editorDispatcher.PushDispatcherContext();

                Internal_MakeModal(m_Parent.window);

                UnityEngine.UIElements.EventDispatcher.editorDispatcher.PopDispatcherContext();
                guiState.ApplyAndForget();
            }
            finally
            {
                ContainerWindow.s_Modal = false;
            }
        }
        public static DragAndDropVisualMode Drop(int dropDstId, params object[] args)
        {
            List <Delegate> handlers;
            SavedGUIState   guiState = SavedGUIState.Create();

            if (!m_DropDescriptors.TryGetValue(dropDstId, out handlers))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var dropResult = DragAndDropVisualMode.Rejected;

            for (var i = handlers.Count - 1; i >= 0; --i)
            {
                var handler = handlers[i];
                dropResult = (DragAndDropVisualMode)handler.DynamicInvoke(args);
                if (dropResult != DragAndDropVisualMode.None)
                {
                    break;
                }
            }

            guiState.ApplyAndForget();
            return(dropResult);
        }
        protected RenderTexture RenderView(Vector2 mousePosition, bool clearTexture)
        {
            using (var renderingView = new RenderingView(this))
            {
                SetPlayModeViewSize(targetSize);
                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;
                }

                ConfigureTargetTexture((int)targetSize.x, (int)targetSize.y, clearTexture, playModeViewName);

                if (Event.current == null || Event.current.type != EventType.Repaint)
                {
                    return(m_TargetTexture);
                }

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

                EditorGUIUtility.RenderPlayModeViewCamerasInternal(m_TargetTexture, currentTargetDisplay, mousePosition, showGizmos, renderIMGUI);

                oldState.ApplyAndForget();
                GUIUtility.s_EditorScreenPointOffset = oldOffset;

                return(m_TargetTexture);
            }
        }
示例#4
0
 private void SetupRectsFromSplitter()
 {
     if (base.children.Length != 0)
     {
         int   num       = 0;
         int   num2      = 0;
         int[] realSizes = this.splitState.realSizes;
         for (int i = 0; i < realSizes.Length; i++)
         {
             int num3 = realSizes[i];
             num2 += num3;
         }
         float num4 = 1f;
         if ((float)num2 > ((!this.vertical) ? base.position.width : base.position.height))
         {
             num4 = ((!this.vertical) ? base.position.width : base.position.height) / (float)num2;
         }
         SavedGUIState savedGUIState = SavedGUIState.Create();
         for (int j = 0; j < base.children.Length; j++)
         {
             int num5 = (int)Mathf.Round((float)this.splitState.realSizes[j] * num4);
             if (this.vertical)
             {
                 base.children[j].position = new Rect(0f, (float)num, base.position.width, (float)num5);
             }
             else
             {
                 base.children[j].position = new Rect((float)num, 0f, (float)num5, base.position.height);
             }
             num += num5;
         }
         savedGUIState.ApplyAndForget();
     }
 }
示例#5
0
 private void SetupRectsFromSplitter()
 {
     if (base.children.Length != 0)
     {
         int num  = 0;
         int num2 = 0;
         foreach (int num3 in this.splitState.realSizes)
         {
             num2 += num3;
         }
         float num5 = 1f;
         if (num2 > (!this.vertical ? base.position.width : base.position.height))
         {
             num5 = (!this.vertical ? base.position.width : base.position.height) / ((float)num2);
         }
         SavedGUIState state = SavedGUIState.Create();
         for (int i = 0; i < base.children.Length; i++)
         {
             int num7 = (int)Mathf.Round(this.splitState.realSizes[i] * num5);
             if (this.vertical)
             {
                 base.children[i].position = new Rect(0f, (float)num, base.position.width, (float)num7);
             }
             else
             {
                 base.children[i].position = new Rect((float)num, 0f, (float)num7, base.position.height);
             }
             num += num7;
         }
         state.ApplyAndForget();
     }
 }
示例#6
0
        void SetupRectsFromSplitter()
        {
            if (children.Length == 0)
            {
                return;
            }

            float cursor = 0;

            int total = 0;

            foreach (int size in splitState.realSizes)
            {
                total += size;
            }
            float scale = 1;

            if (total > (vertical ? position.height : position.width))
            {
                scale = (vertical ? position.height : position.width) / total;
            }

            // OSX webviews might trigger nested Repaint events when being resized
            // so we protected the GUI state at this level
            SavedGUIState state = SavedGUIState.Create();

            for (int i = 0; i < children.Length; i++)
            {
                cursor += PlaceView(i, cursor, Mathf.Round(splitState.realSizes[i] * scale));
            }

            state.ApplyAndForget();
        }
示例#7
0
        internal bool SendEvent(Event e)
        {
            int depth = SavedGUIState.Internal_GetGUIDepth();

            if (depth > 0)
            {
                SavedGUIState oldState = SavedGUIState.Create();
                var           retval   = Internal_SendEvent(e);
                if (retval)
                {
                    EditorApplication.SignalTick();
                }
                oldState.ApplyAndForget();
                return(retval);
            }

            {
                var retval = Internal_SendEvent(e);
                if (retval)
                {
                    EditorApplication.SignalTick();
                }
                return(retval);
            }
        }
        // Show modal editor window. Other windows will not be accessible until this one is closed.
        internal void ShowModal()
        {
            ShowWithMode(ShowMode.AuxWindow);
            SavedGUIState guiState = SavedGUIState.Create();

            MakeModal(m_Parent.window);
            guiState.ApplyAndForget();
        }
示例#9
0
        internal void ShowModal()
        {
            this.ShowWithMode(ShowMode.AuxWindow);
            SavedGUIState savedGUIState = SavedGUIState.Create();

            this.MakeModal(this.m_Parent.window);
            savedGUIState.ApplyAndForget();
        }
        // Show modal editor window. Other windows will not be accessible until this one is closed.
        internal void ShowModal()
        {
            ShowWithMode(ShowMode.AuxWindow);
            SavedGUIState guiState = SavedGUIState.Create();

            m_Parent.visualTree.panel.dispatcher?.PushDispatcherContext();
            MakeModal(m_Parent.window);
            m_Parent.visualTree.panel.dispatcher?.PopDispatcherContext();
            guiState.ApplyAndForget();
        }
示例#11
0
        internal bool SendEvent(Event e)
        {
            int  num  = SavedGUIState.Internal_GetGUIDepth();
            bool flag = false;

            if (num > 0)
            {
                SavedGUIState state = SavedGUIState.Create();
                flag = this.Internal_SendEvent(e);
                state.ApplyAndForget();
                return(flag);
            }
            return(this.Internal_SendEvent(e));
        }
示例#12
0
        internal bool SendEvent(Event e)
        {
            int depth = SavedGUIState.Internal_GetGUIDepth();

            if (depth > 0)
            {
                SavedGUIState oldState = SavedGUIState.Create();
                var           retval   = Internal_SendEvent(e);
                oldState.ApplyAndForget();
                return(retval);
            }

            return(Internal_SendEvent(e));
        }
示例#13
0
        internal bool SendEvent(Event e)
        {
            bool flag;

            if (SavedGUIState.Internal_GetGUIDepth() > 0)
            {
                SavedGUIState savedGuiState = SavedGUIState.Create();
                flag = this.Internal_SendEvent(e);
                savedGuiState.ApplyAndForget();
            }
            else
            {
                flag = this.Internal_SendEvent(e);
            }
            return(flag);
        }
示例#14
0
 internal void ShowWithMode(ShowMode mode)
 {
     if (this.m_Parent == null)
     {
         SavedGUIState   savedGUIState   = SavedGUIState.Create();
         ContainerWindow containerWindow = ScriptableObject.CreateInstance <ContainerWindow>();
         containerWindow.title = this.titleContent.text;
         HostView hostView = ScriptableObject.CreateInstance <HostView>();
         hostView.actualView = this;
         Rect position = this.m_Parent.borderSize.Add(new Rect(this.position.x, this.position.y, this.position.width, this.position.height));
         containerWindow.position = position;
         containerWindow.rootView = hostView;
         this.MakeParentsSettingsMatchMe();
         containerWindow.Show(mode, true, false);
         savedGUIState.ApplyAndForget();
     }
 }
示例#15
0
        internal bool SendEvent(Event e)
        {
            int  num = SavedGUIState.Internal_GetGUIDepth();
            bool result;

            if (num > 0)
            {
                SavedGUIState savedGUIState = SavedGUIState.Create();
                result = this.Internal_SendEvent(e);
                savedGUIState.ApplyAndForget();
            }
            else
            {
                result = this.Internal_SendEvent(e);
            }
            return(result);
        }
示例#16
0
        // Show modal editor window. Other windows will not be accessible until this one is closed.
        public void ShowModal()
        {
            ShowWithMode(ShowMode.AuxWindow);
            try
            {
                ContainerWindow.s_Modal = true;

                SavedGUIState guiState = SavedGUIState.Create();
                m_Parent.visualTree.panel.dispatcher?.PushDispatcherContext();

                MakeModal(m_Parent.window);

                m_Parent.visualTree.panel.dispatcher?.PopDispatcherContext();
                guiState.ApplyAndForget();
            }
            finally
            {
                ContainerWindow.s_Modal = false;
            }
        }
        void MakeModal()
        {
            try
            {
                ContainerWindow.s_Modal = true;

                SavedGUIState guiState = SavedGUIState.Create();
                // TODO need to promote this outside of UIE
                UnityEngine.UIElements.EventDispatcher.editorDispatcher.PushDispatcherContext();

                Internal_MakeModal(m_Parent.window);

                UnityEngine.UIElements.EventDispatcher.editorDispatcher.PopDispatcherContext();
                guiState.ApplyAndForget();
            }
            finally
            {
                ContainerWindow.s_Modal = false;
            }
        }
示例#18
0
        internal void ShowWithMode(ShowMode mode)
        {
            if (!((UnityEngine.Object) this.m_Parent == (UnityEngine.Object)null))
            {
                return;
            }
            SavedGUIState   savedGuiState = SavedGUIState.Create();
            ContainerWindow instance1     = ScriptableObject.CreateInstance <ContainerWindow>();

            instance1.title = this.titleContent.text;
            HostView instance2 = ScriptableObject.CreateInstance <HostView>();

            instance2.actualView = this;
            Rect rect = this.m_Parent.borderSize.Add(new Rect(this.position.x, this.position.y, this.position.width, this.position.height));

            instance1.position = rect;
            instance1.mainView = (View)instance2;
            this.MakeParentsSettingsMatchMe();
            instance1.Show(mode, true, false);
            savedGuiState.ApplyAndForget();
        }
        internal static DragAndDropVisualMode Drop(int dropDstId, params object[] args)
        {
            SavedGUIState guiState = SavedGUIState.Create();

            if (!dropHandlers.TryGetValue(dropDstId, out var handlers))
            {
                return(DragAndDropVisualMode.Rejected);
            }

            var dropResult = DragAndDropVisualMode.None;

            for (var i = handlers.Count - 1; i >= 0; --i)
            {
                var dropHandler = handlers[i];
                dropResult = (DragAndDropVisualMode)dropHandler.DynamicInvoke(args);
                if (dropResult != DragAndDropVisualMode.None)
                {
                    break;
                }
            }

            guiState.ApplyAndForget();
            return(dropResult);
        }
        internal void ShowWithMode(ShowMode mode)
        {
            if (m_Parent == null)
            {
                SavedGUIState oldState = SavedGUIState.Create();

                ContainerWindow cw = ScriptableObject.CreateInstance <ContainerWindow>();
                cw.title = titleContent.text;
                HostView host = ScriptableObject.CreateInstance <HostView>();
                host.actualView = this; // Among other things, this sets m_Parent to host

                Rect r = m_Parent.borderSize.Add(new Rect(position.x, position.y, position.width, position.height));
                // Order is important here: first set rect of container, then assign main view, then apply various settings, then show.
                // Otherwise the rect won't be set until first resize happens.
                cw.position = r;
                cw.rootView = host;
                MakeParentsSettingsMatchMe();
                cw.Show(mode, loadPosition: true, displayImmediately: false, setFocus: true);
                // set min/max size now that native window is not null so that it will e.g., use proper styleMask on macOS
                cw.SetMinMaxSizes(minSize, maxSize);

                oldState.ApplyAndForget();
            }
        }
示例#21
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();
            }
        }
示例#22
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();
            }
        }
示例#23
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();
            }
        }
示例#24
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();
            }
        }
示例#26
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();
            }
        }