UImGui (Unity ImGui) is an UPM package for the immediate mode GUI library using ImGui.NET.
This a fork of UImGui, which that project is based off RG.ImGui. This project use FreeType as the default renderer.
Using ImGui 1.87
Dear ImGui is a bloat-free graphical user interface library for C . It outputs optimized vertex buffers that you can render anytime in your 3D-pipeline enabled application. It is fast, portable, renderer agnostic and self-contained (no external dependencies).
Dear ImGui is designed to enable fast iterations and to empower programmers to create content creation tools and visualization / debug tools (as opposed to UI for the average end-user). It favors simplicity and productivity toward this goal, and lacks certain features normally found in more high-level libraries.
Feature | RG | UImGui |
---|---|---|
IL2CPP | ❌ | ✔️ |
Windows | ✔️ | ✔️ |
Linux | ✔️ | ✔️ (Needs Freetype2 Installed) |
MacOS | ✔️ | ❌ |
Custom Assert | ✔️ | ❌ |
Unity Input Manager | ✔️ | ✔️ |
Unity Input System | ✔️ | ✔️ |
Docking | ❌ | ✔️ |
RenderPipeline Built in | ✔️ | ✔️ |
RenderPipeline URP | ❌ | ✔️ |
RenderPipeline HDRP | ❌ | ✔️ |
Renderer Mesh | ✔️ | ✔️ |
Renderer Procedural | ~ | ✔️ |
FreeType | ~ | ✔️ |
Image / Texture | ❌ | ✔️ |
- Setup UnityNuGet.
- Add package from git URL:
https://github.com/Voltstro-Studios/uimgui.git
. - Add
UImGui
component to the scene. - (Optional) Set
Platform Type
toInput System
if you're using the new input system. - You're ready. Look at the Example section for more usage samples.
- Add a
Render Im Gui Feature
render feature to the renderer asset. - Assign it to the
render feature
field of the DearImGui component. - Check this issue which I describe how to make it work step by step.
When using the High Definition Render Pipeline
:
- Add a script called Custom Pass Volume anywhere in your scene.
- Add "DearImGuiPass".
- Update Injection Point to before or after post processing.
- You're good to go.
You can subscribe to global layout or for a specific UImGui
context:
If choose to use global, don't to forget to set Do Global Events
to true
on UImGui
instance.
using UImGui;
using ImGuiNET;
using UnityEngine;
public class StaticSample : MonoBehaviour
{
private void Awake()
{
UImGuiUtility.Layout = OnLayout;
}
private void OnLayout(UImGui.UImGui obj)
{
// Unity Update method.
// Your code belongs here! Like ImGui.Begin... etc.
ImGui.ShowDemoWindow();
}
private void OnInitialize(UImGui.UImGui obj)
{
// runs after UImGui.OnEnable();
}
private void OnDeinitialize(UImGui.UImGui obj)
{
// runs after UImGui.OnDisable();
}
private void OnDisable()
{
UImGuiUtility.Layout -= OnLayout;
UImGuiUtility.OnInitialize -= OnInitialize;
UImGuiUtility.OnDeinitialize -= OnDeinitialize;
}
}
[SerializeField]
private float sliderFloatValue = 1;
[SerializeField]
private string inputText;
// Add listeners, etc ...
private void OnLayout(UImGui.UImGui obj)
{
ImGui.Text($"Hello, world {123}");
if (ImGui.Button("Save"))
{
Debug.Log("Save");
}
ImGui.InputText("string", ref inputText, 100);
ImGui.SliderFloat("float", ref sliderFloatValue, 0.0f, 1.0f);
}
[SerializeField] private Vector4 myColor;
private bool isOpen;
private void OnLayout(UImGui.UImGui obj)
{
// Create a window called "My First Tool", with a menu bar.
ImGui.Begin("My First Tool", ref isOpen, ImGuiWindowFlags.MenuBar);
if (ImGui.BeginMenuBar())
{
if (ImGui.BeginMenu("File"))
{
if (ImGui.MenuItem("Open..", "Ctrl O"))
{
/* Do stuff */
}
if (ImGui.MenuItem("Save", "Ctrl S"))
{
/* Do stuff */
}
if (ImGui.MenuItem("Close", "Ctrl W"))
{
isOpen = false;
}
ImGui.EndMenu();
}
ImGui.EndMenuBar();
}
// Edit a color (stored as ~4 floats)
ImGui.ColorEdit4("Color", ref myColor);
// Plot some values
float[] myValues = new float[] { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
ImGui.PlotLines("Frame Times", ref myValues[0], myValues.Length);
// Display contents in a scrolling region
ImGui.TextColored(new Vector4(1, 1, 0, 1), "Important Stuff");
ImGui.BeginChild("Scrolling");
for (int n = 0; n < 50; n )
ImGui.Text($"{n}: Some text");
ImGui.EndChild();
ImGui.End();
}
[SerializeField]
private Texture sampleTexture;
private void OnLayout(UImGui.UImGui obj)
{
if (ImGui.Begin("Image Sample"))
{
System.IntPtr id = UImGuiUtility.GetTextureId(sampleTexture);
Vector2 size = new Vector2(sampleTexture.width, sampleTexture.height)
ImGui.Image(id, size);
ImGui.End();
}
}
[Serializable]
private struct UserData
{
public int SomeCoolValue;
}
[SerializeField]
private UserData _userData;
private string _input = "";
// Add Listeners... etc.
private unsafe void OnInitialize(UImGui.UImGui uimgui)
{
fixed (UserData* ptr = &_userData)
{
uimgui.SetUserData((IntPtr)ptr);
}
}
private unsafe void OnLayout(UImGui.UImGui obj)
{
if (ImGui.Begin("Custom UserData"))
{
fixed (UserData* ptr = &_userData)
{
ImGuiInputTextCallback customCallback = CustomCallback;
ImGui.InputText("label", ref _input, 100, ~(ImGuiInputTextFlags)0, customCallback, (IntPtr)ptr);
}
ImGui.End();
}
}
private unsafe int CustomCallback(ImGuiInputTextCallbackData* data)
{
IntPtr userDataPtr = (IntPtr)data->UserData;
if (userDataPtr != IntPtr.Zero)
{
UserData userData = Marshal.PtrToStructure<UserData>(userDataPtr);
Debug.Log(userData.SomeCoolValue);
}
// You must to overwrite how you handle with new inputs.
// ...
return 1;
}
Thanks
Check here for more information
First create a method with ImGuiIOPtr like this
public void AddJapaneseFont(ImGuiIOPtr io)
{
// you can put on StreamingAssetsFolder and call from there like:
//string fontPath = $"{Application.streamingAssetsPath}/NotoSansCJKjp - Medium.otf";
string fontPath = "D:\\Users\\rofli.souza\\Desktop\\NotoSansCJKjp-Medium.otf";
io.Fonts.AddFontFromFileTTF(fontPath, 18, null, io.Fonts.GetGlyphRangesJapanese());
// you can create a configs and do a lot of stuffs
//ImFontConfig fontConfig = default;
//ImFontConfigPtr fontConfigPtr = new ImFontConfigPtr(&fontConfig);
//fontConfigPtr.MergeMode = true;
//io.Fonts.AddFontDefault(fontConfigPtr);
//int[] icons = { 0xf000, 0xf3ff, 0 };
//fixed (void* iconsPtr = icons)
//{
// io.Fonts.AddFontFromFileTTF("fontawesome-webfont.ttf", 18.0f, fontConfigPtr, (System.IntPtr)iconsPtr);
//}
}
Assign the object that contain these method in UImGui script
Create an awesome text:
if (ImGui.Begin("ウィンドウテスト"))
{
ImGui.Text("こんにちは!テスト");
ImGui.End();
}
Yay!
You can see more samples here.
- realgamessoftware - Initial work of RG.ImGui - realgamessoftware
- psydack - Initial work - psydack
- Voltstro - This fork's maintainer - Voltstro
This project is licensed under the MIT License - see the LICENSE.md file for details.