Individual Inspector Class Serializable

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

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

And this appears in the inspector (if I make a public variable of this type.) Although the default method is not shown very well:

enter image description here

Now I was wondering how can I change this? I found how to change the mono object inspector, although I could not find how to change it to other classes. I would like these to be just two numbers next to each other, something like this:

enter image description here

This is just a small thing, and not such a big problem if it is impossible, although knowing how you can be useful again later.

Oh yes, as you may have noticed, I am using C #, so it would be nice if any sample code were in C #.

Thanks.

+4
source share
3 answers

From Unity4 you can do it with PropertyDrawer

+1
source

This no longer applies to later versions of Unity.

It just turned out that this was impossible.

The only way to do this is whenever you use it in a mono object to provide this monobestel with an individual inspector and in it give the class your own layout. To make this easier, you can create a method that does the layout, and then use it in each candy bar.

+2
source

One solution that requires writing less specialized inspectors would be to make the UnitRange component. Everything that UnitRange requires you can annotate with [RequireComponent (typeof (UnitRange))] , so you don't have to go through the difficulty of adding it yourself. Make UnitRange check it only one attached (and error / delete itself, etc., if it is not).

Then have your various blocks cache the attached unit range component on Start() with GetComponent<UnitRange>() , ready for future use (as you are doing now if you just change the visibility to personal and reuse).

Finally - write an inspector for UnitRange that looks good.

0
source

Source: https://habr.com/ru/post/1445778/


All Articles