Skip to main content

EditorTools Sample

An editor window and an Inspector built in code with the package's helpers.

The Halve cooldown, +5 MP button changes the cost and the cooldown, and Undo restores them.The Halve cooldown, +5 MP button changes the cost and the cooldown, and Undo restores them.

The Halve cooldown, +5 MP button changes the cost and the cooldown, and Undo restores them.

Open it​

  1. Import the sample: Tools → Aspid 🐍 → FastTools → Welcome → Samples → Import on EditorTools. It has no scene.
  2. Open Tools → Aspid 🐍 → FastTools → Samples → Ability Catalog: the left pane lists the project's abilities, the four assets from Data/ among them, and the right pane shows the selected one.

Try​

  1. A ListView in one chain. The list on the left is one chain of ListView extensions, SetMakeItem, SetBindItem and AddSelectionChanged included. Type in the search field: AddValueChanged filters the source, and RefreshItems redraws the list.

  2. Binding. The name, description, cost and cooldown fields sit in one container bound with .BindTo(serializedObject). Edit the name: the list and the title follow, and Undo restores it.

  3. Typed property setters. Press Halve cooldown, +5 MP. The handler writes two properties and applies them once, so a single Undo reverts both:

    serializedObject.Update();
    var cooldown = serializedObject.FindProperty("_cooldown");
    var manaCost = serializedObject.FindProperty("_manaCost");
    cooldown.SetFloat(cooldown.floatValue * 0.5f);
    manaCost.SetIntAndApply(manaCost.intValue + 5);
  4. The type picker from code. Press Change… next to Effect: TypeSelectorWindow.Show() opens the picker of [TypeSelector] at the button, limited to IAbilityEffect implementations, and writes the pick into a string property. Pick HealEffect and change Mana Cost: the effect description follows the value, through Undo and Redo too.

  5. Open the script. Double-click the ability title in the right pane: AddOpenScriptCommand opens AbilityConfig.cs in your IDE.

  6. The inspector. Select Data/Sprint.asset in the Project window. AbilityConfigEditor draws a card titled with GetDisplayName(), “Ability Config”, a cost badge and a warning shown while Mana Cost is 0; PropertyField.AddValueChanged() drives both. Set the cost to 10 and back.

  7. Create. Press Create: a new asset appears next to the selected one, already selected in the list.

Where to look​

FileShows
Scripts/Editor/AbilityCatalogWindow.csListView extensions, BindTo, SetFloat and SetIntAndApply, TypeSelectorWindow.Show() with a TypeSelectorFilter, AddOpenScriptCommand
Scripts/Editor/AbilityConfigEditor.csA custom inspector on the style and layout setters, GetDisplayName
Scripts/AbilityConfig.csThe data; [TypeSelector] on the effect string gives the asset's Inspector the same picker
Scripts/Effects/The effect classes the picker offers

Reference: VisualElement Extensions, SerializedProperty Extensions, Editor Helpers and TypeSelectorWindow.