Bare-bone implementation of ImGui and a couple of debug tools for Stride
- Add this repo as a submodule of your game's repo.
- Add a project reference pointing to this project inside your game's .csproj.
- Reference Hexa.NET.ImGui's nuget package in your game's project, see below.
<ProjectReference Include="..\StrideCommunity.ImGuiDebug\StrideCommunity.ImGuiDebug.csproj" />
- Start ImGui within your game's BeginRun():
using StrideCommunity.ImGuiDebug;
protected override void BeginRun()
{
base.BeginRun();
new ImGuiSystem( Services, GraphicsDeviceManager );
}
Builtin Debug interfaces:
new HierarchyView( Services );
new PerfMonitor( Services );
Inspector.FindFreeInspector( Services ).Target = objectToInspect;
Example interface implementation:
using System.Numerics;
using static Hexa.NET.ImGui.ImGui;
using static StrideCommunity.ImGuiDebug.ImGuiExtension;
public class YourInterface : StrideCommunity.ImGuiDebug.BaseWindow
{
bool my_tool_active;
Vector4 my_color;
float[] my_values = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
public YourInterface( Stride.Core.IServiceRegistry services ) : base( services )
{
}
protected override void OnDestroy()
{
}
protected override void OnDraw( bool collapsed )
{
if( collapsed )
return;
if( BeginMenuBar() )
{
if( BeginMenu( "File" ) )
{
if( MenuItem( "Open..", "Ctrl+O" ) ) { /* Do stuff */ }
if( MenuItem( "Save", "Ctrl+S" ) ) { /* Do stuff */ }
if( MenuItem( "Close", "Ctrl+W" ) ) { my_tool_active = false; }
EndMenu();
}
EndMenuBar();
}
// Edit a color (stored as ~4 floats)
ColorEdit4( "Color", ref my_color );
// Plot some values
PlotLines( "Frame Times", ref my_values[ 0 ], my_values.Length );
// Display contents in a scrolling region
TextColored( new Vector4( 1, 1, 0, 1 ), "Important Stuff" );
using( Child() )
{
for( int n = 0; n < 50; n++ )
Text( $"{n}: Some text" );
}
}
}
Add the Hexa.NET.ImNodes package
dotnet add package Hexa.NET.ImNodes
In your Game class add the ImNodes
context after the ImGuiSystem
and add the context to ImNodes
protected override void BeginRun()
{
base.BeginRun();
var imGuiSystem = new ImGuiSystem(Services, GraphicsDeviceManager);
ImNodesContextPtr = ImNodes.CreateContext();
ImNodes.SetImGuiContext(imGuiSystem.ImGuiContext);
}
Create ImNodes widgets as needed
using Hexa.NET.ImNodes;
using Stride.Core;
using StrideCommunity.ImGuiDebug;
using static Hexa.NET.ImGui.ImGui;
using static Hexa.NET.ImNodes.ImNodes;
namespace StrideVisualScripting.ImGuiWindows;
public class HelloNodesWindow : BaseWindow
{
private System.Numerics.Vector2 nodePos = new System.Numerics.Vector2(200, 100);
private System.Numerics.Vector3 Color = System.Numerics.Vector3.Zero;
private ImNodesEditorContextPtr _context;
public HelloNodesWindow(IServiceRegistry services) : base(services)
{
_context = EditorContextCreate();
}
protected override void OnDestroy() { }
protected override void OnDraw(bool collapsed)
{
Text("Hello World!");
BeginNodeEditor();
EditorContextSet(_context);
BeginNode(1);
BeginOutputAttribute(1);
Text("Attribute Pin");
EndOutputAttribute();
EndNode();
BeginNode(2);
SetNodeGridSpacePos(2, nodePos);
BeginInputAttribute(2);
Text("Attribute Pin");
EndInputAttribute();
SetNextItemWidth(100f * Scale);
ColorPicker3("Test", ref Color);
EndNode();
Link(0, 1, 2);
EndNodeEditor();
nodePos = GetNodeEditorSpacePos(2);
}
}