I wondering if is possible to do something like this.
[Serializable]
public class AnimationData
{
/// some data
}
public class AnimatorDataController
{
public int size;
if(size>0)
{
//serialize an array
public AnimationData[] animationData = new AnimationData[] { };
}
else
{
//serialize one element only
public AnimationData animationData = new AnimationData();
}
}
No, you couldnât change the declaring type of a member like that. You could mimic what Unity does though, serialize the array and expose properties that act the way you want. Like Renderer.material and Renderer.materials, where material is just a property that returns the first element of the materials array.
Using a custom inspector would allow you to selectively make it appear as a single property instead of an array with a length of one, definitely. That wonât change how the code works under the hood though.