Unity Editor Toolbox

repository·master·Indexed 24 days ago

https://github.com/arimger/unity-editor-toolbox

A suite of tools for Unity 2018.x and newer designed to improve editor usability. It provides custom attributes and drawers for readable component editors, hierarchy overlays, project window icon customization, and specialized scene view tools. Key features include InLineEditor, ReorderableList, ReferencePicker for [SerializeReference] fields, and serialized types for Dictionaries, DateTimes, and Directories. The package is IMGUI-based and requires EditorCoroutines.

Tokens
7.8K
Snippets
20
Records
28
Agent score
34%

What's inside Unity Editor Toolbox

  1. How ToolboxDrawers work

    master

    ToolboxDrawers are categorized into 5 sub-types to handle different Inspector customization needs. Choosing the right type depends on whether you want to decorate, validate, or completely replace the rendering of a property.

    Drawer Sub-types

    1. ToolboxDecoratorDrawers: Used to create UI elements (icons, labels, controls) that appear before or after a serialized property. You can use multiple decorators on a single property.
    2. ToolboxConditionDrawers: Used to validate a property's state. They determine if a property should be Disabled or hidden. Use only one per property.
    3. ToolboxSelfPropertyDrawers: Used to customize the visual look of a specific property field. Use only one per property.
    4. ToolboxListPropertyDrawers: Used to customize the appearance of list/array properties. Use only one per property.
    5. ToolboxTargetTypeDrawers: Used to specify a custom look for all properties of a specific type (e.g., all int fields) regardless of attributes.

    Implementation Workflow

    To create a new drawer, follow these steps:

    1. Decide which drawer sub-type fits your requirement.
    2. Implement a dedicated ToolboxAttribute class (if the drawer is attribute-based).
    3. Implement the corresponding ToolboxDrawer class.
    4. Assign the newly created drawer in the Toolbox Settings file.
    5. Apply the attribute to your target field in your scripts.
  2. Customize the Hierarchy overlay

    master

    The Toolbox provides a Hierarchy overlay that can be enabled and customized via ToolboxEditorSettings. This overlay adds extra data directly to the Hierarchy window, such as:

    • Script information
    • Layer and Tag
    • Toggle to enable/disable GameObjects
    • Icons and Tree Lines

    You can also create 'Header' objects in the hierarchy using the #h prefix or via the menu: GameObject/Editor Toolbox/Hierarchy Header.

  3. Important Compatibility Notes

    master

    When using Unity Editor Toolbox, be aware of the following technical constraints:

    • IMGUI-based: The package is fully IMGUI-based, which may cause conflicts with pure UI Toolkit features in your project.
    • Inspector Overwriting: The toolbox overwrites the 'base' custom Editor for all UnityEngine.Objects. This is a common extension pattern, but it means you cannot combine this toolbox with other Inspector extensions or plugins that rely on the same mechanism.
  4. Set custom folder icons in the Project window

    master

    You can set custom icons for folders in the Project window through ToolboxEditorSettings. For each folder, you can configure:

    • XY position and scale for both large and small icons.
    • The path to the directory or the name.
    • An optional tooltip.
    • The large and small icon textures.
  5. Configure Unity Editor Toolbox settings

    master

    Settings manage the available features of the toolbox and can be accessed via Edit > Project Settings > Editor Toolbox or directly within the Project window.

    To ensure your custom settings are preserved across different versions of the toolbox, it is highly recommended to create your own settings file at: Create/Editor Toolbox/Settings

    Features are organized into four groups:

    • Hierarchy: Enable/disable Hierarchy overlay and choose displayed information.
    • Project: Enable/disable Project icons and assign custom directory icons.
    • Inspector: Enable/disable Toolbox drawers and assign custom drawers.
    • SceneView: Enable/disable Toolbox Scene View and assign hotkeys.
    Create/Editor Toolbox/Settings
  6. Install Unity Editor Toolbox

    master

    You can install the Unity Editor Toolbox package using one of three methods:

    1. Unity Package Manager (UPM): Open the Package Manager (Window > Package Manager), click the '+' button, select 'Add package from git URL...', and enter: https://github.com/arimger/Unity-Editor-Toolbox.git#upm
    2. Manual Copy: Copy and paste the Assets/Editor Toolbox directory directly into your project's Assets/ folder. Note that you must manually add the required dependencies.
    3. OpenUPM: Use the OpenUPM CLI: openupm add com.browar.editor-toolbox
    openupm add com.browar.editor-toolbox
  7. Use the ScriptableObject Creation Wizard

    master

    The Toolbox includes a built-in wizard to create multiple ScriptableObject assets at once. This wizard automatically detects and lists ScriptableObject types that are marked with either the [Toolbox.Attributes.CreateInWizard] attribute or the standard [UnityEngine.CreateAssetMenu] attribute.

    You can find it at: Assets/Create/Editor Toolbox/ScriptableObject Creation Wizard.

  8. Create a Custom List Property Drawer

    master

    Use ToolboxListPropertyDrawer<T> to customize the rendering of lists or arrays. Inherit from ToolboxListPropertyAttribute to create the attribute.

    • OnGuiSafe(property, label, attribute): Use this to define how the list header and its elements are drawn.
    using UnityEngine;
    
    public class StandardListAttribute : ToolboxListPropertyAttribute
    { }
    using UnityEditor;
    using Toolbox.Editor.Drawers;
    
    public class StandardListAttributeDrawer : ToolboxListPropertyDrawer<StandardListAttribute>
    {
    	protected override void OnGuiSafe(SerializedProperty property, GUIContent label, StandardListAttribute attribute)
    	{
    		EditorGUILayout.LabelField("Custom list drawer example");
    		EditorGUILayout.PropertyField(property, label, false);
    		if (property.isExpanded)
    		{
    			EditorGUILayout.PropertyField(property.FindPropertyRelative("Array.size"));
    			var size = property.arraySize;
    			for (var i = 0; i < size; i++)
    			{
    				var element = property.GetArrayElementAtIndex(i);
    				EditorGUILayout.PropertyField(element, element.isExpanded);
    			}
    		}
    	}
    }
  9. Extend the Unity Main Toolbar

    master

    You can add custom buttons and elements to the Unity main toolbar using ToolboxEditorToolbar.

    Note: For Unity 6.3+, it is recommended to use the official Unity Toolbar API instead of this implementation, which relies on Reflection and overriding VisualElements.

    To use it, subscribe to OnToolbarGuiLeft or OnToolbarGuiRight within an [InitializeOnLoad] class.

    using Toolbox.Editor;
    
    [UnityEditor.InitializeOnLoad]
    public static class MyEditorUtility
    {
    	static MyEditorUtility()
    	{
    		ToolboxEditorToolbar.OnToolbarGuiLeft += OnToolbarGuiLeft;
    		ToolboxEditorToolbar.OnToolbarGuiRight += OnToolbarGuiRight;
    	}
    	
    	private static void OnToolbarGuiLeft()
    	{
    		GUILayout.FlexibleSpace();
    		if (GUILayout.Button("1", Style.commandLeftStyle))
    		{
    			Debug.Log("1");
    		}
    		// ... other buttons
    	}
    
    	private static void OnToolbarGuiRight()
    	{
    		if (GUILayout.Button("1"))
    		{
    			Debug.Log("1");
    		}
    	}
    }
  10. Use Toolbox Condition Attributes to show/hide properties

    master

    You can enable/disable or show/hide properties using custom conditions. These work with boolean, int, string, UnityEngine.Object, and enum types, and they function correctly even with array/list properties. You can pass values from fields, properties, or methods.

    Condition Types:

    • Visibility: [ShowIf(nameof(member), value)], [HideIf(nameof(member), value)], [ShowDisabledIf(...)], and [HideDisabledIf(...)].
    • Interactivity: [EnableIf(nameof(member), value)], [DisableIf(nameof(member), value, Comparison)], [DisableInPlayMode], and [DisableInEditMode].
    • Warnings: [ShowWarningIf(nameof(member), value, "Message", DisableField)].
    • Combined: [Disable, ReorderableList] can be used to apply multiple attributes.
    public string StringValue => "Sho";
    [ShowIf(nameof(StringValue), "show")]
    public int var1;
    
    [DisableIf(nameof(GetFloatValue), 2.0f, Comparison = UnityComparisonMethod.GreaterEqual)]
    public int var2;
    
    public float GetFloatValue()
    {
    	return 1.6f;
    }