fungus

Open full view…

How to make a dropdown of Sequences?

Shane Whelan
Wed, 15 Apr 2015 19:05:06 GMT

Hi Chris & John, I'm trying to make a command based on a switch case that can call a sequence from a list. I started imitating the Scripting/ Call command you already have because it presents the choice of available sequences as a dropdown list, based on the sequences already in the editor. When I put in my own Sequence[] builtin array, they appear, but only as a list of regular unity fields in the inspector. When I copy & paste the Call class into a new class of my own with a different name, the targetSequence still appears without the dropdown list. Am I missing something simple to get my own Sequence variables to appear as a dropdown, or is that hard-coded for the Call command elsewhere? Cheers

chrisgregan
Wed, 15 Apr 2015 20:46:38 GMT

Yep, it's hard coded for the Call command elsewhere :) We have a default CommandEditor class which works well for most public property types, but it doesn't automatically create dropdowns for Sequence properties. In that situation you have create a custom CommandEditor class for your command. The Call command is a good example, take a look at the matching CallEditor class. When you create a custom editor you need to handle displaying the editor GUI controls for each property yourself - it's not that complicated though. Usually this means getting a reference to a SerializedProperty for each public property in your command class, and then calling EditorGUILayout.PropertyField() with the serialized property in the GUI drawing method. This draws the appropriate control for that property in the inspector. To draw a dropdown for a Sequence property however, you need to use SequenceEditor.SequenceField() to draw the dropdown control. Hopefully that's enough for yo u to figure it out, ask about anything you get stuck on. Worth reading up on unity custom editor classes too - very powerful!

Shane Whelan
Wed, 15 Apr 2015 21:07:58 GMT

I've looked up the property drawer stuff before and just not bothered to make anything with it. I had a feeling it would be along those lines. It's this or use 20 sequenced If commands. Thanks for getting back to me -- I'll give this a go later.