I’m not sure how to proceed with this, but I’ve been investigating PropertyDrawer and PropertyAttribute and I’m not sure if they’re going to work for what I want.
Here’s the setup:
public class ContainerClass : Monobehaviour
{
public List<BaseBehavior> behaviors;
public void AddToList(BaseBehavior b)
{
if(!behaviors.Contains(b))
behaviors.Add(b);
}
...
public void BunchaFunctions() { //etc }
}
[System.Serializable]
public class BaseBehavior : ScriptableObject
{
public float force;
public Vector3 direction;
}
[System.Serializable]
public class FirstBehavior : BaseBehavior
{
public float additionalForce;
public float delayTime;
}
[System.Serializable]
public class SecondBehavior : BaseBehavior
{
public bool isStupendous;
public Vector3 exampleVector;
}
Here’s the loop in my editor class where I might expand / view each Behavior class:
ContainerObject control = target as ContainerObject ;
int index = 0;
foreach (BaseBehavior in control.behaviors)
{
foldouts[index] = EditorGUILayout.Foldout(foldouts[index], behavior.ReportType().ToString());
if (foldouts[index])
{
// this is where I assume display info goes?
}
index++;
}
What I have so far is an Editor class that creates a custom inspector for ContainerClass. The custom inspector allows me to select and add various behavior types from my project to the List. All good so far. I can display the list of behaviors, but now I need to get into each Behavior and edit its parameters.
Normally this wouldn’t be a problem without a custom inspector, as you can just expand the list, look at each element and expand the available parameters that way. Unfortunately, implementing a custom inspector overrides that ability.
How can I get that back without coding an inspector for each class? Or at least making something general enough that it works for any new Behaviors written, regardless of what variables the new Behaviors might have (so long as they inherit from BaseBehavior). At this stage, it doesn’t necessarily need to be pretty, so long as the variables are accessible.
At some point I found myself delving into System.Reflection to pull apart each behavior and send back arrays of variables to be displayed. That seems like overkill, and presents its own world of problems.
What are my options in this scenario?
Thanks in advance