예제 #1
0
    public void PlayerDeath()
    {
        Playerdata     newplayerdata = new Playerdata(playername, 100, 0, 0, 0, 0, 0, 0);
        MainMenuManger mainMenu      = new MainMenuManger();
        SaveTool       saveTool      = new SaveTool();
        PlayerManger   playerManger  = new PlayerManger();

        playercards = mainMenu.CreatCardList();
        playerManger.PlayerDataSet(newplayerdata);
        saveTool.SaveCardList(playercards);
        saveTool.SavePlayerData();
        SceneManager.LoadScene(0);
    }
예제 #2
0
    public void GetName()
    {
        filename = inputname.text;
        Playerdata   playerdata   = new Playerdata(filename, 100, 0, 0, 0, 0, 0, 0);
        PlayerManger playerManger = new PlayerManger();

        playerManger.PlayerDataSet(playerdata);
        year       = DateTime.Now.Year.ToString();
        month      = DateTime.Now.Month.ToString();
        day        = DateTime.Now.Day.ToString();
        hour       = DateTime.Now.Hour.ToString();
        minute     = DateTime.Now.Minute.ToString();
        second     = DateTime.Now.Second.ToString();
        time       = year + "年" + month + "月" + day + "日";
        detailtime = hour + ":" + minute + ":" + second;
        SaveFile    saveFile    = new SaveFile(filename, time, detailtime);
        List <Card> newcardlist = CreatCardList();
        string      file        = JsonConvert.SerializeObject(newcardlist, Formatting.Indented);
        string      data        = JsonConvert.SerializeObject(playerdata, Formatting.Indented);

        files.Add(saveFile);
        string filestext    = JsonConvert.SerializeObject(files, Formatting.Indented);
        string filelistpath = Application.dataPath + "/Doc" + "/flielist.json";
        string savepath     = Application.dataPath + "/Doc/" + saveFile.file_name;

        if (!Directory.Exists(savepath))
        {
            Directory.CreateDirectory(savepath);
            StreamWriter sw = new StreamWriter(savepath + "/cardlist.json");
            sw.Write(file);
            sw.Close();
            StreamWriter saveplayerdata = new StreamWriter(savepath + "/playerdata.json");
            saveplayerdata.Write(data);
            saveplayerdata.Close();
            StreamWriter filelistwriter = new StreamWriter(filelistpath);
            filelistwriter.Write(filestext);
            filelistwriter.Close();
            SceneManager.LoadScene(1);
            Debug.Log("创建" + saveFile.file_name);
            Debug.Log(savepath);
        }
        else
        {
            Debug.Log("该名字存档已存在!请重新输入");
        }
    }
예제 #3
0
    public void ChooseFile()
    {
        string okpath = Application.dataPath + "/Doc/" + files[index].file_name + "/playerdata.json";

        if (File.Exists(okpath))
        {
            Debug.Log("file is real");
            StreamReader sr           = new StreamReader(okpath);                        //读取JSON文件
            string       str          = sr.ReadToEnd();
            Playerdata   loaddata     = JsonConvert.DeserializeObject <Playerdata>(str); //反序列化为List
            PlayerManger playerManger = new PlayerManger();
            playerManger.PlayerDataSet(loaddata);
            SceneManager.LoadScene(1);
            Debug.Log(str);
        }
        else
        {
            Debug.Log("Error");
        }
    }