コード例 #1
0
    public void SaveDataToFile(GamePalyer _player)
    {
        string filePath = Application.persistentDataPath + "/" + DATA_PATH;

        Debug.Log("Saving At : " + filePath);
        string savedData = JsonUtility.ToJson(_player);

        File.WriteAllText(filePath, savedData);
    }
コード例 #2
0
    void Start()
    {
        GamePalyer p = new GamePalyer();

        p.Id    = 1;
        p.Name  = "John Smith";
        p.Score = 100;
        Debug.Log("Starts Saving");
        SaveDataToFile(p);
        ReadData();
    }
コード例 #3
0
    public void ReadData()
    {
        string filePath = Application.persistentDataPath + "/" + DATA_PATH;

        if (File.Exists(filePath))
        {
            string     data   = File.ReadAllText(filePath);;
            GamePalyer player = JsonUtility.FromJson <GamePalyer>(data);
            Debug.Log(player.Id);
            Debug.Log(player.Name);
            Debug.Log(player.Score);
        }
    }