[Serializable]

public class TestData

{

ย  ย  public int TotalKill;

}




public class GameManager : MonoBehaviour

{

ย  ย 

ย  ย  public TestData testData;

ย  ย  public int totalKill



ย public void SaveData()ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย ย 

ย  ย  {ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย  ย 


ย  ย  ย  ย testData = new TestData();

ย  ย  ย  ย 

ย  ย  ย  ย testData.TotalKill = totalKill;

ย  ย  ย  ย ย 

ย  ย  ย  ย string jsonData = JsonUtility.ToJson(testData, true);

ย  ย  ย  ย string path = Path.Combine(Application.persistentDataPath , "testData.json");

ย  ย  ย  ย File.WriteAllText(path, jsonData);


ย  ย  }

ย  ย  public void LoadData()ย  ย  ย  ย  ย  ย  ย  ย ย 

ย  ย  {

ย  ย  ย  ย 

ย  ย  ย  ย  if (!Directory.Exists(Application.persistentDataPath ))

ย  ย  ย  ย  {

ย  ย  ย  ย  ย  ย  Directory.CreateDirectory(Application.persistentDataPath );

ย  ย  ย  ย  }

ย  ย ย 

ย  ย  ย ย 

ย  ย  ย  ย  String path = Path.Combine(Application.persistentDataPath , "testData.json");

ย  ย  ย  ย  String jsonData = File.ReadAllText(path);

ย  ย  ย  ย  JsonUtility.FromJson<TestData>(jsonData);


ย  ย  ย  ย  totalKill = testData.TotalKill;

ย  ย  }





์ด๋ ‡๊ฒŒ ํ–ˆ๋Š”๋ฐ ๋ฐ์ดํ„ฐ๊ฐ€ ์ €์žฅ์ด ์•ˆ๋œ๋‹ค. ์•ˆ๋“œ๋กœ์ด๋“œ ๋นŒ๋“œ๋ฅผ ํ–ˆ๋Š”๋ฐ ๋‚ด๊ฐ€ ์•„์ดํฐ์ด๋ผ์„œ ๋…น์Šค๋กœ ํ•ด๋ณด๋‹ˆ๊นŒ ์ €์žฅ์ด ์•ˆ๋˜๋”๋ผ

๋ญ๊ฐ€ ๋ฌธ์ œ๋ƒ