Collection of vars

Hey Guys,

Is it possible to set up an collection of vars in a script so that it is visible in the inspector as parent-child hierarchy?

Like this->

varParent[ ]
→ varChild1
→ varChild2
→ varChild2.1
→ varChild2.2

and so on? If so, could anyone tell me how to do this?
It should be work like the image attached:
Materials
→ Size
→ Element0

210169--7725--$pc_118.png

i don think that is possible,

a hashtable would do the trick if it is serializable, but then you’ll have var name as opposed to true code vars.

I wonder if there is a way to write code to make widgets for the unity editor??

It is possible - the Unity editor is completely scriptable. In fact, the entire Unity editor itself is actually written using Unity’s own GUI system. AngryAnt’s “Behave” is another good example of how flexible Unity’s editor scripting is.

The downside is that if you want custom widgets for your component, you’ll have to write the entire inspector code for your component yourself. You can’t just modify the look of one or two variables. The documentation is a little scant on this subject though, so good luck!

thanx duck, hope it’ll be easier in the future, any way such functionality is secondary.

What you want is possible by creating your own custom (serializable) classes. If you use java script, all classes are serializable by default (see: http://unity3d.com/support/documentation/ScriptReference/Serializable.html).

For instance, if you define a class like this:

class MyTest extends System.Object
{
    var number = 5;
    var color = Color.white;
}

you can add it to one of your behaviour scripts like this:

var testObjectWithNumberAndColor : MyTest = new MyTest();

The result will be that the behaviour script will have a field in the editor called ‘testObjectWithNumberAndColor’. When you expand ‘testObjectWithNumberAndColor’ it will have two fields: ‘number’ and ‘color’ that allow you to fill in an int and a color.

(I assumed you use JavaScript. I have not actually tested the code I provided)

okay sounds nice, I will try your solution tom, thanks to all others anyway. And yes I use JS, I actually dont like C#, I would prefer Ruby as Unity language :wink:

rgds

zemog