From 62e492452dec984851c654fc15bd385ea82bbbe3 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Thu, 12 Mar 2026 09:26:23 +0100 Subject: [PATCH] Add UI editor grid toggle --- Source/Editor/Gizmo/UIEditorGizmo.cs | 30 ++++++++++++------- .../Editor/Viewport/PrefabWindowViewport.cs | 3 +- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/Source/Editor/Gizmo/UIEditorGizmo.cs b/Source/Editor/Gizmo/UIEditorGizmo.cs index 765893bed..8307ec8de 100644 --- a/Source/Editor/Gizmo/UIEditorGizmo.cs +++ b/Source/Editor/Gizmo/UIEditorGizmo.cs @@ -180,6 +180,11 @@ namespace FlaxEditor /// public bool EnableCamera => _view != null && EnableBackground; + /// + /// True if enable grid drawing. + /// + public bool ShowGrid { get; set; } = true; + /// /// Transform gizmo to use sync with (selection, snapping, transformation settings). /// @@ -492,17 +497,20 @@ namespace FlaxEditor // Draw background Surface.VisjectSurface.DrawBackgroundDefault(Editor.Instance.UI.VisjectSurfaceBackground, Width, Height); - // Draw grid - var viewRect = GetClientArea(); - var upperLeft = _view.PointFromParent(viewRect.Location); - var bottomRight = _view.PointFromParent(viewRect.Size); - var min = Float2.Min(upperLeft, bottomRight); - var max = Float2.Max(upperLeft, bottomRight); - var pixelRange = (max - min) * ViewScale; - Render2D.PushClip(ref viewRect); - DrawAxis(Float2.UnitX, viewRect, min.X, max.X, pixelRange.X); - DrawAxis(Float2.UnitY, viewRect, min.Y, max.Y, pixelRange.Y); - Render2D.PopClip(); + if (ShowGrid) + { + // Draw grid + var viewRect = GetClientArea(); + var upperLeft = _view.PointFromParent(viewRect.Location); + var bottomRight = _view.PointFromParent(viewRect.Size); + var min = Float2.Min(upperLeft, bottomRight); + var max = Float2.Max(upperLeft, bottomRight); + var pixelRange = (max - min) * ViewScale; + Render2D.PushClip(ref viewRect); + DrawAxis(Float2.UnitX, viewRect, min.X, max.X, pixelRange.X); + DrawAxis(Float2.UnitY, viewRect, min.Y, max.Y, pixelRange.Y); + Render2D.PopClip(); + } } base.Draw(); diff --git a/Source/Editor/Viewport/PrefabWindowViewport.cs b/Source/Editor/Viewport/PrefabWindowViewport.cs index 7f2b1a471..a8bdc8f20 100644 --- a/Source/Editor/Viewport/PrefabWindowViewport.cs +++ b/Source/Editor/Viewport/PrefabWindowViewport.cs @@ -6,7 +6,6 @@ using System.Linq; using FlaxEditor.Content; using FlaxEditor.Gizmo; using FlaxEditor.GUI.ContextMenu; -using FlaxEditor.GUI.Input; using FlaxEditor.Modules; using FlaxEditor.SceneGraph; using FlaxEditor.Scripting; @@ -15,7 +14,6 @@ using FlaxEditor.Viewport.Previews; using FlaxEditor.Windows.Assets; using FlaxEngine; using FlaxEngine.GUI; -using FlaxEngine.Json; using Utils = FlaxEditor.Utilities.Utils; namespace FlaxEditor.Viewport @@ -185,6 +183,7 @@ namespace FlaxEditor.Viewport showGridButton.Clicked += () => { _gridGizmo.Enabled = !_gridGizmo.Enabled; + _uiRoot.ShowGrid = _gridGizmo.Enabled; showGridButton.Checked = _gridGizmo.Enabled; }; showGridButton.Checked = true;