public static void SaveLevel(string p_levelDataFilePath, string p_levelIconFileName, byte[] p_levelData, byte[] p_levelMeta, int p_removedDuplicatesCount) { // info popup System.Action <string> infoPopup = (string p_infoText) => { if (uMyGUI_PopupManager.Instance != null) { if (p_removedDuplicatesCount > 0) { p_infoText += "\n'" + p_removedDuplicatesCount + "' duplicate object(s) removed before saving\n(duplicate = same: object, position, rotation, scale)."; } ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(POPUP_TEXT)).SetText("Level Saved", p_infoText).ShowButton("ok"); } }; // save level icon as png LE_SaveLoad.LevelMetaData loadedMeta = LE_SaveLoad.LoadLevelMetaFromByteArray(p_levelMeta, true); if (loadedMeta.Icon != null) { Texture2D downScaledIcon = LE_FileSelectionHelpers.DownscaleTexture(loadedMeta.Icon, 255, 128); // save to file string path = Path.Combine(Application.persistentDataPath, p_levelIconFileName); // need to use own implementation of SaveToFile to keep backwards compatibility with MRLE v1.31 (had no UtilityPlatformIO.SaveToFile(..., bytes[])) LE_FileSelectionHelpers.SaveToFile(path, downScaledIcon.EncodeToPNG()); Object.Destroy(loadedMeta.Icon); Object.Destroy(downScaledIcon); } // save level infoPopup(ExampleGame_LoadSave.SaveByFilePath(p_levelDataFilePath, p_levelData, p_levelMeta)); }
public void SaveFile(string p_levelName, byte[] p_levelData, byte[] p_levelMeta, int p_removedDuplicatesCount, LevelFile[] p_levelFiles, System.Action <string> p_onSuccess, System.Action p_onFail) { // check if this is a new level file name bool isExistingLevel = false; string[] levelNames = System.Array.ConvertAll(p_levelFiles, levelFile => levelFile.Name); for (int i = 0; i < levelNames.Length; i++) { if (levelNames[i] == p_levelName) { isExistingLevel = true; break; } } string levelDataFilePath = Path.Combine(Application.persistentDataPath, Path.Combine(p_levelName, p_levelName + ".txt")); string levelIconFilePath = Path.Combine(Application.persistentDataPath, Path.Combine(p_levelName, p_levelName + ".png")); if (!isExistingLevel) { // create directory Directory.CreateDirectory(Path.Combine(Application.persistentDataPath, p_levelName)); // save level LE_FileSelectionHelpers.SaveLevel(levelDataFilePath, levelIconFilePath, p_levelData, p_levelMeta, p_removedDuplicatesCount); if (p_onSuccess != null) { p_onSuccess(levelDataFilePath); } } else { // show confirm popup ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_TEXT)).SetText("Save Level", "The level '" + p_levelName + "' already exists, do you want to overwrite it?") .ShowButton("no", () => { // go back if (p_onFail != null) { p_onFail(); } }) .ShowButton("yes", () => { // save level LE_FileSelectionHelpers.SaveLevel(levelDataFilePath, levelIconFilePath, p_levelData, p_levelMeta, p_removedDuplicatesCount); if (p_onSuccess != null) { p_onSuccess(levelDataFilePath); } }); } }
public void SaveFile(string p_levelName, byte[] p_levelData, byte[] p_levelMeta, int p_removedDuplicatesCount, LevelFile[] p_levelFiles, System.Action <string> p_onSuccess, System.Action p_onFail) { // check if this is a new level file name bool isExistingLevel = false; string[] levelNames = LevelFile.GetLevelNames(p_levelFiles); for (int i = 0; i < levelNames.Length; i++) { if (levelNames[i] == p_levelName) { isExistingLevel = true; break; } } string levelDataFilePath = Path.Combine(Application.persistentDataPath, p_levelName + ".txt"); string levelIconFilePath = Path.Combine(Application.persistentDataPath, p_levelName + ".png"); if (!isExistingLevel) { // add new level file name to the list string[] updatedLevelNames = new string[levelNames.Length + 1]; System.Array.Copy(levelNames, updatedLevelNames, levelNames.Length); updatedLevelNames[updatedLevelNames.Length - 1] = p_levelName; System.Array.Sort(updatedLevelNames); string levelFileNamesText = ""; for (int i = 0; i < updatedLevelNames.Length; i++) { levelFileNamesText += updatedLevelNames[i] + "\n"; } string levelListFilePath = Path.Combine(Application.persistentDataPath, LEVEL_FILE_NAMES_PATH); UtilityPlatformIO.SaveToFile(levelListFilePath, levelFileNamesText); // save level LE_FileSelectionHelpers.SaveLevel(levelDataFilePath, levelIconFilePath, p_levelData, p_levelMeta, p_removedDuplicatesCount); if (p_onSuccess != null) { p_onSuccess(levelDataFilePath); } } else { // show confirm popup ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_TEXT)).SetText("Save Level", "The level '" + p_levelName + "' already exists, do you want to overwrite it?") .ShowButton("no", () => { // go back if (p_onFail != null) { p_onFail(); } }) .ShowButton("yes", () => { // save level LE_FileSelectionHelpers.SaveLevel(levelDataFilePath, levelIconFilePath, p_levelData, p_levelMeta, p_removedDuplicatesCount); if (p_onSuccess != null) { p_onSuccess(levelDataFilePath); } }); } }