Exemplo n.º 1
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 = 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);
                    }
                });
            }
        }
Exemplo n.º 2
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);
                    }
                });
            }
        }