public static Nullable <SaveGame> LoadGame(string SaveName = "AutoSave.bin") { BinaryFormatter BFormatter = new BinaryFormatter(); FileStream LoadFile; try { LoadFile = File.Open(GetSaveGameFolder() + SaveName, FileMode.Open); SaveGame Instance = (SaveGame)BFormatter.Deserialize(LoadFile); Debug.Log("Loaded from instance..."); Debug.Log("Instance Items: " + Instance.ItemPosition.Length); Debug.Log("Item Checkup..."); for (int i = 0; i < Instance.ItemPosition.Length; i++) { Debug.Log("Item Type: " + Instance.ItemPosition[i].Type + " " + Instance.ItemPosition[i].Position.ToString()); } Debug.Log("Enemies: " + Instance.Enemies.Length); Debug.Log("Score:" + Instance.PlayerScore); Debug.Log("Scene: " + Instance.SceneName); LoadFile.Close(); return(Instance); } catch (FileNotFoundException Exception) { Debug.Log("File was not found " + Exception.Message); } return(null); }
/* * Load the button position from the file and returns the new class if found * null if not. */ public static AndroidButtonPosition Load() { BinaryFormatter BFormatter = new BinaryFormatter(); FileStream LoadFile; try { LoadFile = File.Open(Application.persistentDataPath + "/" + PlayerPrefs.GetString("AndroidControlPanelFile", "AndroidControlPanelSettings.bin"), FileMode.Open); AndroidButtonPosition Instance = (AndroidButtonPosition)BFormatter.Deserialize(LoadFile); Debug.Log("Loaded " + Instance.ToString()); LoadFile.Close(); return(Instance); } catch (FileNotFoundException Exception) { Debug.Log("File was not found " + Exception.Message); } return(null); }