Manage layout of Scripts in Inspector Window?

hey -

As a script gets bigger and bigger, more and more user inputs become available… lets take something simple like a moving Lift Platform. We have sounds we have models and animations and perhaps an assortment of particle effects… and things like simple booleans that the user may want to play with.

Pretty soon the Inspector becomes a long, unordered list…

So! Is it possible to have Attributes for exposed members? Like you do when creating Classes that can be inspected by a user at runtime in a control such as a Property Grid (which is similar to what the Inspector is).

For example with the sounds… maybe I want them in a neatly expandable group - in WinForms I simply add this to each member.

[Category("Lift Sounds")]
[Description("The sounds the lift will play")]
public AudioClip MyLiftSound;

The Description is useful for people who didn’t write your script (designers making a level) so that they can quickly see what this member is for.

I think this would be extremely useful to add to Unity… (or maybe I’ve missed it?! :slight_smile:

I too like things to be nice a and neat and easy to find and view. Things i do to organize are, create arrays so i can collapse them in the inspector, make vars private that i don’t need to see, create a GM type gui list that has bools and timers so i can see on the fly what’s going on, purposely creating a name scheme with vars, to group them and have those most looked at and used at the top of the inspector list. Also i break down scripts into two scripts if it has a lot of members.

I think searching in the forum one day i ran across a custom inspector topic or script :idea:

Just wondering though what kind of script do you have that have so many members expose? Even insane ones i have seen have only had around. 20 :smile:

yep I do use a lot of what you mentioned when it suits…

Hmm, so an example could be a dynamic Sky class.
Lets see… you may want a catagory called ‘Sun’

  • Angle
  • Color
  • Intensity
  • Flare Image
  • Specular

So that’s just sun…
Then you may have Clouds (a projected cloud map for eaxmple)… with speed, scale and intensity…
Then Ambience… etc etc

Soon enough you have lots of properties. Either way, it’s no so much about quanity, simply neatness. :slight_smile:

So - I think this would be a great addition being able to add a [Catagory(" ")] attribute.

Something similar to the .NET forms [Description(" ")] alread exists… but only in the hard coded objects such as a Particle Emmiter… you can hover your mouse and a ‘tool tip’ pops up.

Again, this would be great to be able to add to our scripts.

It’s especially handy on large projects where people using your scripts might be on the other side of the world :wink:

I would suggest using [serializable] and a class structure.

For example:

A Sky class contains a Sun Class, and an array of Clouds Classes. Both the Sun and Clouds are tagged serializable.

The Sky class manages their implementation (updates, constructors, etc…) but your sun and clouds are now much more reusable and easier to debug and rearrange.

The Serializable tag will allow each public Sun or Clouds object to have an arrow and be expandable. This way you can still change properties of the children through the parent class, but can also be much better organized through both the inspector and general code design.

Edit: I seems to have misread, and am replying to a separate complaint to the actual one listed here I think.

thanks for the class tip - seems like a neat way to go!

though as per original post, i don’t think it would work for example, if there are several sounds associated with a Lift (GroundStop, Moving, UpStop, Locked, Beep …etc etc) you don’t want another class just for that… and then the lift may have variables… WarmUpSpeed, MoveSpeed, SlowDownSpeed, MoveDistance… etc etc

again, you just want to put a neat [Catagory(“Foo”)] attribute above each property… and tooltips are very helpful to when someone other than yourself wants to know what that variable does [Description(“does foo”)] …especially as projects and members involved grow, you want your classes to be as clear and readable in the inspecter as possible.

I noticed in built Unity objects like particle emitters will have tooltips when you hover over their properties, but can we apply this to properties in our scripts?

Thanks!

You can create a custom editor; see the Editor and CustomEditor classes:

That’ll give you the maximum control. You could also write a generalized editor that was driven by custom attributes I guess. Built-in support for that would be convenient, though :slight_smile:

…could you give me an example of this? I couldn’t find it, the closest I found was [SerializeField] which didn’t work for classes or structs?