Custom inspector and/or Property Drawers in actions/scorers?

  • September 20, 2017 at 09:59 #22009
    edwon
    Participant

    I have a class referenced as a variable in my actions that I’d like to write a custom inspector (or perhaps more like a custom property drawer) for. Is this possible?

    September 20, 2017 at 10:20 #22011
    Rami
    Keymaster

    Hi Edwon,

    Thanks for your post.

    There are two parts to supporting a custom data type in the Utility AI inspector. One is the serialization to JSON (if not using a custom backend), so that the type can be stored and loaded. The other is the actual editor field.

    The serialization part is handled by writing a “Converter” or a “Stager”, depending on whether the type is simple and can be easily converted to / from a string (Converter), or if it is more complex with multiple fields (Stager).

    Look at IStager interface and IValueConverter interface.

    An example for a stager, in this case a ‘RectStager’ for staging Unity rects:

    An example of a converter, in this case for floats:

    Finally, you need to define an editor field to handle the exposing of the type to the AI inspector. Here is an example for a FloatField exposed in the AI editor inspector:

    I believe there should be nothing else to it. If you add these classes anywhere in your project (remember the attribute for the editor field), then they should be picked up automatically through reflection.

You must be logged in to reply to this topic.