Example #1
0
        public IEnumerator GetLevelListAsync(System.Action <LevelFile[]> p_onLoaded)
        {
            // show loading popup
            if (uMyGUI_PopupManager.Instance != null)
            {
                uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_LOADING);
            }

            // load file with the level file names
            WWW www = new WWW(UtilityPlatformIO.FixFilePath(Path.Combine(Application.persistentDataPath, LEVEL_FILE_NAMES_PATH)));

            yield return(www);

            string savedLevelFileNamesText;

            if (string.IsNullOrEmpty(www.error))
            {
                savedLevelFileNamesText = www.text;
            }
            else
            {
                savedLevelFileNamesText = "";
            }

            // hide loading popup
            if (uMyGUI_PopupManager.Instance != null)
            {
                uMyGUI_PopupManager.Instance.HidePopup(LE_FileSelectionHelpers.POPUP_LOADING);
            }

            // callback with the loaded level names
            string[] savedLevelFileNames = savedLevelFileNamesText.Split(new string[] { "\r\n", "\n" }, System.StringSplitOptions.RemoveEmptyEntries);
            if (p_onLoaded != null)
            {
                LevelFile[] levelFiles = new LevelFile[savedLevelFileNames.Length];
                for (int i = 0; i < levelFiles.Length; i++)
                {
                    levelFiles[i] = new LevelFile()
                    {
                        Name     = savedLevelFileNames[i],
                        PathData = Path.Combine(Application.persistentDataPath, savedLevelFileNames[i] + ".txt"),
                        PathIcon = Path.Combine(Application.persistentDataPath, savedLevelFileNames[i] + ".png")
                    };
                }
                p_onLoaded(levelFiles);
            }
        }
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 static void SelectLevel(MonoBehaviour p_worker, string p_popupTitle, string p_popupText, System.Action <int, LevelFile[]> p_onSelectedCallback)
 {
     LE_ExtensionInterface.FileSelectionExtensionLoader fileSelect = LE_ExtensionInterface.FileSelectionInstance;
     p_worker.StartCoroutine(fileSelect.LevelDB.GetLevelListAsync((LevelFile[] p_levelFiles) =>
     {
         if (uMyGUI_PopupManager.Instance != null)
         {
             // show file selection UI
             string[] levelNames     = LevelFile.GetLevelNames(p_levelFiles);
             string[] levelIconPaths = LevelFile.GetLevelIconPaths(p_levelFiles);
             ((LE_PopupFileSelection)uMyGUI_PopupManager.Instance.ShowPopup(LE_FileSelectionHelpers.POPUP_NAME))
             .SetFiles(levelNames, levelIconPaths, (int p_selectedIndex) => p_onSelectedCallback(p_selectedIndex, p_levelFiles), null, true)
             .SetText(p_popupTitle, p_popupText)
             .ShowButton("close");
         }
     }));
 }
Example #4
0
        public IEnumerator Delete(LevelFile p_levelFile, System.Action <bool> p_onResult)
        {
            // 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", () =>
            {
#if !UNITY_WEBPLAYER && !UNITY_WEBGL
                Directory.Delete(Path.GetDirectoryName(p_levelFile.PathData), true);
                if (p_onResult != null)
                {
                    p_onResult(true);
                }
#endif
            });
            yield return(null);
        }
Example #5
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);
                    }
                });
            }
        }