GameObject Array in Editor GUI

Hey,

I'm trying to get an array of gameobjects editable in a custom editor. Does anyone know a good way to do this?

For instance what if the enemyObject in the following code snippet was an Array[], how can I make this an editable Array list like in the normal inspector?

var enemyObject : GameObject;

    function OnGUI () 
        {
            enemyObject = EditorGUILayout.ObjectField ("enemyObject",enemyObject, typeof(GameObject));
        }

For clarity: I'm building a custom editor window (EditorGUI), and that's were I want to be able to see my GameObject Array. Doesn't have to be editable, just need to see whats in there.

Thanks a lot!

cheers

using UnityEngine;
using UnityEditor;
using System.Collections;

[CustomEditor(typeof(MyClass))]

public class BoardEditor : Editor {
	private SerializedObject m_Object;
	private SerializedProperty m_Property;

	void OnEnable() {
		m_Object = new SerializedObject(target);
	}
	
	public override void OnInspectorGUI(){
		m_Property = m_Object.FindProperty("MyProperty");
		EditorGUILayout.PropertyField(m_Property, new GUIContent("MyLabel"), true);
		m_Object.ApplyModifiedProperties();
	}
}

Unity Editor GUI has function to make the same ARRAY view like in default inspector! All you need is to assign TRUE to IncludeChildren property in function EditorGUILayout.PropertyField() like in example! sorry for my English) best wishes) PS I found it thanks to your examples!) so thank you all …

try this:

SerializedObject m_Object;
SerializedProperty m_Property;

void OnEnable() {
    m_Object = new SerializedObject(target);
}

public override void OnInspectorGUI() {
    m_Property = m_Object.FindProperty("NAMEOFARRAY");
    EditorGUILayout.BeginVertical();
    do {
      if (m_Property.propertyPath != "NAMEOFARRAY" && !m_Property.propertyPath.StartsWith("NAMEOFARRAY" + ".") ) {
          break;
      }  
      EditorGUILayout.PropertyField(m_Property);
    } while (m_Property.NextVisible(true));
    EditorGUILayout.EndVertical();

    // Apply the property, handle undo
    m_Object.ApplyModifiedProperties();
    //DrawDefaultInspector();
}

You probably have to do it by hand.

Untested:

var scrollPosition : Vector2;

function OnGUI()
{
    scrollPosition = EditorGUILayout.BeginScrollView(scrollPosition);

        foreach( GameObject go in myGameObjectArray )
        {
              go = EditorGUILayout.ObjectField( go.name, go, typeof( GameObject ) );
        } 

    EditorGUILayout.EndScrollView();
}

You might be able to set up something with a Foldout object to make it collapsable, as well as maybe putting an int field there to resize your array. But that's the path I would suggest going down.