diff --git a/Source/Editor/Viewport/MainEditorGizmoViewport.cs b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
index bd5d3ffa6..0c895640d 100644
--- a/Source/Editor/Viewport/MainEditorGizmoViewport.cs
+++ b/Source/Editor/Viewport/MainEditorGizmoViewport.cs
@@ -165,6 +165,11 @@ namespace FlaxEditor.Viewport
///
public bool DrawDebugDraw = true;
+ ///
+ /// Gets the debug draw data for the viewport.
+ ///
+ public ViewportDebugDrawData DebugDrawData => _debugDrawData;
+
///
/// Gets or sets a value indicating whether show navigation mesh.
///
diff --git a/Source/Editor/Windows/GameWindow.cs b/Source/Editor/Windows/GameWindow.cs
index 3b5ba4218..26cef2621 100644
--- a/Source/Editor/Windows/GameWindow.cs
+++ b/Source/Editor/Windows/GameWindow.cs
@@ -1,11 +1,11 @@
// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved.
+using System;
using FlaxEditor.GUI.ContextMenu;
using FlaxEditor.GUI.Input;
using FlaxEditor.Options;
using FlaxEngine;
using FlaxEngine.GUI;
-using FlaxEngine.Utilities;
namespace FlaxEditor.Windows
{
@@ -18,6 +18,7 @@ namespace FlaxEditor.Windows
private readonly RenderOutputControl _viewport;
private readonly GameRoot _guiRoot;
private bool _showGUI = true;
+ private bool _showDebugDraw = false;
private float _gameStartTime;
///
@@ -36,14 +37,20 @@ namespace FlaxEditor.Windows
if (value != _showGUI)
{
_showGUI = value;
-
- // Update root if it's in game
- //if (Editor.StateMachine.IsPlayMode)
- _guiRoot.Visible = value;
+ _guiRoot.Visible = value;
}
}
}
+ ///
+ /// Gets or sets a value indicating whether show Debug Draw shapes in the view or keep it hidden.
+ ///
+ public bool ShowDebugDraw
+ {
+ get => _showDebugDraw;
+ set => _showDebugDraw = value;
+ }
+
///
/// Gets or sets a value indicating whether center mouse position on window focus in play mode. Helps when working with games that lock mouse cursor.
///
@@ -191,6 +198,7 @@ namespace FlaxEditor.Windows
AutoFocus = false,
Parent = this
};
+ task.PostRender += OnPostRender;
// Override the game GUI root
_guiRoot = new GameRoot
@@ -214,6 +222,31 @@ namespace FlaxEditor.Windows
InputActions.Add(options => options.StepFrame, Editor.Simulation.RequestPlayOneFrame);
}
+ private void OnPostRender(GPUContext context, RenderContext renderContext)
+ {
+ // Debug Draw shapes
+ if (_showDebugDraw)
+ {
+ var task = _viewport.Task;
+
+ // Draw actors debug shapes manually if editor viewport is hidden (game viewport task is always rendered before editor viewports)
+ var editWindowViewport = Editor.Windows.EditWin.Viewport;
+ if (editWindowViewport.Task.LastUsedFrame != Engine.FrameCount)
+ {
+ unsafe
+ {
+ var drawDebugData = editWindowViewport.DebugDrawData;
+ fixed (IntPtr* actors = drawDebugData.ActorsPtrs)
+ {
+ DebugDraw.DrawActors(new IntPtr(actors), drawDebugData.ActorsCount, true);
+ }
+ }
+ }
+
+ DebugDraw.Draw(ref renderContext, task.OutputView);
+ }
+ }
+
private void OnOptionsChanged(EditorOptions options)
{
CenterMouseOnFocus = options.Interface.CenterMouseOnGameWinFocus;
@@ -282,12 +315,16 @@ namespace FlaxEditor.Windows
// Show GUI
{
- var showGui = menu.AddButton("Show GUI");
- var showGuiCheckbox = new CheckBox(140, 2, ShowGUI)
- {
- Parent = showGui
- };
- showGuiCheckbox.StateChanged += x => ShowGUI = x.Checked;
+ var button = menu.AddButton("Show GUI");
+ var checkbox = new CheckBox(140, 2, ShowGUI) { Parent = button };
+ checkbox.StateChanged += x => ShowGUI = x.Checked;
+ }
+
+ // Show Debug Draw
+ {
+ var button = menu.AddButton("Show Debug Draw");
+ var checkbox = new CheckBox(140, 2, ShowDebugDraw) { Parent = button };
+ checkbox.StateChanged += x => ShowDebugDraw = x.Checked;
}
menu.MinimumWidth = 200;
diff --git a/Source/Engine/Graphics/RenderTask.h b/Source/Engine/Graphics/RenderTask.h
index 96048bcc2..86fa20856 100644
--- a/Source/Engine/Graphics/RenderTask.h
+++ b/Source/Engine/Graphics/RenderTask.h
@@ -84,7 +84,7 @@ public:
///
/// The index of the frame when this task was last time rendered.
///
- uint64 LastUsedFrame = 0;
+ API_FIELD(ReadOnly) uint64 LastUsedFrame = 0;
///
/// Action fired on task rendering.