unity-technologies/skills

ui-imgui

Unity IMGUI (Immediate Mode GUI) expert for legacy editor tools using OnGUI/immediate mode.

ソースを見る
リポジトリの原文

見出し、例、コード、表、リンク、参照画像を含む原文を表示しています。

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:

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 windowsEditorWindow classes with OnGUI()
  • Custom inspectorsEditor, PropertyDrawer classes with OnInspectorGUI()
  • Debug overlaysOnGUI() 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 menu
ShowWindow() static method → opens window
OnGUI() → draws interface
OnEnable/OnDisable → initialization/cleanup

Custom Editor

[CustomEditor attribute] → targets component type
OnInspectorGUI() → draws inspector
OnEnable() → cache SerializedProperties
serializedObject.Update/ApplyModifiedProperties → undo support

PropertyDrawer

[CustomPropertyDrawer attribute] → targets type or attribute
OnGUI(Rect, SerializedProperty, GUIContent) → draws property
GetPropertyHeight() → 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 side
EditorGUILayout.EndHorizontal();

Vertical grouping:

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

Scroll view:

csharp
scrollPos = EditorGUILayout.BeginScrollView(scrollPos);
// scrollable content
EditorGUILayout.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 elements
EditorGUI.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.

同じリポジトリから

関連する Skills

すべての Skills
unity-technologies
コミュニティ

build-live-game

Build and operate a live game using Unity Services. Use when the user needs to implement, connect, or debug backend-driven features — battle passes, achievements, player progression, cloud saves, leaderboards, matchmaking, virtual economies, server-authoritative logic, anti-cheat, player accounts and authentication, remote configuration, feature flags, A/B testing, analytics, or cloud resource deployment. Triggers on live-ops, live service, backend, server authority, cloud code, cloud save, remote config, player data, retention, monetization loop, season pass, ranking, multiplayer sessions, lobbies, or any Unity Services integration.

導入数
1
GitHub Stars
730
更新日
9月4日
unity-technologies
コミュニティ

implement-in-app-purchases

Implement, configure, and debug Unity In-App Purchases (IAP) — store connection, product catalog, consumable/non-consumable/subscription purchases, two-step pending-confirm flow, receipt validation, entitlement checking, restore transactions, Apple extensions (promotional purchases, Ask-to-Buy, code redemption), and Google Play extensions (subscription upgrade/downgrade), D2C Capabilities(direct to customer), 3rd party payment provider (Stripe/Coda) via Unity IAP/Unity Cloud. Use when the user needs to add, modify, debug, or migrate from native Android/iOS billing, 3rd party packages(RevenueCat/Adapty/Essential Kit/Unipay supported) to IAP. Triggers on microtransactions (MTX), monetization, real-money purchases, store purchases, buying items, support D2C, purchase via Stripe/Coda, migrate from native billing(Google's BillingClient or Apple's StoreKit/SKPaymentQueue/SKProduct)/RevenueCat/Adapty/EssentialKit/Unipay.

導入数
1
GitHub Stars
730
更新日
9月4日
unity-technologies
コミュニティ

initialize-ai-navigation

Sets up and configures the Unity AI Navigation system — NavMesh surfaces, NavMesh agents, obstacles, links, modifiers, areas and costs. Use when creating walkable navigation meshes, adding pathfinding agents, setting up patrol routes, configuring obstacle avoidance and carving, connecting separate NavMeshes with links, coupling navigation with animation, or troubleshooting navigation issues.

導入数
1
GitHub Stars
730
更新日
9月4日
unity-technologies
コミュニティ

levelplay-unity-integration

Adds ads and monetization to a Unity game using the LevelPlay Mediation SDK (installed via the Ads Mediation UPM package). Use when a developer asks about adding ads to a Unity game, implementing rewarded, interstitial, or banner ads, setting up ad mediation, configuring ad networks, installing or updating the Ads Mediation package, troubleshooting LevelPlay namespace errors, resolving Android gradle or iOS CocoaPods dependency issues for ads, configuring ATT or privacy settings for ad compliance, tracking impression-level revenue (ILRD), initializing the LevelPlay SDK, or setting up ad unit IDs. Also use when a developer wants to monetize their Unity game with ads, asks how to get started with LevelPlay, ads, or mediation, or needs help with any part of the LevelPlay integration workflow including platform-specific setup for iOS or Android. Also use when upgrading the LevelPlay or IronSource SDK version, migrating from deprecated IronSource.Agent APIs, or migrating a game from Unity Ads to LevelPlay.

導入数
1
GitHub Stars
730
更新日
9月4日