Ui Imgui

unity-technologies/skills/skills/ui-imgui

作者 unity-technologiescb1dccb8f5ad無授權條款1K 個星標收錄於 2026年10月8日更新於 2026年10月8日儲存庫今天更新

Generates and modifies Unity IMGUI editor code such as EditorWindows, custom Inspectors, PropertyDrawers, and OnGUI scripts. Use for IMGUI or OnGUI or maintaining existing IMGUI code.

AI 產生的概覽

產生與修改舊版 Unity IMGUI 編輯器程式碼,例如 EditorWindow、自訂 Inspector、PropertyDrawer 與 OnGUI 指令碼。

功能
此技能引導代理撰寫與更新舊版 Unity IMGUI 編輯器程式碼,涵蓋含 OnGUI() 的 EditorWindow 類別、含 OnInspectorGUI() 的自訂 Editor 與 PropertyDrawer 類別,以及執行階段除錯疊層。它提供範本、版面配置模式、命名與資料夾慣例,以及快取 GUIStyle 物件、使用 SerializedProperty 支援復原等規則。除非使用者明確要求 IMGUI 或正在維護現有 IMGUI 程式碼,否則它也建議新的編輯器介面改用 UI Toolkit。
適用情境
適用於維護或更新含有 OnGUI() 或 OnInspectorGUI() 的現有 IMGUI 編輯器程式碼,或使用者明確要求 IMGUI 或即時模式 GUI 的情況。它不適用於新建編輯器視窗或 Inspector(應改用 UI Toolkit),也不適用於執行階段遊戲介面。
執行需求
不隨附指令碼,僅為指示文件與兩個參考檔案。需要 Unity 專案與 UnityEditor 命名空間,並假定產生的編輯器指令碼置於 Editor 資料夾中。

Before proceeding: If the user is asking about creating a new editor window, custom inspector, or PropertyDrawer without explicitly mentioning IMGUI/OnGUI, recommend using UI Toolkit (CreateGUI) instead, as it's the modern approach. Only proceed with IMGUI if:

  • User is modifying existing IMGUI code
  • User explicitly requests IMGUI/immediate mode
  • The project exclusively uses IMGUI for editor tools

When activated, read the reference files:

  • references/templates.md [blocked] — EditorWindow, Inspector, PropertyDrawer templates
  • references/gui-elements.md [blocked] — GUI elements, layout groups, styling

When to Use This Skill

IMPORTANT: This skill is for legacy IMGUI code only. Use this skill when:

  • User is maintaining/updating existing IMGUI editor code (files with OnGUI(), OnInspectorGUI())
  • User explicitly requests IMGUI/immediate mode GUI
  • Project exclusively uses IMGUI for all editor tools

Do NOT use this skill for:

  • New editor windows (use UI Toolkit with CreateGUI() instead)
  • New custom inspectors (use UI Toolkit instead)
  • Requests that don't explicitly mention IMGUI or OnGUI

Legacy IMGUI is used for:

  • Editor windows — EditorWindow classes with OnGUI()
  • Custom inspectors — Editor, PropertyDrawer classes with OnInspectorGUI()
  • Debug overlays — OnGUI() in MonoBehaviour (runtime)

IMGUI is not for runtime game UI — use UI Toolkit or uGUI instead.

Scope

Generate only what is requested (for legacy IMGUI code):

RequestOutputNote
Editor window (IMGUI/OnGUI)EditorWindow with OnGUI()Only if explicitly IMGUI
Custom inspector (IMGUI)Editor with OnInspectorGUI()Only if explicitly IMGUI
Property drawer (IMGUI)PropertyDrawer with OnGUI()Only if explicitly IMGUI
Debug overlayMonoBehaviour with OnGUI()Runtime debugging
Update existing IMGUI scriptModify existing OnGUI codeAlways appropriate

Clarify if ambiguous:

  • "inspector" → Custom Editor for a specific type, or PropertyDrawer? Also ask: Should this use UI Toolkit (modern) or IMGUI (legacy)?
  • "editor window" → First ask: Should this use UI Toolkit (modern/CreateGUI) or IMGUI (legacy/OnGUI)?
  • "tool window" → EditorWindow with what functionality? Which UI system?

Conventions

Follow project patterns first. Search existing editor scripts before applying defaults.

TypeConventionGoodBad
Script namesPascalCaseMyToolWindow.csmy-tool-window.cs
EditorWindow[Name]Window.csLevelEditorWindow.csLevelEditor.cs
Custom Editor[Type]Editor.csEnemyEditor.csEnemyInspector.cs
PropertyDrawer[Type]Drawer.csRangeDrawer.csRangePropertyDrawer.cs
LocationEditor folderAssets/Editor/Assets/Scripts/

Editor folder is required — Scripts using UnityEditor namespace must be in an Editor folder or they will fail to build.

Workflow

  1. Analyze — Determine script type needed (EditorWindow, Editor, PropertyDrawer, etc.)
  2. Search — Find existing editor scripts to match patterns
  3. Follow project patterns — Match folder structure and naming
  4. Create script — Use appropriate base class and attributes
  5. Implement OnGUI — Build the interface with layout groups

Script Structure

EditorWindow

[MenuItem attribute] → adds to menuShowWindow() static method → opens windowOnGUI() → draws interfaceOnEnable/OnDisable → initialization/cleanup

Custom Editor

[CustomEditor attribute] → targets component typeOnInspectorGUI() → draws inspectorOnEnable() → cache SerializedPropertiesserializedObject.Update/ApplyModifiedProperties → undo support

PropertyDrawer

[CustomPropertyDrawer attribute] → targets type or attributeOnGUI(Rect, SerializedProperty, GUIContent) → draws propertyGetPropertyHeight() → custom height if needed

Key Rules

  • Cache GUIStyle objects — never create new GUIStyle in OnGUI (causes memory allocation every frame)
  • Use SerializedProperty — for proper undo/redo support in inspectors
  • Call ApplyModifiedProperties() — after any serialized object changes
  • Use EditorGUILayout — for editor scripts (auto-layout)
  • Use GUILayout — for runtime OnGUI
  • Begin/End pairs — always match BeginHorizontal with EndHorizontal, etc.
  • Editor folder required — scripts fail to build if not in Editor folder

Layout Basics

Horizontal grouping:

csharp
EditorGUILayout.BeginHorizontal();// elements appear side by sideEditorGUILayout.EndHorizontal();

Vertical grouping:

csharp
EditorGUILayout.BeginVertical("box");// elements appear stacked, with box styleEditorGUILayout.EndVertical();

Scroll view:

csharp
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);// scrollable contentEditorGUILayout.EndScrollView();

Foldout section:

csharp
showSection = EditorGUILayout.Foldout(showSection, "Section Name");if (showSection){    EditorGUI.indentLevel++;    // section content    EditorGUI.indentLevel--;}

Common Patterns

Button with action:

csharp
if (GUILayout.Button("Do Something")){    // action here}

Property field with label:

csharp
EditorGUILayout.PropertyField(myProperty, new GUIContent("Label"));

Object reference field:

csharp
myObject = (MyType)EditorGUILayout.ObjectField("Label", myObject, typeof(MyType), true);

Disabled group:

csharp
EditorGUI.BeginDisabledGroup(condition);// disabled elementsEditorGUI.EndDisabledGroup();

Best Practices

  • Use SerializedObject and SerializedProperty for undo support
  • Cache property references in OnEnable()
  • Use EditorUtility.SetDirty() only for non-serialized changes
  • Use Undo.RecordObject() before modifying objects directly
  • Use EditorStyles for consistent appearance
  • Use GUILayout.FlexibleSpace() to push elements apart

See references/templates.md for complete script templates. See references/gui-elements.md for full element reference.

來源與署名

來源:unity-technologies/skills位於skills/ui-imgui提交cb1dccb

授權條款: 無授權條款

內容歸原作者所有。SourceWeft 從公開儲存庫中收錄這些內容。

檢舉或申請下架