josn_list_practice.cs
1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
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;
}
}