Windows
This page uses GameObject from Unity. The glossary says what each one is.
A window is a screen the player sees over the game, with its own areas to fill. You open one with ModWindow.Open and give it your code to fill it. The controls can also be built in other places, not only in a window (see the next section).
ModWindow a screen over the game
Use Open to show a window, Find to get one back by its mod id and title, and Close to close it.
public sealed class ModWindow : MonoBehaviour
{
public static ModWindow Open(string modId, string title, WindowDock dock, Action<ModWindow> build);
public static ModWindow Find(string modId, string title);
public void Close();
public void Run(Action action);
public string ModId { get; }
public string Title { get; }
public WindowDock Dock { get; }
public bool Faulted { get; }
public WindowCloseReason CloseReason { get; }
public RectTransform Body { get; }
public RectTransform Side { get; }
public RectTransform Footer { get; }
public event Action Closed;
}
| Method | Returns | What it does |
|---|---|---|
Open(modId, title, dock, build) | ModWindow | Opens a window. Your build code fills it. |
Find(modId, title) | ModWindow | Gives the open window with this mod id and title, or null if none. |
Close() | void | Closes the window. |
Run(action) | void | Runs your code safely inside the window. |
| Property | Type | What it means |
|---|---|---|
ModId | string | The mod id the window was opened with. |
Title | string | The window’s title. |
Dock | WindowDock | Where the window sits. |
Faulted | bool | true when your code threw an error and the window closed. |
CloseReason | WindowCloseReason | Why the window closed. |
Body | RectTransform | The main area. Put your controls here. |
Side | RectTransform | The left column of a Full window. |
Footer | RectTransform | A bar along the bottom of the window. |
| Event | Gives you | When it fires |
|---|---|---|
Closed | Nothing, it carries no value. | The window has closed. |
WindowDock where a window sits
ModWindow.Open takes one of these to choose where the window sits on screen.
public enum WindowDock
{
Left,
Right,
Center,
Full
}
| Value | Meaning |
|---|---|
Left | A panel at the left of the screen. |
Right | A panel at the right of the screen. |
Center | A panel in the middle of the screen. |
Full | The whole screen. |
WindowCloseReason why a window closed
CloseReason holds one of these once the window has closed. Requested means your code called Close, and Fault means your code threw an error in the window.
public enum WindowCloseReason
{
Requested,
Escape,
SaveLoad,
SceneUnload,
Destroyed,
Fault
}
| Value | Meaning |
|---|---|
Requested | Your mod, or the player, closed it. |
Escape | The player pressed Escape. |
SaveLoad | A save was loaded. |
SceneUnload | The scene the window was opened in was unloaded. |
Destroyed | The window’s object was destroyed. |
Fault | Your code threw an error. |
Things to know
Opengives back the new window, ornullwhen it could not open one. It givesnullwhen a window with the same mod id and title is already open (that window is brought to the front instead), or when its set-up fails (the window is removed and the error is logged).- An open window turns off the game’s controls and shows the mouse cursor, and gives them back when it closes. If giving the controls back fails, the window releases the keys and the cursor itself, but only when nothing else is holding them off. (It calls
GameController.ControlsDisabled(gameObject, ShowCursor: true)and releases throughCoreInput.EnableControls. It also hides the game menu if it is showing.) - Your build code runs once, inside
Run. If it throws an error, the window closes with the reasonFault,Faultedbecomestrue, and the error is logged once. Closedfires before the window’s model previews are cleaned up. Your mod can save its own work there.- Escape closes only the top window, and not while a text field in it has focus.
Findlets you close a window from a hotkey.- A window closes with
SceneUnloadonly when the scene it was opened in is unloaded. Other scenes that are unloaded at the same time do not close it. (Unloads of other additive scenes are ignored.) - The window sizes are fixed.
LeftandRightare 440 pixels wide with 24 pixels of space around them, andRightstarts 110 pixels from the top.Centeris 640 pixels wide. - These three panels block clicks across their whole area.
Fullcovers the whole screen with a nearly solid dark backdrop that hides the game and blocks its clicks. (The backdrop has an alpha of 0.97.) Fullalso has a 440 pixel column on the left,Side, andBodyto its right. TheFooteris a 56 pixel bar along the bottom.