Add Edit GUI option to Game Window

#3269
This commit is contained in:
Wojtek Figat
2025-03-11 00:04:57 +01:00
parent a93085d6d6
commit cd72f4f19b

View File

@@ -21,7 +21,7 @@ namespace FlaxEditor.Windows
{ {
private readonly RenderOutputControl _viewport; private readonly RenderOutputControl _viewport;
private readonly GameRoot _guiRoot; private readonly GameRoot _guiRoot;
private bool _showGUI = true; private bool _showGUI = true, _editGUI = true;
private bool _showDebugDraw = false; private bool _showDebugDraw = false;
private bool _audioMuted = false; private bool _audioMuted = false;
private float _audioVolume = 1; private float _audioVolume = 1;
@@ -84,6 +84,22 @@ namespace FlaxEditor.Windows
} }
} }
/// <summary>
/// Gets or sets a value indicating whether allow editing game GUI in the view or keep it visible-only.
/// </summary>
public bool EditGUI
{
get => _editGUI;
set
{
if (value != _editGUI)
{
_editGUI = value;
_guiRoot.Editable = value;
}
}
}
/// <summary> /// <summary>
/// Gets or sets a value indicating whether show Debug Draw shapes in the view or keep it hidden. /// Gets or sets a value indicating whether show Debug Draw shapes in the view or keep it hidden.
/// </summary> /// </summary>
@@ -275,8 +291,9 @@ namespace FlaxEditor.Windows
/// </summary> /// </summary>
private class GameRoot : UIEditorRoot private class GameRoot : UIEditorRoot
{ {
public override bool EnableInputs => !Time.GamePaused && Editor.IsPlayMode; internal bool Editable = true;
public override bool EnableSelecting => !Editor.IsPlayMode || Time.GamePaused; public override bool EnableInputs => !Time.GamePaused && Editor.IsPlayMode && Editable;
public override bool EnableSelecting => (!Editor.IsPlayMode || Time.GamePaused) && Editable;
public override TransformGizmo TransformGizmo => Editor.Instance.MainTransformGizmo; public override TransformGizmo TransformGizmo => Editor.Instance.MainTransformGizmo;
} }
@@ -668,6 +685,13 @@ namespace FlaxEditor.Windows
checkbox.StateChanged += x => ShowGUI = x.Checked; checkbox.StateChanged += x => ShowGUI = x.Checked;
} }
// Edit GUI
{
var button = menu.AddButton("Edit GUI");
var checkbox = new CheckBox(140, 2, EditGUI) { Parent = button };
checkbox.StateChanged += x => EditGUI = x.Checked;
}
// Show Debug Draw // Show Debug Draw
{ {
var button = menu.AddButton("Show Debug Draw"); var button = menu.AddButton("Show Debug Draw");
@@ -1191,6 +1215,7 @@ namespace FlaxEditor.Windows
public override void OnLayoutSerialize(XmlWriter writer) public override void OnLayoutSerialize(XmlWriter writer)
{ {
writer.WriteAttributeString("ShowGUI", ShowGUI.ToString()); writer.WriteAttributeString("ShowGUI", ShowGUI.ToString());
writer.WriteAttributeString("EditGUI", EditGUI.ToString());
writer.WriteAttributeString("ShowDebugDraw", ShowDebugDraw.ToString()); writer.WriteAttributeString("ShowDebugDraw", ShowDebugDraw.ToString());
writer.WriteAttributeString("DefaultViewportScaling", JsonSerializer.Serialize(_defaultViewportScaling)); writer.WriteAttributeString("DefaultViewportScaling", JsonSerializer.Serialize(_defaultViewportScaling));
writer.WriteAttributeString("CustomViewportScaling", JsonSerializer.Serialize(_customViewportScaling)); writer.WriteAttributeString("CustomViewportScaling", JsonSerializer.Serialize(_customViewportScaling));
@@ -1201,6 +1226,8 @@ namespace FlaxEditor.Windows
{ {
if (bool.TryParse(node.GetAttribute("ShowGUI"), out bool value1)) if (bool.TryParse(node.GetAttribute("ShowGUI"), out bool value1))
ShowGUI = value1; ShowGUI = value1;
if (bool.TryParse(node.GetAttribute("EditGUI"), out value1))
EditGUI = value1;
if (bool.TryParse(node.GetAttribute("ShowDebugDraw"), out value1)) if (bool.TryParse(node.GetAttribute("ShowDebugDraw"), out value1))
ShowDebugDraw = value1; ShowDebugDraw = value1;
if (node.HasAttribute("CustomViewportScaling")) if (node.HasAttribute("CustomViewportScaling"))
@@ -1226,6 +1253,7 @@ namespace FlaxEditor.Windows
public override void OnLayoutDeserialize() public override void OnLayoutDeserialize()
{ {
ShowGUI = true; ShowGUI = true;
EditGUI = true;
ShowDebugDraw = false; ShowDebugDraw = false;
} }
} }