public void SaveToFile(string fileName) { if (fileName == "" || fileName == null) { Debug.Log("No file specified to save"); return; } EasyFileSave saveFile = new EasyFileSave(fileName); Debug.Log("Filename:" + saveFile.GetFileName()); try { object[] obj = Resources.FindObjectsOfTypeAll <SerializedObject>(); //this ensures disabled object are also considered //object[] obj = Resources.FindObjectsOfType(typeof (SerializedObject)); //this ignores disabled objects foreach (object o in obj) { SerializedObject g = (SerializedObject)o; if (g.UUID == "") { continue; } saveFile.AddBinary(g.UUID, g.getSaveData()); //Debug.Log(g.UUID + " is saved"); } saveFile.Save(); PlayerPrefs.SetString("LastCheckPoint", fileName); PlayerPrefs.Save(); Debug.Log("saving done"); } catch (Exception e) { Debug.Log("Exception while saving file:" + e); } finally { saveFile.Dispose(); } }
/** Save level before going to next */ public bool SaveLevel(int level, int score, int timer) { savedName = currentUserName(); if (savedName != null) { myFile = new EasyFileSave(savedName); if (myFile.Load()) { Debug.Log("Level: " + level + " score: " + score + " Name:" + savedName + " Time: " + timer); myFile.Add("username", savedName); myFile.Add("level", level); myFile.Add("score", score); myFile.Add("timer", timer); if (myFile.Save()) { myFile.Dispose(); return(true); } else { return(false); } } } return(false); }
public void SaveData() { totalShotBullet += shotBullet; totalEnemyKilled += enemyKilled; myFile.Add("totalShotBullet", totalShotBullet); myFile.Add("totalEnemyKilled", totalEnemyKilled); myFile.Save(); }
public void SaveBreak(int cantidad, float barra) { EasyFileSave miarchivo = new EasyFileSave("Break"); miarchivo.Add("barra", barra); miarchivo.Add("cantidad", cantidad); miarchivo.Save(); }
public void SaveInventory() { myFile.AddSerialized("inventory", inventoryManager.inventory); myFile.AddSerialized("eqItems", Player.GetComponent <PlayerEquippedItems>().EquippedItemsArray); myFile.AddSerialized("shop", shop.inventory); myFile.Add("gold", gold.Wealth); myFile.Add("encounter", gameManager.nextEncounterNumber); myFile.Save(); }
public void SaveOpciones(float valorMusica, float valorSFX) { EasyFileSave miarchivo = new EasyFileSave("Opciones"); miarchivo.Add("Musica", valorMusica); miarchivo.Add("SFX", valorSFX); miarchivo.Save(); Debug.Log("Opciones Guardado"); }
public void Save(TextAsset asset) { EasyFileSave file = new EasyFileSave(asset.name); file.Add("text", asset.text); file.Save(); if (!allFileNames.Contains(asset.name)) { AddToFileNames(asset.name); } }
/********** New game button **********/ private void showInput() { // Debug.Log(field.text.ToString()); nameFromUser = field.text.Trim().ToString(); if (nameFromUser.Length != 0) // Check if name isn't blank { myFile = new EasyFileSave(nameFromUser); myFile.suppressWarning = false; /** Check if username exist */ if (myFile.Load()) { Debug.Log("Username already exist"); errorText.gameObject.SetActive(true); errorText.text = "Username already exist!"; } else { /** we are going to save username */ userData = new List <savedData>(); userData.Add(new savedData { username = nameFromUser, level = 0, score = 0, timer = 60 }); // Data set for new user myFile.AddSerialized("user", userData); myFile.Save(); /** Save current username in currentUser.dat file */ currentFile = new EasyFileSave("currentUserFile"); currentFile.Add("currentUser", nameFromUser); currentFile.Save(); if (myFile.Load() && currentFile.Load()) // Check if data saved { myFile.Dispose(); // Free data currentFile.Dispose(); // Free data FindObjectOfType <SceneLoader>().LoadNextScene(); } else { Debug.Log("Error while saving! Try again"); } } } else { errorText.gameObject.SetActive(true); } }
public void Save() { EasyFileSave myFile = new EasyFileSave(); myFile.Add("PlayerLevel", player.level); myFile.Add("PlayerExp", player.playerExp); myFile.Add("GoalExp", player.goalExp); myFile.Add("PlayerGold", player.gold); myFile.Add("PlayerDiamond", player.diamond); myFile.Add("PlayerSkipForward", player.skipForward); myFile.Add("MonsterKillRecord", player.monsterKillRecord); myFile.Add("PlayerTotalScore", player.playerTotalCP); myFile.Add("StartScene", player.StartScene); myFile.Add("Volume", soundManager.masterVolume); myFile.Add("VolumeSprite", soundManager.isMute); for (int i = 0; i < player.CollectionItemsId.Count; i++) { if (!myFile.GetList <int>("PlayerCollection").Contains(i)) { CollectionItemsId.Add(player.CollectionItemsId[i]); } } for (int i = 0; i < player.SkillItemsId.Count; i++) { if (!myFile.GetList <int>("PlayerSkills").Contains(i)) { SkillsItemsId.Add(player.SkillItemsId[i]); } } for (int i = 0; i < player.DialogueProgress.Count; i++) { if (!myFile.GetList <int>("PlayerProgress").Contains(i)) { PlayerProgressId.Add(player.DialogueProgress[i]); } } myFile.Add("PlayerSkills", SkillsItemsId); myFile.Add("PlayerCollection", CollectionItemsId); myFile.Add("PlayerProgress", PlayerProgressId); myFile.Save(); }
public void SaveData() { totalShotBullet += shotBullet; totalEnemyKilled += enemyKilled; totalEarnedCoin += earnedCoin; totalHat += hat; totalPotion += potion; totalSword += sword; myfile.Add("totalShotBullet", totalShotBullet); myfile.Add("totalEnemyKilled", totalEnemyKilled); myfile.Add("totalEarnedCoin", totalEarnedCoin); myfile.Add("totalHat", totalHat); myfile.Add("totalPotion", totalPotion); myfile.Add("totalSword", totalSword); myfile.Add("power", power); myfile.Add("defance", defance); myfile.Add("ability", ability); if (enemyKilled != 0 && bestEnemyKilled != 0 && shotBullet / enemyKilled <= bestShotBullet / bestEnemyKilled && enemyKilled > bestEnemyKilled) { bestShotBullet = shotBullet; bestEnemyKilled = enemyKilled; myfile.Add("bestShotBullet", bestShotBullet); myfile.Add("bestEnemyKilled", bestEnemyKilled); } else if (bestShotBullet == 0 && bestEnemyKilled == 0) { bestShotBullet = shotBullet; bestEnemyKilled = enemyKilled; myfile.Add("bestShotBullet", bestShotBullet); myfile.Add("bestEnemyKilled", bestEnemyKilled); } myfile.Save(); shotBullet = 0; enemyKilled = 0; earnedCoin = 0; sword = 0; hat = 0; potion = 0; }
public void SaveHeroe(HeroeBase heroe) { EasyFileSave miarchivo = new EasyFileSave(heroe.nombre); miarchivo.Add("nombre", heroe.nombre); miarchivo.Add("HeroeVidaActual", heroe.vidaActual); miarchivo.Add("HeroeVidaBase", heroe.vidaBase); miarchivo.Add("HeroeManaActual", heroe.manaActual); miarchivo.Add("HeroeManaBase", heroe.manaBase); miarchivo.Add("HeroeFuerza", heroe.fuerza); miarchivo.Add("HeroeInteligencia", heroe.inteligencia); miarchivo.Add("HeroeResistenciaF", heroe.resistenciaF); miarchivo.Add("HeroeResistenciaM", heroe.resistenciaM); miarchivo.Add("HeroeVelocidad", heroe.velocidad); miarchivo.Add("HeroeXP", heroe.cantidadXP); miarchivo.Add("HeroeNivel", heroe.nivel); miarchivo.Save(); Debug.Log(heroe.nombre + " Guardado"); }
private void AddToFileNames(string name) { allFileNames.Add(name); NAMES_FILE.AddSerialized("names", allFileNames); NAMES_FILE.Save(); }
void Update() { // When [S] key is pressed: SAVE. if (Input.GetKeyUp(KeyCode.S)) { Debug.Log(">> I'M GOING TO SAVE SOME DATA!" + "\n"); // Some values. equipment = new List <string>(); equipment.Add("Hammer"); equipment.Add("Knife"); equipment.Add("Rope"); initialLocation = new Vector3(101.5f, -30.4f, 22f); coins = new Dictionary <string, int>(); coins.Add("Copper", 1200); coins.Add("Silver", 450); coins.Add("Gold", 300); // Simple data. character = "Conan"; age = 30; strenght = 300.5f; has_sword = true; has_bow = false; myFile.Add("name", character); myFile.Add("age", age); myFile.Add("strenght", strenght); myFile.Add("has_sword", has_sword); myFile.Add("has_bow", has_bow); // GameObject data. myFile.Add("equipment", equipment); myFile.Add("coins", coins); myFile.Add("initialLocation", initialLocation); myFile.Add("player", gameObject.transform); // Class data (serialization). items = new List <Item>(); items.Add(new Item { name = "Gold", quantity = 15000 }); items.Add(new Item { name = "Darts", quantity = 24 }); items.Add(new Item { name = "Potions", quantity = 10 }); myFile.AddSerialized("items", items); // Custom Extension for managing BoxCollider myFile.AddCustom("collider", gameObject.GetComponent <BoxCollider>(), "BoxCollider"); // Save all the collected data. // At the end of the process, stored data is cleared to free memory. myFile.Save(); Debug.Log(">> Data saved in: " + myFile.GetFileName() + "\n"); ShowData(); } // When [L] key is pressed: LOAD. if (Input.GetKeyUp(KeyCode.L)) { // Load data from file. if (myFile.Load()) { Debug.Log(">> I'M GOING TO USE LOADED DATA!" + "\n"); // Simple data. character = myFile.GetString("name"); age = myFile.GetInt("age"); strenght = myFile.GetFloat("strenght"); has_sword = myFile.GetBool("has_sword"); has_bow = myFile.GetBool("has_bow"); // In this case, if 'nickname' key doesn't exist, 'user_1234' string is used. nickname = myFile.GetString("nickname", "user_1234"); // GameObject data. equipment = (List <string>)myFile.GetData("equipment"); coins = (Dictionary <string, int>)myFile.GetData("coins"); initialLocation = myFile.GetUnityVector3("initialLocation"); var tr = myFile.GetUnityTransform("player"); gameObject.transform.position = tr.position; gameObject.transform.rotation = tr.rotation; gameObject.transform.localScale = tr.localScale; // Class data (serialization). items = (List <Item>)myFile.GetDeserialized("items", typeof(List <Item>)); // Custom Extension for managing BoxCollider. var bc = myFile.GetCustom("collider", "BoxCollider"); var thisBoxColllider = gameObject.GetComponent <BoxCollider>(); thisBoxColllider.center = new Vector3 { x = bc["centerX"].ToFloat(), y = bc["centerY"].ToFloat(), z = bc["centerZ"].ToFloat() }; thisBoxColllider.isTrigger = bc["isTrigger"].ToBool(); // Loaded data has been used as needed. // Stored data is manually cleared to free memory. myFile.Dispose(); Debug.Log(">> Data loaded from: " + myFile.GetFileName() + "\n"); ShowData(); } } // When [A] key is pressed: APPEND. if (Input.GetKeyUp(KeyCode.A)) { // Simple data. myFile.Add("nickname", "The Warrior"); myFile.Add("age", 32); // Append this data to the current file content. // 'nickname' key is new, so its value is added to the file. // 'age' key already exists, so its current value is updated with this new one. myFile.Append(); Debug.Log(">> New data added to: " + myFile.GetFileName() + "\n"); Debug.Log(">> Age value updated to 32." + "\n"); Debug.Log(">> Added nickname." + "\n"); } // When [Del] key is pressed: FILE DELETE. if (Input.GetKeyUp(KeyCode.Delete)) { // Delete this file. // This method clears stored data as well. myFile.Delete(); Debug.Log(">> The file has been deleted." + "\n"); } // When [T] key is pressed: SAVING AND LOADING DATA TEST. if (Input.GetKeyUp(KeyCode.T)) { // Perform a test of writing and loading data. // ------------------------------------------- myFile.Delete(); // Add some values to the internal storage for saving and loading test. equipment = new List <string>(); equipment.Add("Hammer"); equipment.Add("Knife"); equipment.Add("Rope"); initialLocation = new Vector3(101.5f, -30.4f, 22f); character = "Conan"; age = 30; strenght = 300.5f; has_sword = true; has_bow = false; items = new List <Item>(); items.Add(new Item { name = "Gold", quantity = 15000 }); items.Add(new Item { name = "Darts", quantity = 24 }); items.Add(new Item { name = "Potions", quantity = 10 }); myFile.Add("name", character); myFile.Add("age", age); myFile.Add("strenght", strenght); myFile.Add("has_sword", has_sword); myFile.Add("has_bow", has_bow); myFile.Add("equipment", equipment); myFile.Add("initialLocation", initialLocation); myFile.Add("player", gameObject.transform); myFile.AddSerialized("items", items); myFile.AddCustom("collider", gameObject.GetComponent <BoxCollider>(), "BoxCollider"); // Test if (myFile.TestDataSaveLoad()) { Debug.Log("<color=green>GOOD! Go to step 2!</color>\n"); } else { Debug.Log("<color=red>OPS! SOMETHING WENT WRONG!</color>\n"); } } }
private void SaveGame() { easyFileSave.Add("points", points); easyFileSave.Save(); }