public void Save(bool useTemp, bool deleteTemp = true) { if (Data == null) { Debug.LogError("Tile Map Data is null, cannot save! Invalid loaded map!"); return; } // Should be in editor mode for this to work correctly, but it theoretically also works even at runtime. string zipFilePath = Data.SavedZipPath; Debug.Log("Saving map '{0}' to {1}".Form(this, zipFilePath)); string fileSaveDir = null; if (useTemp) { // Save to a temporary folder. fileSaveDir = Path.Combine(Path.GetTempPath(), Data.InternalName); } else { // Save to the extracted (unzipped) folder, and then zip it up anyway. fileSaveDir = Path.Combine(GameIO.UnzippedMapsDirectory, Data.InternalName); } // Save all map data to file. Debug.Log("Saving files to '{0}' ({1}) ...".Form(fileSaveDir, useTemp ? "temp" : "pers")); GameIO.EnsureDirectory(fileSaveDir); var fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_DATA_FILE)); MapIO.WriteTileIDs(fs, TileIDs); MapIO.End(fs); // Save metadata. GameIO.ObjectToFile(this.Data, Path.Combine(fileSaveDir, METADATA_FILE)); // Work out all the tile varieties. // TODO fs = MapIO.StartWrite(Path.Combine(fileSaveDir, TILE_VARIATION_FILE)); MapIO.WriteTileVariations(fs, this.TileVariations); MapIO.End(fs); // Grab all the saved files, and zip the up into the save zip path. MapIO.Zip(fileSaveDir, zipFilePath); // Delete the temporary directory, just to be clean. if (useTemp && deleteTemp) { Directory.Delete(fileSaveDir, true); } Debug.Log("Finished saving, zipped to '{0}'".Form(zipFilePath)); }