Hi all,
This might not be an easy problem to solve.
Here’s the situation: (I know this doesn’t compile, just an example)
[Serializable]
public class Nested : System.Object
{
public float sliderValue = 0f;
}
public class Container
{
public List<Nested> nestedList;
}
So, This works in the inspector:
It will roughly look like:
-
Container
-
NestedList
-
Size 1
-
sliderValue 0
Now comes the tricky part: How can I use a custom inspector to transform that sliderValue float into a floatslider?
It seems impossible but if there is some trick, I’d love to hear it. Workarounds etc. are also appreceated.
Thanks.
Create a PropertyDrawer for your nested class
So, I’ve suspected from the start that there was a hard way to do this and it seems that there was. I don’t know if this is officially supported or a hack but here is how I got this to work:
[Serializable]
public class Nested //Don't inherit from object
{
public float sliderValue = 0f;
}
public class Container
{
public int nestedListSize = 0; //Add this
public List<Nested> nestedList;
}
What you have to do now is write an inspector for your container class. You have to write the respresentation of the array by yourself and I solved that by adding a size variable in the class and use that for the length of the list. In the inspector you have to handle size changes; adding or removing items from the list etc. This kind of sucks but it’s not that hard.
After you do that you can construct the representation of your Nested class. Use a for-loop to loop over your list and write your inspector code for your Nested class item.
I have successfully done this for three layers of nesting.