我正在尝试统一创建一个保存文件,保存和加载功能可以正常工作,但是未创建保存文件

时间:2019-06-07 19:48:23

标签: c#

因此,我目前正在统一使用C#在任何操作系统中创建保存文件 使用“ Application.persistentDataPath”命令。

在Windows 10上应该在 C:\ Users \ User \ AppData \ LocalLow 事实是,它不是在创建文件。

在打开应用程序时,将保存并存储数据,当我加载时,保存的所有内容都会出现

但是当应用程序关闭并再次打开时,以前保存的数据根本不存在

我只是想让它创建一个文件,并在其中保存数据

我尝试了几个视频,几个个人课程,并且每个人都遵循了

到目前为止,保存功能可以正常工作,但是如上所述,没有创建保存文件

using UnityEngine;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
using System.Collections;
using System.Collections.Generic;


public static class SaveSystem
{
    public static BeerPiratePS beerpirateps { get; private set; }
    public static BeerPS beerps { get; private set; }
    public static BeerPubPS beerpubps { get; private set; }
    public static FactoryPS factoryps { get; private set; }
    public static GlobalBeer globalbeer { get; private set; }
    public static BeerChemistsPS beerchem { get; private set; }
    public static MainButtonClick mainbuttonclick { get; private set; }

    public static void SavePlayer ()
    {
        BinaryFormatter formatter = new BinaryFormatter();

        FileStream stream = File.Create(Application.persistentDataPath + "/beerplayer.ber");
        Debug.Log("BEER SAVED AAAAAAAAAAAAAAAAAAA");
        PlayerData dataPub = new PlayerData(beerpubps);
        PlayerData dataDwarves = new PlayerData(factoryps);
        PlayerData dataPirates = new PlayerData(beerpirateps);
        PlayerData dataBrew = new PlayerData(beerps);
        PlayerData dataGlobal = new PlayerData(globalbeer);
        PlayerData dataChemist = new PlayerData(beerchem);
        PlayerData dataClick = new PlayerData(mainbuttonclick);

        formatter.Serialize(stream, dataPub);
        formatter.Serialize(stream, dataPirates);
        formatter.Serialize(stream, dataDwarves);
        formatter.Serialize(stream, dataBrew);
        formatter.Serialize(stream, dataGlobal);
        formatter.Serialize(stream, dataClick);
        formatter.Serialize(stream, dataChemist);
        stream.Close();
    }
 public static PlayerData LoadPlayer()
    {
        string path = Application.persistentDataPath + "/beerplayer.ber";

        if (File.Exists(path))
        {

           BinaryFormatter formatter = new BinaryFormatter();
           FileStream stream = File.Open(Application.persistentDataPath + "/beerplayer.ber", FileMode.Open);
           Debug.Log("BEER FOUND AAAAAAAAAAAAAAAAAAAAAAAAAAA");
           PlayerData dataPub = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataPirates = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataDwarves = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataBrew = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataGlobal = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataClick = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           PlayerData dataChemist = (PlayerData)formatter.Deserialize(stream) as PlayerData;
           stream.Close();

           return dataChemist;
        }
        else
        {
           Debug.LogError("NO BEER FOUND AAAAAAAAAAAAAAAAAAAAA" + path);
           return null;
        }
    }
}

令人惊讶的是,没有一次出现logError“ NO BEER FOUND AAAAAAAAAAAAAAAAAAAAA”

0 个答案:

没有答案