josn_list_practice.cs 1.32 KB
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System;
using System.Runtime.Serialization.Formatters.Binary;


public class josn_list_practice : MonoBehaviour
{

    public MainObjectData mainObject; //싸고있는놈
    public InnerObjectData innerObject; //진짜 저장하고 싶은 클래스

    //진짜 저장하고싶은 리스트
    List<InnerObjectData> objectList = new List<InnerObjectData>();
    public InnerObjectData createSubObject(string n, int sc) {
        InnerObjectData myinnerObject = new InnerObjectData(n, sc);
        return myinnerObject;

    }
    void Start()
    {
        objectList.Add(createSubObject("BB", 33));
        objectList.Add(createSubObject("CC", 343));

        //리스트를 배열로 바꿔서 저장!!
        mainObject.highscore = objectList.ToArray(); 

        //이밑으로 그냥 json저장하면됨...오키 리스트로 갖고있다가 저장할때만 배열로 하면되는군.
        //읽을때는? 하나씩 추가해줘도 되고...AddRange라는걸 써도 되는듯?


    }

}

[Serializable]
public class MainObjectData {
    public InnerObjectData[] highscore;
}

[Serializable]
public class InnerObjectData {
    public string name;
    public int scores;

    public InnerObjectData(string a, int b) {
        name = a;
        scores = b;
    }

}