IMGUI
“即時模式”GUI 系統(也稱為 IMGUI)是一個完全獨立的功能系統,不同于 Unity 基于游戲物件的主 UI 系統,IMGUI 是一個代碼驅動的 GUI 系統,主要用作程式員的工具,為了驅動該系統,需在實作腳本上呼叫 OnGUI 函式,
EditorWindow
1.繼承EditorWindow
2.EditorWindow.GetWindow(typeof(MyWindow)).Show()顯示視窗
3.在OnGui渲染視窗
GUILayout(編輯器,運行時可用)
GUILayout 類是 Unity GUI 的介面,并且具有自動布局功能,
UnityEngine.GUILayout - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/GUILayout.html
GUI(編輯器,運行時可用)
GUI 類是 Unity GUI 的介面,并且具有手動定位功能,(對比GUILayout需要多傳個Rect)
UnityEngine.GUI - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/GUI.html
EditorGUILayout(編輯器可用)
EditorGUI 的自動布局版本,
UnityEditor.EditorGUILayout - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/EditorGUILayout.html
EditorGUI(編輯器可用)
這些方法的運行方式與常規 GUI 函式十分相似,(對比 EditorGUILayout需要多傳個Rect)
UnityEditor.EditorGUI - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/EditorGUI.html
編輯器的簡易框架(可以讓你的編輯器更好的可視化管理)
using System;
using UnityEditor;
using UnityEngine;
public class MyWindow : EditorWindow
{
string myString = "Hello World";
bool groupEnabled;
bool myBool = true;
float myFloat = 1.23f;
bool isEnable = false;
bool isRotate = false;
bool isScale = false;
Color color;
//定義列舉
public enum ToolEnum
{
Basic,
Enable,
Rotate,
Scale,
Color,
Other,
}
ToolEnum selectId = ToolEnum.Basic;
[MenuItem("Window/My Window")]
static void Init()
{
MyWindow window = (MyWindow)EditorWindow.GetWindow(typeof(MyWindow));
window.Show();
}
void OnGUI()
{
//渲染Toolbar
selectId = (ToolEnum)GUILayout.Toolbar((int)selectId, Enum.GetNames(typeof(ToolEnum)));
if (selectId == ToolEnum.Basic)
{
Basic();
}
else if (selectId == ToolEnum.Enable)
{
isEnable = GUILayout.Toggle(isEnable, "IsEnable");
if (isEnable != GUI.enabled)
{
GUI.enabled = isEnable;
}
Basic();
}
else if (selectId == ToolEnum.Rotate)
{
isRotate = GUILayout.Toggle(isRotate, "IsRotate");
if (isRotate)
{
GUIUtility.RotateAroundPivot(45, new Vector2(100, 100));
}
Basic();
}
else if (selectId == ToolEnum.Scale)
{
isScale = GUILayout.Toggle(isScale, "IsScale");
if (isScale)
{
GUIUtility.ScaleAroundPivot(Vector2.one * 0.5f, new Vector2(100, 100));
}
Basic();
}
else if (selectId == ToolEnum.Color)
{
color = EditorGUILayout.ColorField(color);
GUI.color = color;
Basic();
}
}
private void Basic()
{
GUILayout.Label("Base Settings", EditorStyles.boldLabel);
myString = EditorGUILayout.TextField("Text Field", myString);
groupEnabled = EditorGUILayout.BeginToggleGroup("Optional Settings", groupEnabled);
myBool = EditorGUILayout.Toggle("Toggle", myBool);
myFloat = EditorGUILayout.Slider("Slider", myFloat, -3, 3);
EditorGUILayout.EndToggleGroup();
}
}
GUIContent
定義/渲染內容 ,包含圖示,文本,提示
UnityEngine.GUIContent - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/GUIContent.html
GUIStyle
定義/渲染方式,這讓您能夠更改或根據不同狀態(例如,當滑鼠懸停在控制元件上時)切換顏色、字體及其他細節,
UnityEngine.GUIStyle - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/GUIStyle.html
GUISkin
定義 GUI 的外觀和行為,GUISkin 包含 GUI 設定和 GUIStyle 物件的集合,它們共同指定 GUI 皮膚,
UnityEngine.GUISkin - Unity 腳本 API
https://docs.unity.cn/cn/current/ScriptReference/GUISkin.html
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/352030.html
標籤:其他
下一篇:我們如何學習 3:人生哲學
