Coding
This is an explanation to get started with RimGui.
class ManualEntry : MonoBehaviour
{
[SerializeField] ManualSO manualSO;
GuiHelper guiHelper;
Gui gui;
Context ctx;
public void Start()
{
guiHelper = new(
manualSO.CursorAssets,
manualSO.GuiShader,
manualSO.CircleSprite,
manualSO.FontSO,
Camera.main);
gui = guiHelper.Gui;
ctx = guiHelper.Gui.Ctx;
}
public void Update()
{
// Process Gui for this frame.
// Must be executed once at the beginning of the frame.
guiHelper.ProcessFrame();
// It is possible to execute Gui.Text() and other Gui functions freely between ProcessFrame() and CompleteFrame().
if (gui.BeginStandardWindow("Window"))
{
gui.Text("A");
gui.EndStandardWindow();
}
// Must be executed once at the end of the frame.
guiHelper.CompleteFrame();
}
void OnDestroy()
{
// Make sure to call Dispose().
guiHelper.Dispose();
}
}
Explanation of Each Process
1. Initialization in Start()
A GuiHelper
instance is created to set up the necessary resources for GUI rendering. GuiHelper
provides a Gui
object, which manages the Ctx
(context).
guiHelper = new(
manualSO.CursorAssets,
manualSO.GuiShader,
manualSO.CircleSprite,
manualSO.FontSO,
unityCamera);
gui = guiHelper.Gui;
ctx = guiHelper.Gui.Ctx;
2. GUI Processing in Update()
Starting Frame Processing
At the beginning of each frame, guiHelper.ProcessFrame()
is called. This resets the GUI state and prepares it for new frame rendering.
guiHelper.ProcessFrame();
Rendering the GUI
A standard window is created with Gui.BeginStandardWindow("Window")
, and Gui.Text("A")
displays text within the window.
if (gui.BeginStandardWindow("Window"))
{
gui.Text("A");
gui.EndStandardWindow();
}
Ending Frame Processing
At the end of the frame, guiHelper.CompleteFrame()
is called to finalize the rendering and reflect it on the screen.
guiHelper.CompleteFrame();
3. Releasing Resources in OnDestroy()
Calling guiHelper.Dispose()
ensures that GUI resources are properly released. Failure to do so may lead to memory leaks.
void OnDestroy()
{
guiHelper.Dispose();
}
Summary
- Use
GuiHelper
to initialize RimGui. - Call
ProcessFrame()
at the start of the frame, render the GUI, and callCompleteFrame()
at the end. - Ensure proper resource release by calling
Dispose()
.