internal static SavedGUIState Create() { SavedGUIState savedGuiState = new SavedGUIState(); if (SavedGUIState.Internal_GetGUIDepth() > 0) { savedGuiState.skin = GUI.skin; savedGuiState.layoutCache = new GUILayoutUtility.LayoutCache(GUILayoutUtility.current); SavedGUIState.Internal_SetupSavedGUIState(out savedGuiState.guiState, out savedGuiState.screenManagerSize); } return savedGuiState; }
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(); } }
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 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 (this.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); GL.sRGBWrite = (this.m_CurrentColorSpace == ColorSpace.Linear); GUI.DrawTexture(this.deviceFlippedTargetInView, this.m_TargetTexture, ScaleMode.StretchToFill, false); GL.sRGBWrite = false; 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; } 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; } } 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 = (!this.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; 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(); } }
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(); } }
private static void Internal_ApplySavedGUIState(IntPtr state, Vector2 screenManagerSize, Rect renderManagerRect) { SavedGUIState.INTERNAL_CALL_Internal_ApplySavedGUIState(state, ref screenManagerSize, ref renderManagerRect); }
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(); } }