Exemple #1
0
        private void BuildSaveRecord(string filePath)
        {
            string fileName = filePath.Replace(Application.persistentDataPath + "\\", "");

            fileName = fileName.Replace(".sav", "");

            var stateDict = new Dictionary <string, object>();

            using (FileStream stream = File.Open(filePath, FileMode.Open))
            {
                BinaryFormatter formatter = new BinaryFormatter();
                stateDict = (Dictionary <string, object>)formatter.Deserialize(stream);
            }

            stateDict = (Dictionary <string, object>)stateDict["player"];
            var        state      = (Dictionary <string, string>)stateDict["ButtonGame.Attributes.PlayerInfo"];
            SaveRecord saveRecord = new SaveRecord();

            saveRecord.playerName = state["name"];
            saveRecord.rank       = state["rank"];
            saveRecord.time       = state["time"];
            saveRecord.quest      = state["quest"];
            saveRecord.location   = state["location"];
            saveRecord.scene      = state["scene"];

            saveLookup[fileName] = saveRecord;
        }
Exemple #2
0
    // 更新紀錄.
    public bool RecordNow()
    {
        SaveRecord Temp = new SaveRecord();

        Temp.iStage      = DataPlayer.pthis.iStage;
        Temp.iPlayTime   = DataPlayer.pthis.iPlayTime;
        Temp.iEnemyKill  = DataPlayer.pthis.iEnemyKill;
        Temp.iPlayerLost = DataPlayer.pthis.iPlayerLost;
        Temp.szTime      = System.DateTime.Now.ToString();

        Data.Add(Temp);

        Save();

        Data.Sort();

        int iRecCount = Data.Count;

        if (iRecCount > 0 && Data[iRecCount - 1].szTime == Temp.szTime)
        {
            return(true);
        }

        return(false);
    }
Exemple #3
0
 void Start()
 {
     Debug.Log(count);
     _score  = GameObject.Find("ScoreCounter").GetComponent <ScoreCounter> ();
     _record = GameObject.Find("SceneController").GetComponent <SaveRecord> ();
     canvas.SetActive(false);
 }
Exemple #4
0
    private void Start()
    {
        SaveRecord loadedData = SaveLoadManager.Instance.LoadData();

        if (loadedData != null)
        {
            highscore = loadedData.highscore;
        }
    }
Exemple #5
0
    public void SaveData(SaveRecord data)
    {
        JSONObject playerSaveData = data.SaveToJSON();

        //SAVE JSON IN COMPUTER
        string path = Application.persistentDataPath + "/SaveData.json";

        File.WriteAllText(path, playerSaveData.ToString());
    }
        public void Load(object state)
        {
            //Casts the data as a SaveRecord
            SaveRecord record = (SaveRecord)state;

            //Reads the data
            _currency = record.cash;
            _roaches  = record.roaches;

            //Updates the UI
            UpdateRoach();
            UpdateCash();
        }
Exemple #7
0
    public SaveRecord LoadData()
    {
        string path = Application.persistentDataPath + "/SaveData.json";

        if (System.IO.File.Exists(path))
        {
            string     jsonString = File.ReadAllText(path);
            JSONObject playerJson = (JSONObject)JSON.Parse(jsonString);

            //SET VALUES
            SaveRecord retrievedData = new SaveRecord((int)playerJson["Highscore"]);
            return(retrievedData);
        }
        return(null);
    }
Exemple #8
0
        private void BuildLookup()
        {
            saveLookup = new Dictionary <string, SaveRecord>();

            List <string> filePaths = Directory.GetFiles(Application.persistentDataPath, "*.dat").ToList();

            // List<string> saveFiles = new List<string>();
            // saveFiles.Add("auto");
            // for (int i = 1; i < 20; i++)
            // {
            //     if(PlayerPrefs.HasKey("save" + i))
            //     {
            //         saveFiles.Add("save" + i);
            //     }
            // }
            foreach (var filePath in filePaths)
            {
                // if(!PlayerPrefs.HasKey(filePath))
                // {
                //     continue;
                // }

                string fileName = filePath.Replace(Application.persistentDataPath + Path.DirectorySeparatorChar, "");
                fileName = fileName.Replace(".dat", "");

                // string saveString = PlayerPrefs.GetString(saveFile);
                // var stateDict = JsonUtility.FromJson<Dictionary<string, object>>(saveString);
                var stateDict = new Dictionary <string, object>();
                using (FileStream stream = File.Open(filePath, FileMode.Open))
                {
                    BinaryFormatter formatter = new BinaryFormatter();
                    stateDict = (Dictionary <string, object>)formatter.Deserialize(stream);
                }

                stateDict = (Dictionary <string, object>)stateDict["ScriptController"];
                var        state      = (Dictionary <string, string>)stateDict["BasicFunctions"];
                SaveRecord saveRecord = new SaveRecord();

                saveRecord.playerName = state["name"];
                saveRecord.money      = state["money"];
                saveRecord.energy     = state["energy"];
                saveRecord.location   = state["location"];
                saveRecord.scene      = state["scene"];

                saveLookup[fileName] = saveRecord;
            }
        }
Exemple #9
0
        public void AddSaveRecord(string saveFile)
        {
            BuildLookup();

            ISlotInfo slotInfo = GameObject.FindGameObjectWithTag("Player").GetComponent <ISlotInfo>();
            var       state    = (Dictionary <string, string>)slotInfo.CaptureState();

            SaveRecord newRecord = new SaveRecord();

            newRecord.playerName = state["name"];
            newRecord.rank       = state["rank"];
            newRecord.time       = state["time"];
            newRecord.quest      = state["quest"];
            newRecord.location   = state["location"];
            newRecord.scene      = state["scene"];

            saveLookup[saveFile] = newRecord;
        }
Exemple #10
0
        public void AddSaveRecord(string saveFile)
        {
            if (saveLookup == null)
            {
                BuildLookup();
            }

            ISlotInfo slotInfo = GameObject.FindGameObjectWithTag("GameController").GetComponent <ISlotInfo>();
            var       state    = (Dictionary <string, string>)slotInfo.CaptureState();

            SaveRecord newRecord = new SaveRecord();

            newRecord.playerName = state["name"];
            newRecord.money      = state["money"];
            newRecord.energy     = state["energy"];
            newRecord.location   = state["location"];
            newRecord.scene      = state["scene"];

            saveLookup[saveFile] = newRecord;
        }
Exemple #11
0
 /// <summary>
 /// Raises the SaveRecord event
 /// </summary>
 protected void OnSave()
 {
     SaveRecord?.Invoke(this, new EventArgs());
 }
Exemple #12
0
 public void LoadAllData()
 {
     svRec = JsonUtility.FromJson <SaveRecord>(PlayerPrefs.GetString("SavedRecord"));
 }