Add option to show Debug Draw shapes in Game Viewport
This commit is contained in:
@@ -165,6 +165,11 @@ namespace FlaxEditor.Viewport
|
||||
/// </summary>
|
||||
public bool DrawDebugDraw = true;
|
||||
|
||||
/// <summary>
|
||||
/// Gets the debug draw data for the viewport.
|
||||
/// </summary>
|
||||
public ViewportDebugDrawData DebugDrawData => _debugDrawData;
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether show navigation mesh.
|
||||
/// </summary>
|
||||
|
||||
@@ -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;
|
||||
|
||||
/// <summary>
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Gets or sets a value indicating whether show Debug Draw shapes in the view or keep it hidden.
|
||||
/// </summary>
|
||||
public bool ShowDebugDraw
|
||||
{
|
||||
get => _showDebugDraw;
|
||||
set => _showDebugDraw = value;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
@@ -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;
|
||||
|
||||
@@ -84,7 +84,7 @@ public:
|
||||
/// <summary>
|
||||
/// The index of the frame when this task was last time rendered.
|
||||
/// </summary>
|
||||
uint64 LastUsedFrame = 0;
|
||||
API_FIELD(ReadOnly) uint64 LastUsedFrame = 0;
|
||||
|
||||
/// <summary>
|
||||
/// Action fired on task rendering.
|
||||
|
||||
Reference in New Issue
Block a user