Part 5. Case Study - Contextual Editors
- Sam Walet
- 3 jun 2022
- 1 minuten om te lezen
The modifiers allow you to link certain values like scale to property values or to trigger things like animations when a threshold is crossed. A lot of the variables in these modifiers are mutually exclusive, if you are transitioning based on speed then you are by definition not using duration. As such we should hide irrelevant variables using a custom editor.


Here you see the custom editor for the AnimationModifier which can change animator parameters. We use two types of context, an enum which only displays the variables for the type of animation parameter we want to edit and two booleans which hide and show variables for more specific settings. First we get all the properties and in the OnInspectorGUI function we display those variables that always need to be displayed. Next we store local references to the enum and the two booleans.
Now we can use a simple switch case to display the appropriate variables for the parameter type and in the case of a float or int check if the parameter should be linked to the detector in which case we need the min and max value. If the value should also change over time then we check the final enum which checks if we want to use speed or duration for this change. Itās all fairly simple if else logic, but it makes your inspector much prettier and simpler to use.



Opmerkingen