Example #1
0
        /// <summary>
        /// Save data to a text file or to the clipboard in the WebPlayer
        /// </summary>
        public static string SaveByFilePath(string p_filePath, byte[] p_data, byte[] p_meta)
        {
            // YOU SHOULD ZIP THE LEVEL DATA! YOU CAN SAVE UP TO 95% DATA VOLUME, AVARAGE SEEMS TO BE AROUND 75% REDUCTION
            string dataAsString     = System.Convert.ToBase64String(p_data) + "#" + System.Convert.ToBase64String(p_meta);
            string levelSizeMessage = "Level size: '" + ((float)(p_data.Length + p_meta.Length) / 1048576f).ToString("0.00") + "' MB\n";

            UtilityPlatformIO.SaveToFile(p_filePath, dataAsString);
            return("Level saved to '" + p_filePath + "'.\n" +
                   levelSizeMessage +
                   "The load button will load from this file.");
        }
Example #2
0
 public IEnumerator Delete(LevelFile p_levelFile, System.Action <bool> p_onResult)
 {
     return(GetLevelListAsync((LevelFile[] p_levels) =>
     {
         // show confirm popup
         ((uMyGUI_PopupText)uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_TEXT)).SetText("Delete Level", "Do you really want to delete '" + p_levelFile.Name + "'?")
         .ShowButton("no", () =>
         {
             if (p_onResult != null)
             {
                 p_onResult(false);
             }
         })
         .ShowButton("yes", () =>
         {
             // remove level file name from the list
             List <string> updatedLevelNames = new List <string>();
             for (int i = 0; i < p_levels.Length; i++)
             {
                 if (p_levels[i].Name != p_levelFile.Name)
                 {
                     updatedLevelNames.Add(p_levels[i].Name);
                 }
             }
             string levelFileNamesText = "";
             for (int i = 0; i < updatedLevelNames.Count; i++)
             {
                 levelFileNamesText += updatedLevelNames[i] + "\n";
             }
             string levelListFilePath = Path.Combine(Application.persistentDataPath, LEVEL_FILE_NAMES_PATH);
             UtilityPlatformIO.SaveToFile(levelListFilePath, levelFileNamesText);
             // delete level files
             if (!string.IsNullOrEmpty(p_levelFile.PathData))
             {
                 File.Delete(p_levelFile.PathData);
             }
             if (!string.IsNullOrEmpty(p_levelFile.PathIcon))
             {
                 File.Delete(p_levelFile.PathIcon);
             }
             if (p_onResult != null)
             {
                 p_onResult(true);
             }
         });
     }));
 }
Example #3
0
        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);
                    }
                });
            }
        }