-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add support for running ImGui in the Editor.
- Loading branch information
1 parent
1331798
commit d07996a
Showing
5 changed files
with
230 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#if TOOLS | ||
using Godot; | ||
using ImGuiNET; | ||
|
||
Check failure on line 4 in addons/imgui-godot/ImGuiGodot/ImGuiEditorPlugin.cs GitHub Actions / .NET 6.0.x
|
||
|
||
namespace ImGuiGodot; | ||
|
||
[Tool] | ||
public partial class ImGuiEditorPlugin : EditorPlugin { | ||
|
||
#region VARIABLES | ||
|
||
private ImGuiLayer _imguiLayerControl; | ||
private Callable _onImGuiLayoutCallback; | ||
|
||
#endregion | ||
|
||
|
||
Check failure on line 18 in addons/imgui-godot/ImGuiGodot/ImGuiEditorPlugin.cs GitHub Actions / .NET 6.0.x
|
||
#region EditorPlugin override | ||
|
||
public override void _Ready() { | ||
// Initialization of the plugin goes here. | ||
Init(); | ||
} | ||
|
||
public override void _EnterTree() { | ||
if ( !Engine.IsEditorHint() ) { | ||
AddAutoloadSingleton( "ImGuiLayer", "res://addons/imgui-godot/ImGuiLayer.tscn" ); | ||
} | ||
} | ||
|
||
public override void _ExitTree() { | ||
|
||
if ( !Engine.IsEditorHint() ) { | ||
RemoveAutoloadSingleton( "ImGuiLayer" ); | ||
} | ||
else { | ||
DeInit(); | ||
|
||
ImGuiLayer.Instance = null; | ||
} | ||
} | ||
|
||
public override void _Process( double delta ) { | ||
base._Process( delta ); | ||
UpdateOverlays(); | ||
} | ||
|
||
public override bool _HasMainScreen() => false; | ||
|
||
public override void _MakeVisible( bool visible ) { | ||
// if ( _imguiLayerControl != null ) { | ||
// _imguiLayerControl.Visible = visible; | ||
// } | ||
} | ||
|
||
public override string _GetPluginName() => "ImGui"; | ||
|
||
public override Texture2D _GetPluginIcon() { | ||
return EditorInterface.Singleton.GetBaseControl().GetThemeIcon( "ResourcePreloader", "EditorIcons" ); | ||
} | ||
|
||
|
||
#endregion | ||
|
||
|
||
private void Init() { | ||
_imguiLayerControl = new (); | ||
_imguiLayerControl.Layer = 128; | ||
_imguiLayerControl.ProcessMode = ProcessModeEnum.Always; | ||
_imguiLayerControl.Visible = true; | ||
_onImGuiLayoutCallback = new Callable( this, MethodName.OnImGuiLayout ); | ||
Check failure on line 72 in addons/imgui-godot/ImGuiGodot/ImGuiEditorPlugin.cs GitHub Actions / .NET 6.0.x
|
||
|
||
SetupWindow(); | ||
|
||
ImGuiLayer.Connect( _onImGuiLayoutCallback ); | ||
} | ||
|
||
private void DeInit() { | ||
// RemoveToolMenuItem( "Toggle ImGui" ); | ||
|
||
if ( _imguiLayerControl is not null ) { | ||
ImGuiLayer.Disconnect( _onImGuiLayoutCallback ); | ||
EditorInterface.Singleton.GetEditorMainScreen().RemoveChild( _imguiLayerControl ); | ||
_imguiLayerControl.Free(); | ||
_imguiLayerControl = null; | ||
} | ||
} | ||
|
||
private void SetupWindow() { | ||
if ( _imguiLayerControl is not null ) { | ||
EditorInterface.Singleton.GetEditorMainScreen().AddChild( _imguiLayerControl ); | ||
} | ||
|
||
// _MakeVisible( false ); | ||
} | ||
|
||
private void OnImGuiLayout() { | ||
// your code here | ||
ImGui.ShowDemoWindow(); | ||
} | ||
|
||
|
||
private void ToggleImGuiLayer() { | ||
if ( _imguiLayerControl is not null ) { | ||
_imguiLayerControl.Visible = !_imguiLayerControl.Visible; | ||
} | ||
} | ||
|
||
} | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters