The “Immediate Mode” GUI system (also known as IMGUI) is an entirely separate feature to Unity’s main GameObject-based UI System. IMGUI is a code-driven GUI system, and is mainly intended as a tool for programmers. It is driven by calls to the OnGUI function on any script which implements it. For example, this code:
void OnGUI() {
if (GUILayout.Button("Press Me"))
Debug.Log("Hello!");
}
Resultaría en un botón mostrado como:
El sistema de Immediate Mode GUI se utiliza comúnmente para:
The IMGUI system is not generally intended to be used for normal in-game user interfaces that players might use and interact with. For that you should use Unity’s main GameObject-based UI system, which offers a GameObject-based approach for editing and positioning UI elements, and has far better tools to work with the visual design and layout of the UI.
“Immediate Mode” refers to the way the IMGUI is created and drawn. To create IMGUI elements, you must write code that goes into a special function named OnGUI. The code to display the interface is executed every frame, and drawn to the screen. There are no persistent gameobjects other than the object to which your OnGUI code is attached, or other types of objects in the hierarchy related to the visual elements that are drawn.
El Legacy GUI le permite crear una amplia variedad de interfaces gráficas de usuario funcionales utilizando código. En lugar de crear un objeto de interfaz gráfica de usuario, manualmente posicionándola, y luego escribir un script que se encarga de su funcionalidad, se puede hacer todo a la vez con sólo unas pocas líneas de código. El código produce GUI controls que son instanciados, posicionados y manejados con una sola llamada de una función.
Esta sección explica cómo utilizar GUI, tanto en su juego y en las extensiones al editor Unity.