Я пытаюсь конвертировать данные в json но почему list не сохраняется?
public class NewDialog
{
public string Name,Textarea;
public Sprite MySprite;
public NewDialog( string textarea, string name = null, string SpritePath = null)
{
Textarea = textarea;
Name = name;
if(SpritePath != null)
MySprite = Resources.Load<Sprite>(SpritePath);
}
}
public class ArrayDialog{
public List<NewDialog> MyListDialog;
public string Name;
public ArrayDialog(string name)
{
Name = name;
MyListDialog = new List<NewDialog>();
}
}
Создание дилога
ArrayDialog arraydialog1 = new ArrayDialog("first dialog");
arraydialog1.MyListDialog.Add(new NewDialog("blablabla1", "player1", "Sprites/Cards/ebalo"));
arraydialog1.MyListDialog.Add(new NewDialog("blablabla2"));
DialogManagerList.AllDialogs.Add(arraydialog1);
ArrayDialog arraydialog2 = new ArrayDialog("second dialog");
arraydialog2.MyListDialog.Add(new NewDialog("blablabla1", "player2", "Sprites/Cards/ebalo"));
arraydialog2.MyListDialog.Add(new NewDialog("blablabla2", "player2", "Sprites/Cards/ebalo"));
DialogManagerList.AllDialogs.Add(arraydialog2);
string jsonDataString = JsonUtility.ToJson(arraydialog1, true);
Debug.Log("DIALOG");
Debug.Log(jsonDataString);
var bibi = JsonUtility.FromJson<ArrayDialog>(jsonDataString);
foreach (var vary in arraydialog1.MyListDialog)
{
Debug.Log(vary.Textarea);
}
foreach (var vary in bibi.MyListDialog)
{
Debug.Log(vary.Textarea);
}