public void RenderToHMDOnly() { ConfigureTargetTexture((int)targetSize.x, (int)targetSize.y); if (m_TargetTexture.IsCreated()) { var gizmos = false; var targetDisplay = 0; var sendInput = false; EditorGUIUtility.RenderGameViewCamerasInternal( m_TargetTexture, targetDisplay, GUIClip.Unclip(viewInWindow), Vector2.zero, gizmos, sendInput); } }
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 (position.size * EditorGUIUtility.pixelsPerPoint != m_LastWindowPixelSize) // pixelsPerPoint only reliable in OnGUI() { UpdateZoomAreaAndParent(); } DoToolbarGUI(); // Setup game view dimensions, so that player loop can use it for input CopyDimensionsToParentView(); // 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; } var editorMousePosition = Event.current.mousePosition; var gameMousePosition = WindowToGameMousePosition(editorMousePosition); GUI.color = Color.white; // Get rid of play mode tint var originalEventType = Event.current.type; m_ZoomArea.BeginViewGUI(); 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(); ConfigureTargetTexture((int)targetSize.x, (int)targetSize.y); if (m_ClearInEditMode && !EditorApplication.isPlaying) { ClearTargetTexture(); } var currentTargetDisplay = 0; if (ModuleManager.ShouldShowMultiDisplayOption()) { // Display Targets can have valid targets from 0 to 7. System.Diagnostics.Debug.Assert(m_TargetDisplay < 8, "Display Target is Out of Range"); currentTargetDisplay = m_TargetDisplay; } if (m_TargetTexture.IsCreated()) { EditorGUIUtility.RenderGameViewCamerasInternal(m_TargetTexture, currentTargetDisplay, GUIClip.Unclip(viewInWindow), gameMousePosition, m_Gizmos); oldState.ApplyAndForget(); GUIUtility.s_EditorScreenPointOffset = oldOffset; GUI.BeginGroup(m_ZoomArea.drawRect); // Actually draw the game view to the screen, without alpha blending Graphics.DrawTexture(deviceFlippedTargetInView, m_TargetTexture, 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 (WindowLayout.s_MaximizeKey.activated) { if (!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 = m_TargetDisplay; EditorGUIUtility.QueueGameViewInputEvent(Event.current); bool useEvent = true; // 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. if (Event.current.rawType == EventType.MouseUp && !mousePosInGameViewRect) { useEvent = false; } // 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_TargetTexture) { if (m_ZoomArea.scale.y < 1f) { m_TargetTexture.filterMode = FilterMode.Bilinear; } else { m_TargetTexture.filterMode = FilterMode.Point; } } if (m_NoCameraWarning && !EditorGUIUtility.IsDisplayReferencedByCameras(m_TargetDisplay)) { GUI.Label(warningPosition, GUIContent.none, EditorStyles.notificationBackground); var displayName = ModuleManager.ShouldShowMultiDisplayOption() ? DisplayUtility.GetDisplayNames()[m_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 (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(); } }
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(); } }