UITK Editor Aid
Elements and scripts that help in making Unity editors with UIToolkit.
UIToolkit (UITK) allows for interfaces that are more dynamic and performant than IMGUI. Its web-like API makes creating complex Editor UI (i.e. node graphs) a lot easier.
There's a problem, though: the editor part of UITK currently lacks some of the IMGUI features required for easily creating anything more than basic stuff. This issue can be avoided a little by using IMGUI containers inside UITK, but projects can easily get too limited and unwieldy, and performance drops quickly when there are multiple instances of them.
This package contains some of the stuff I use to solve the problem with a pure UIToolkit approach.
How to install
You can either download this package directly to your project's Assets folder, or you can use the Package Manager. Installing with the Package Manager is very easy:
- In Unity, go to Window > Package Manager.
- Click the
➕ ▾ in the top left and choose Add Package from git URL - Enter
https://github.com/OscarAbraham/UITKEditorAid.git
and press Add.
Some of the stuff included
Click a name to go to the relevant documentation page for usage info and some code examples:
EditableLabel
A label that tranforms into a text field to be edited. It's edited with a double-click by default.
ArrayPropertyField
A UITK version of the good old reorderable list, very customizable. Here's what it looks like by default:
There's also an abstract ListControl class that you can use to create your own lists that don't depend on a SerializedProperty
ManagedReferenceField
Currently, PropertyFields from members with the SerializeReference
attribute break when they change type. This element is like a PropertyField that updates when the type changes.
The next gif shows a customized ArrayPropertyField that uses ManagedReferenceFields for its items. Notice that the
interface updates itself when the elements change type due to being reordered:
ValueTracker
Some times you don't need a VisualElement for anything visual, sometimes you just need a quick way to get a callback when a property changes. This element helps you with that.
ListOfInspectors
A list that is similar to the component's list in GameObjects. I use it with ScriptableObject subassets. You still have to do the stuff that's not related to UIToolkit yourself, like handling assets and the lifetime of your objects, which is outside the scope of this package; but if you know how to do that, this could be very helpful.
More Stuff
Click the link to go to the docs homepage. There is stuff to replace some common IMGUI methods, like a
Disabler element that's equivalent
to EditorGUI.DisabledScope
, and FixedSpace
/FlexibleSpace
elements equivalent to GUILayout's Space
and FlexibleSpace
.
There are also some extension methods that I've found useful for UIToolkit editor development, and some UITK manipulators.
A caveat
Currently, all elements that need rebinding (i.e. Lists and ManagedReferenceFields), don't support UXML. That's because
they need to get a SerializedProperty
in their constructor. The correct way to solve that would be to obtain them with
Unity's binding system, but the required API is not public yet. I don't want to use reflection because that API seems
likely to change, and editors that break when doing a minor Unity update are awful.
IMPORTANT: Avoid collisions when including this code inside packages and plugins
Sometimes one needs to put a copy of a library inside a Unity plugin; that's very ok, that's what the MIT license is for. If you do that, please take steps to avoid collisions when your users have also installed this package themselves. The easiest way to do it is:
-
Rename the ArteHacker part of the namespace. Most text editors have an automated way of doing that.
-
Delete the .asmdef file inside the Editor folder. Create a new one if you need it; renaming it is not enough because some users reference them as assets (with their GUID).