Exemplo n.º 1
0
    public static GM.PlayerData LoadPlayerData()
    {
        string path = Application.persistentDataPath + "/PlayerData/" + "PlayerData" + ".data";

        if (File.Exists(path))
        {
            BinaryFormatter formatter = new BinaryFormatter();
            FileStream      stream    = new FileStream(path, FileMode.Open,
                                                       FileAccess.Read,
                                                       FileShare.Read);
            //stream.Position = 0;

            GM.PlayerData data = new GM.PlayerData();

            //stream.Seek(0, SeekOrigin.Begin);

            data = formatter.Deserialize(stream) as GM.PlayerData;
            stream.Close();


            return(data);
        }
        else
        {
            Debug.Log("<color=red>Load Error</color>");
            return(null);
        }
    }
Exemplo n.º 2
0
    //----------------------------------

    //PlayerData------------------------
    public static void SavePlayerData(GM.PlayerData _playerData)
    {
        BinaryFormatter formatter = new BinaryFormatter();

        string path = Application.persistentDataPath + "/PlayerData";

        if (!Directory.Exists(path))
        {
            Directory.CreateDirectory(path);
        }
        path += "/" + "PlayerData" + ".data";

        FileStream stream = new FileStream(path,
                                           FileMode.Create,
                                           FileAccess.Write, FileShare.None);

        stream.Seek(0, SeekOrigin.Begin);

        formatter.Serialize(stream, _playerData);
        stream.Close();
        stream.Dispose();
    }