How to create a multidimensional string list in the inspector ?

Hi everyone,

I know this kind of questions are quite common on those forums but none of them allowed me to find the answer I’m looking for.
What I want to do is quite simple : When I click on a button, I fill a Text with different Strings randomly chosen from different lists.

This way, I would have a 3 dimensional list of strings. I tried many options but none of them was displayed in the inspector, always with no error.
For now I’ve got this :

public List<List<List<string>>> sentence = new List<List<List<string>>>();

I also tried this :

public string[,,] sentence;

As I have different sentences in which I have to select each word from a list (Sentence number > Chosen word > List of possible words), I’m stuck with this 3D list problem.

Does someone has any idea ?
Thanks in advance !

A hacky approach, from memory:

Create a “string array” class, and make an array of those:

[System.serialized]
public class Sarray {
  public string[] W;
}

Sarray[] my2DstringArray;

The idea is, Unity’s Inspector will display only simple arrays, or Serializable classes. So make a fake Serialized class who’s only purpose is to hold the array.

Of course, it’s now “ragged” (each row can be any length) and it looks like myArray[3].W[2] to get anything.

Hi Owen and thanks for you answer.
I’ve used and adapted it in order to be more efficient with what I planned to do, and here is the result.

I’ve splited my Array in 2 class, which I’m using with an XML document to facilitate the localization of data.

[System.Serializable]
public class Sentence     //The main class I'm using to class the different words of my sentence      
{
    [XmlArray("Words")]        
    [XmlArrayItem("Word")]      
    public List<Words> Words = new List<Words>();  
}

[System.Serializable]
public class Words        //The class I'm using to organize all the possible words for each word of the sentence     
{
    [XmlArray("AvailableWords")]   
    [XmlArrayItem("AvailableWord")] 
    public List<string> AvailableWords = new List<string>();    

    public string GetRandomWord()   
    {
        return AvailableWords[ Random.Range( 0, AvailableWords.Count ) ];
    }
}

I hope this may help someone someday.