[Memo-Unity] 18. JsonSaveLoad

์—…๋ฐ์ดํŠธ:

์นดํ…Œ๊ณ ๋ฆฌ:

ํƒœ๊ทธ: ,


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


๐Ÿ“”

๋Œ“๊ธ€๋‚จ๊ธฐ๊ธฐ