/// <summary> /// Loads the spawn data from file. /// </summary> /// <returns> True loading was successful </returns> public bool LoadSpawns() { string sceneName = SceneManager.GetActiveScene().name; string fileName = "Generated/Spawns/Enemy Spawns " + sceneName; TextAsset file = UnityEngine.Resources.Load(fileName) as TextAsset; if (!file) { Debug.LogError("No Spawn Data"); return(false); } BinaryFormatter bFormatter = new BinaryFormatter(); using (Stream stream = new MemoryStream(file.bytes)) { EnemyAllSpawnData spawnData = (EnemyAllSpawnData)bFormatter.Deserialize(stream); foreach (EnemySpawnData data in spawnData.allSpawns) { for (int i = 0; i < enemySpawnPoints.Count; i++) { if (int.Parse(enemySpawnPoints[i].gameObject.name) == data.blockId) { enemySpawnPoints[i].LoadData(data.blockId, data.spawnGroupData); break; } } } } Debug.Log("Spawns Loaded"); return(true); }
/// <summary> /// Saves the spawn data to file. /// </summary> public void SaveSpawns() { ReloadData(); BinaryFormatter bFormatter = new BinaryFormatter(); FileStream fStream = File.Create(Application.dataPath + "/Resources/Generated/Spawns/Enemy Spawns " + SceneManager.GetActiveScene().name + Extension); EnemyAllSpawnData spawnData = new EnemyAllSpawnData(enemySpawnPoints); bFormatter.Serialize(fStream, spawnData); fStream.Close(); Debug.Log("Spawns Saved"); }