public void SaveMap(string name = null, bool preset = true) { name = name ?? LevelOnPlay; name = name + ".json"; string fullPath = preset ? "Assets/Resources/" + this.directory + name : Path.Combine(Application.persistentDataPath, name); Debug.Log("Saving Grid to " + fullPath); if (File.Exists(fullPath)) { Debug.Log("Overwriting file at " + fullPath); } SerializedLevel level; try { level = new SerializedLevel(); level.SetPopulations(m_populationManager); level.SetPlot(m_plotIO.SavePlot()); } catch { Debug.LogError("Serialization error, NOT saved to protect existing saves"); return; } using (StreamWriter streamWriter = new StreamWriter(fullPath)) streamWriter.Write(JsonUtility.ToJson(level)); Debug.Log("Grid Saved to: " + fullPath); }
private SerializedLevel SaveLevel() { SerializedLevel level = new SerializedLevel(); // Serialize plot level.SetPopulations(this.populationManager); // Serialize Animals level.SetPlot(this.plotIO.SavePlot()); return(level); }
// no idea what these two do public void ClearAnimals() { SerializedLevel level = new SerializedLevel(); level.SetPopulations(m_populationManager); level.SetPlot(m_plotIO.SavePlot()); level.serializedPopulations = new SerializedPopulation[0]; this.PresetMap = level; foreach (Population population in m_populationManager.Populations) { population.RemoveAll(); } m_populationManager.Initialize(); }