Asset Management
Asset: An object imported from project file. One project file can be imported into many assets, like a png tileset image can be imported into many sprite assets.
AssetDatabase
CRUD for project assets- Operates on project relative paths and asset GUIDs
Resources
Allows you to find and access Objects including assets- Can load assets without project relative paths
AssetPostprocessor
&AssetModificationProcessor
Take action after asset importPrefabUtility
Inspect / Modify Prefabs- Instantiate prefabs in the scene as “prefab instances” and not regular game objects
- Create prefab variants
- Add components
- Apply overrides
- Supports
Undo
out of the box
UnityEditorInternal.InternalEditorUtility.LoadSerializedFileAndForget
Loads assets from outside of the project folder- Special Folder Names
Entry points
InitializeOnLoadAttribute
&InitializeOnLoadMethodAttribute
Allows you to initialize an Editor class when Unity loads, and when your scripts are recompiledEditorApplication.delayCall
Delegate which is called once after all inspectors update.EditorApplication.update
Similar toMonobehaviour.Update
but for editor only use
UI
Entry points
Menu Items
MenuItem
Create a menu itemContextMenu
Create object specific context menu items. Works onMonoBehaviour
andScriptableObject
classes. Right click on object inspector header to show menuContextMenuItemAttribute
Same as above but works on serialized fieldsIHasCustomMenu
Defines a method to add custom menu items to an Editor WindowEditorApplication.contextualPropertyMenu
Callback raised whenever the user contex-clicks on a property in an InspectorUnityEditor.SceneManagement.SceneHierarchyHooks
Add menu items to Hierarchy windowaddItemsToCreateMenu
addItemsToGameObjectContextMenu
addItemsToSceneHeaderContextMenu
addItemsToSubSceneHeaderContextMenu
Editors
Editor
Create a custom “Inspector view” for the specific component or scriptable objectAssetImporters.AssetImporterEditor
Create a custom editor for theAssetImporters.ScriptedImporter
ObjectPreview
Create a custom preview for specific component or scriptable objectPropertyDrawer
Customize input field for your serializable c# type
Windows
EditorWindow
Create custom windowsPopupWindow
&PopupWindowContent
Create a popup windowScriptableWizard
Editor window designed for quick object creation toolsSettingsProvider
Create custom view in Preferences or ProjectSettings windows
Addons
Overlays.Overlay
Customizable panels and toolbarsEditorTools.EditorTool
Custom tools are like the built-in Move, Rotate, Scale tools or component specific tools like colider bounds editorEditorApplication.projectWindowItemOnGUI
Customize project window itemsEditorApplication.hierarchyWindowItemOnGUI
Customize hierarchy window itemsEditor.finishedDefaultHeaderGUI
Add UI to the default header drawer in Inspector Window
UI Systems
- UI Toolkit
- Namespaces
UnityEngine.UIElements
andUnityEditor.UIElements
- Namespaces
- IMGUI (Legacy)
- Static classes:
GUI
,GUILayout
,EditorGUI
,EditorGUILayout
- Static classes:
Scene View UI
Gizmos
Draw things like tool handles or bounding boxesDrawGizmo
Supply a gizmo renderer for any componentHandles
Custom 3D GUI controls and drawing in the Scene viewHandleUtility
Helper functions for Scene View style 3D GUIOverlays.Overlay
Customizable panels and toolbars
Utility
EditorGUIUtility.isProSkin
is user using a dark or light editor theme
Serialization
JsonUtility
JSON serializerEditorJsonUtility
JSON serializer that will include editor only values of the engine objects (MonoBehaviour
,ScriptableObject
, etc.)SerializedObject
&SerializedProperty
When you want to modify a component/asset avoid modifying it directly, instead use this API to properly save assets, scenes, supportUndo
etc.Undo
When modifying scene objects or assets use this class to support undo featureISerializationCallbackReceiver
Add logic to serialization eventsMonoBehaviour.OnValidate
&ScriptableObject.OnValidate
calls when a value changes in the InspectorEditorPrefs
Save and load data. Warning: Editor prefs are shared between all unity projects on user mashine. For project/tool/sdk editor only settings useScriptableSingleton<T>
orScriptableObject
instead.ScriptableSingleton<T>
In classes that derive from ScriptableSingleton, serializable data you add survives assembly reloading in the Editor. Also, if the class uses the FilePathAttribute, the serializable data persists between sessions of Unity.
Native Popups
EditorUtility.DisplayDialog
Get confirmation from the userEditorUtility.DisplayPopupMenu
Open context menu- Get the user select path
- Progress bar
EditorGUIUtility.GetMainWindowPosition
Gets editor window rect
Icons
Certain functions that load or set editor icons will find the appropriate texture for the active editor theme if certain conditions are met
- Icon textures for light and dark themes are in the same directory
- Dark theme icon name starts with the prefix: “d_”
- The icon name, path or texture passed to the function was pointing to the light version of the image
Example:
1 2 3 4 5 6 7 8 9 10 11 12
// Assuming the editor theme is set to dark // and there are two icons located at Assets/myIcon.png and Assets/d_myIcon.png // This will return the Assets/d_myIcon.png because Editor theme is set to dark var darkIcon = EditorGUIUtility.IconContent("Assets/myIcon.png").image; // This will return the Assets/myIcon.png because AssetDatabase.LoadAssetAtPath always returns the exact asset var icon = AssetDatabase.LoadAssetAtPath<Texture2D>("Assets/myIcon.png"); var monoImporter = (MonoImporter)AssetImporter.GetAtPath("Assets/SomeScript.cs"); // This will set the icon to Assets/d_myIcon.png because Editor theme is set to dark monoImporter.SetIcon(icon);
- Iconography
EditorGUIUtility.IconContent
Load icon texture from editor resources. Find icons in Editor Icon BrowserMonoImporter.SetIcon
Sets a custom icon to associate with the imported MonoScript.PluginImporter.SetIcon
Sets the custom icon to associate with a MonoScript imported by a managed plugin (like .dll).EditorGUIUtility.SetIconForObject
Set icon texture for GameObject or MonoScript.EditorGUIUtility.SetIconSize
Change IMGUI size of the icon.
Advanced / Tricks
CustomEditorForRenderPipelineAttribute
Tells an Editor class which run-time type it’s an editor for when the given RenderPipeline is activatedIMGUI.Controls.TreeView
IMGUI TreeViewIMGUI.Controls.AdvancedDropdown
Dropdown with pages as in “Add Component” button.- Open About Unity menu and type “internal” to toggle editor developer mode.
- Reload and inspect the editor window from its tab context menu
- Enable “Debug-Internal” inspector mode from the tab context menu
- Bunch of other internal tools, you can look for those in Unity C#Reference repo
Misc
EditorGUIUtility.hierarchyMode
Reason whyFoldout
can behave differently in inspector view. Unity AnswersEditorInternalUtility.IsValidFileName
Resources
Useful Internals
Those are internal classes/methods that I found and thought might be useful. As with any internal stuff your need to keep in mind that this functionality is subject to change.
ScriptAttributeUtility.GetFieldInfoFromProperty
ScriptAttributeUtility.GetDrawerTypeForType
- You can create an assembly with a name like “Unity.InternalAPIEditorBridge.” that has access to the editor’s internal API. To find possible indexes search editor source code