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; }
// 更新紀錄. 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); }
void Start() { Debug.Log(count); _score = GameObject.Find("ScoreCounter").GetComponent <ScoreCounter> (); _record = GameObject.Find("SceneController").GetComponent <SaveRecord> (); canvas.SetActive(false); }
private void Start() { SaveRecord loadedData = SaveLoadManager.Instance.LoadData(); if (loadedData != null) { highscore = loadedData.highscore; } }
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(); }
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); }
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; } }
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; }
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; }
/// <summary> /// Raises the SaveRecord event /// </summary> protected void OnSave() { SaveRecord?.Invoke(this, new EventArgs()); }
public void LoadAllData() { svRec = JsonUtility.FromJson <SaveRecord>(PlayerPrefs.GetString("SavedRecord")); }