> module
std::stub::unity::egui
egui overlay for Unity (Il2Cpp) games
std::stub::unity::egui draws an egui immediate-mode GUI inside a Unity Il2Cpp game, rendered by the game itself. Call init() in ctor() to install the render hooks, then run() in stub_main() to enter the draw loop.
Each frame the game's render thread hands its egui context to the run() thread and waits until the draw function returns, so the draw function runs on the script thread but in lockstep with the game. Work queued for the main thread (e.g. Method.invoke_on_main()) is drained while the render thread waits.
The draw function receives a Ctx; its windows, widgets and textures are the std::gui ones — see xur.std.gui(7). This module also gives Ctx a key(name) method that is true while a key is held, read from Unity's input. Key names (case-insensitive): f1–f6, escape/esc, space, tab, return/enter, backspace, insert/ins, delete/del, home, end, left, right, up, down, lshift, rshift, lctrl, rctrl, lalt, ralt. Unknown names are never pressed.
> functions
The number of frames the overlay hook has seen since init(), counted whether or not run() has started; 0 before init().
init()Install the egui render hooks. Call it from ctor(), before the game's Il2Cpp runtime starts. It also hooks Application.Quit so run() returns when the game exits.
Register a Unity texture object (e.g. a Texture2D or RenderTexture) for drawing with Ui.image(). Returns a Texture::User handle; the object is GC-pinned until it is unregistered.
Enter the draw loop: calls draw once per rendered frame with a Ctx. Blocks until the game shuts down. Raises if init() wasn't called. A runtime error in draw is logged and shown in an "xur error" window for that frame; the loop keeps going.
Set the overlay's UI scale (1.0 = default). Fails with EguiError::InvalidScale if factor is not positive.
> types
> examples
use std::stub::unity::egui;
use std::log;
fn ctor() {
egui::init();
}
fn stub_main() {
let visible = true;
let f1_down = false;
egui::run(|ctx| {
let f1 = ctx.key("f1");
if f1 && !f1_down { visible = !visible; }
f1_down = f1;
if !visible { return; }
ctx.window_sized("My Mod", 300.0, |ui| {
ui.heading("Hello");
if ui.button("Click me") {
log::info("clicked!");
}
});
});
}