Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unity Serializable Class Custom Inspector

I have a very simple class in unity, UnitRange (which has a minimum and a maximum range).

[System.Serializable]
public class UnitRange {
    public int Minimum;
    public int Maximum;
}

And this shows up in the inspector (if I make a public variable of this type.) Though the default way it is shown isn't very good:

enter image description here

Now, I was wondering how I can change this? I found how to change the inspector of monobehaviours, though couldn't find how to change it of other classes. I would like it to just be two numbers next to each other, something like this:

enter image description here

It's just a small thing, and not that big a problem if it's not possible, though knowing how to could prove more useful later too.

Oh yes, as you might have noticed, I'm using c#, so it would be nice if any example code is in c#.

Thanks.

like image 759
The Oddler Avatar asked Nov 13 '12 14:11

The Oddler


2 Answers

This is no longer true in later versions of Unity.

Just found out this is not possible.

The only way to do this is, whenever you use it in a monobehaviour, to give that monobehaviour a custom inspector and in there give the class your custom layout. To make this easier you can make a method which does the layouting and then use that in each monobehaviour.

like image 144
The Oddler Avatar answered Oct 31 '22 20:10

The Oddler


From Unity4 you can make this with PropertyDrawer

like image 35
konsnos Avatar answered Oct 31 '22 18:10

konsnos