I've tried some stuff like
public string[,] = new string[0,0];
and this line doesn't give me any errors in monodev or unity console, but it doesn't show up in the inspector, even if I place serialize field. I can still dynamically set strings with code, but can't give a predefined item in the inspector.
Is this supposed to happen?
Is there any way I can get into the inspector some kind of dynamic 2d array of type string?
This is exactly what I want, but this answer was for javascript.
Thanks
You can create your own string array class and create an array of this:
using UnityEngine;
using System.Collections;
[System.Serializable]
public class MultidimensionalString
{
public string[] stringArray = new string[0];
public string this[int index] {
get {
return stringArray[index];
}
set {
stringArray[index] = value;
}
}
public int Length {
get {
return stringArray.Length;
}
}
public long LongLength {
get {
return stringArray.LongLength;
}
}
}
Usage:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class ArrayTest : MonoBehaviour {
public MultidimensionalString[] multidimensional = new MultidimensionalString[10];
public void Start(){
multidimensional[1].stringArray = new string[4];
multidimensional[1][1] = "test";
Debug.Log(multidimensional[1][1]);
}
}
This answer is based on the following answer:
http://answers.unity3d.com/questions/47049/visializing-a-multidimensional-array
An alternative is to create a custom editor for that gives access to a specific GameObject that contains either multidimensional array of arrays-of-arrays. Note that this is a less general approach that the MultidimensionalString.
http://unity3d.com/support/documentation/ScriptReference/Editor.html
here yo can see a simple multidimesional array c# sample code
groval