Public 2D array, accessed through the editor ??

I am trying to declare a public multidimensional array of GameObjects(Using JavaScript not c#) that I can access through the editor. However it would appear that only single dimension arrays are usable through the property inspector.

can anyone please help me out with this i know it is easily possible with c# but i want to know how it can be achieved using javascript.

Thanks in Advance

What I have done is declare a custom class that has an array as a variable. Declare a new array of this class and you have your multi-dimensional array that can be viewed in the editor without any fuzz.
Here’s an example in UnityScript, but it should be easily convertible to C#.

class Array2D {
	var subArray : GameObject[] = new GameObject [12];
}

var my2DArray: Array2D [] = new Array2D [12];




function PrintArrayContent() {
     if(my2DArray[0].subArray[0] != null) {
           Print(my2DArray[0].subArray[0].name);
}
    
}

You could also write your own Custom Editor/Inspector code or use this code as a
reference:

In know its in c# but just use [this][1] its not that hard to convert and just look at the docs for a custom editor.

using UnityEngine;
using System.Collections;
using UnityEditor;

[CustomEditor(typeof(BackgroundMaster))]
public class BackgroundEditor : Editor {

	bool isShowing;
	bool[] b;

	bool a;

	void Start()
	{
		BackgroundMaster myBGMaster = (BackgroundMaster)target;
		b = new bool[2/*myBGMaster.backgroundItems.GetLength(0)*/];
	}

	public override void OnInspectorGUI()
	{
		base.OnInspectorGUI();
		BackgroundMaster myBGMaster = (BackgroundMaster)target;

		isShowing = EditorGUILayout.Foldout(isShowing, "Background Items");
		if(isShowing)
		{
			//Debug.Log(b.Length + (b[0]?"T":"F") + (b[1]?"T":"F"));
			if(b != null && b.Length > 0)
			{
				for(int i = 0; i < b.Length; i++)
				{
					string s = "";
					if(i == 0)
						s = "    Foreground";
					else if(i == 1)
						s = "    Midground";
					else 
						s = "    Background";

					b _= EditorGUILayout.Foldout(b*, s);*_

_ if(b*)
{
for(int j = 0; j < myBGMaster.backgroundItems.GetLength(1); j++)
{
if(myBGMaster.backgroundItems[i, j])
EditorGUILayout.LabelField(" “, myBGMaster.backgroundItems[i, j].name);
else*
* EditorGUILayout.LabelField(” N/A");
}
}
}
}
else*
* {
EditorGUILayout.LabelField(" N/A");
EditorGUILayout.LabelField((" [" + myBGMaster.backgroundItems.GetLength(0)) + ", " + myBGMaster.backgroundItems.GetLength(1) + “]”);
}
}
}
}
Or you could have a look at this [Unity tutorial][2]
Hope this helps later viewers,
Minchuilla
[1]: http://unity3d.com/learn/tutorials/modules/beginner/scripting/c-sharp-vs-javascript-syntax*_

_*[2]: http://unity3d.com/learn/tutorials/modules/intermediate/editor/building-custom-inspector*_

Hey,

I stumbled in this same issue a month ago and after solving it, I have made a solution to this, now. I have made a grid view for a 2D array.

You can find it here: Unity3D - 2D Array In Inspector - YouTube

Its in c# though.