Organizing variables in the inspector

Hi, is there a way with classes and with javascript to do the same thing in the inspector that arrays does. The thing where you can fold out so you can see more variables.
Lets say i got some code like this.
What would i need to do so the class Attack and the Movement class is a part of the Enemy in the inspector but as a thing that you can fold out and in.

class Enemy
{
	var Health : float;
	
}

class Attack
{
	var Damage : int;	
}

class Movement
{
    var moveSpeed : float;
	var normalSpeed : float;
}
var enemy = new Enemy();

How about just doing it the simple way, using composition? I don't understand why the other two posts here are so complex!

class Enemy
{
    var attack : Attack;
    var move : Movement;

}

Then, when you put it in your script they should show up in the inspector.

To organize your parameters in the inspector, you need to create an editor script. However, the code example you give won’t really work. You need to create 1 class that encompasses all the attributes of your object, rather than being spread out across multiple classes/objects. For example, I’d move Damage, moveSpeed and normalSpeed all into the Enemy class. Then your editor script would look something like:

@CustomEditor(Enemy)
class EnemyEditor extends Editor {
	private var showParams : boolean = true;
	function OnInspectorGUI() {
		showParams = EditorGUILayout.Foldout(showParams, "Enemy Parameters");
		if(showParams) {
			target.Health = EditorGUILayout.FloatField("Health", target.Health);
			target.Damage = EditorGUILayout.FloatField("Damage", target.Damage);
			target.moveSpeed = EditorGUILayout.FloatField("moveSpeed", target.moveSpeed);
			target.normalSpeed = EditorGUILayout.FloatField("normalSpeed", target.normalSpeed);
		}
	}
}

Name your editor script something like ‘EnemyEditor.js’ and place it in Assets/Editor. Then when you select an object with the Enemy.js script, the inspector will display your custom editor script layout.

You could put your variables in a region like so:

#region Variables
//variables go here..
#endregion

But i have noticed monodevelope doesnt always put in the + and - in for collapsing it should look like this:

Photobucket

Simple if i understand your " in and out " , test this two example :

#pragma strict


public class Enemy
{
    var Health : float;
 var attack:Attack;
var mouvement:Movement;
}
 
class Attack
{
    var Damage : int;  
}
 
class Movement
{
    var moveSpeed : float;
    var normalSpeed : float;
}
var enemy = new Enemy();

function Start () {

}

function Update () {

}

and this with array element for those 2 subclasses stript :

#pragma strict


public class Enemy
{
    var Health : float;
 var attack:Attack [];
var mouvement:Movement[];
}
 
class Attack
{
    var Damage : int;  
}
 
class Movement
{
    var moveSpeed : float;
    var normalSpeed : float;
}
var enemy = new Enemy();

function Start () {

}

function Update () {

}

I’ve added a feedback item to have attribute based categories added to the default inspector.

Please go here and vote for it:

http://feedback.unity3d.com/suggestions/built-in-inspector-should-use-system-dot-componentmodel-attributes-category-description-like-the-winforms-propertygrid