- Home /
Dynamic serialized fields based on enum
I have an enum that describes movement type:
public enum MovementType{
STATIONARY,
STATIONARY_AIMING,
}
Now I want editor fields to change based on selected type.
I really wanted to have an abstract class and a set of derived classes that describe the movement behaviour, then to select a type from an enum (in Editor on an object with this script) and serialized fields from those classes would show in editor accordingly. For example stationary type would not have any serialized fields while stationary_aiming would have serialized field - float rotation_speed. And that field would show in editor only when I select adequate enum value.
I know that it is not possible to directly achieve that as serialization does not work with inheritance/polymorphism, so how is that handled on bigger projects then? I don't want to create a separate script/prefab for each movement type as I predict there will be a lot of different movement types in my project.