[Memo-Unity] 18. JsonSaveLoad
์นดํ ๊ณ ๋ฆฌ: MeMo Unity
ํ๊ทธ: C#, MeMo Unity
JsonSaveLoad
JsonSaveLoad
1. JsonSaveLoad
JsonLoad
public class JsonLoad
{
public void SavePlayerData(CharacterStat player)
{
string jsonData = JsonUtility.ToJson(player, true);
string path = Path.Combine(Application.dataPath, "PlayerData.json");
File.WriteAllText(path, jsonData);
}
public CharacterStat LoadPlayerData(CharacterStat player)
{
string path = Path.Combine(Application.dataPath, "PlayerData.json");
string jsonData = File.ReadAllText(path);
player = JsonUtility.FromJson<CharacterStat>(jsonData);
return player;
}
}
2. Player
JsonLoad
public class Player : MonoBehaviour
{
[SerializeField]
CharacterStat player = new CharacterStat();
JsonLoad json = new JsonLoad();
void Start()
{
//SavePlayerData();
player = json.LoadPlayerData(player);
Debug.Log(player._level);
}
}
[Unity] JsonSaveLoad
TOP
๋๊ธ๋จ๊ธฐ๊ธฐ