//delete an existing user level file
        public static void DeleteUserLevel(string levelName)
        {
            string folder     = Application.persistentDataPath + "/UserLevels";
            string levelsInfo = "_UserLevelInfo";

            string pathToInfoFile  = Path.Combine(folder, levelsInfo) + ".json";
            string pathToLevelFile = Path.Combine(folder, levelName) + ".json";

            if (File.Exists(pathToInfoFile))
            {
                string     json         = File.ReadAllText(pathToInfoFile);
                UserLevels userInfoFile = JsonUtility.FromJson <UserLevels>(json);

                userInfoFile.levelNames.Remove(levelName);

                if (userInfoFile.numberOfUserLevels > 0)
                {
                    userInfoFile.numberOfUserLevels--;
                }
                else
                {
                    userInfoFile.numberOfUserLevels = 0;
                }

                File.Delete(pathToLevelFile);

                //save the new UserInfoFile
                InitializeUserLevelInfo(userInfoFile);
            }
        }
        //create a new level file
        public static void AddNewUserLevel(string levelName)
        {
            string folder = Application.persistentDataPath + "/UserLevels";
            string file   = "_UserLevelInfo.json";
            string path   = Path.Combine(folder, file);

            if (!File.Exists(path))
            {
                InitializeUserLevelInfo();
            }

            string     json       = File.ReadAllText(path);
            UserLevels userLevels = JsonUtility.FromJson <UserLevels>(json);

            //make sure that the file does not already contain this name
            if (!userLevels.levelNames.Contains(levelName))
            {
                userLevels.numberOfUserLevels++;
                userLevels.levelNames.Add(levelName);

                InitializeUserLevelInfo(userLevels);
            }

            //else throwback an error
        }
Exemplo n.º 3
0
        public static void DeleteUserLevel(string levelName)
        {
            string     folder     = Application.persistentDataPath + "/UserLevels";
            string     levelsInfo = Application.persistentDataPath + "/UserLevels/UserLevelInfo";
            UserLevels userLevels = JsonUtility.FromJson <UserLevels>(levelsInfo);

            userLevels.levelNames.Remove(levelName);
            userLevels.numberOfUserLevels--;

            InitializeUserLevelInfo(userLevels);
        }
Exemplo n.º 4
0
        public static void AddNewUserLevel(string levelName)
        {
            string folder = Application.persistentDataPath + "/UserLevels";
            string file   = "_UserLevelInfo.json";
            string path   = Path.Combine(folder, file);

            if (!File.Exists(path))
            {
                InitializeUserLevelInfo();
            }

            string     json       = File.ReadAllText(path);
            UserLevels userLevels = JsonUtility.FromJson <UserLevels>(json);

            userLevels.numberOfUserLevels++;
            userLevels.levelNames.Add(levelName);

            InitializeUserLevelInfo(userLevels);
        }
Exemplo n.º 5
0
        //use to initialize or refhresh an existing user info file
        public static void InitializeUserLevelInfo(UserLevels newUserLevels = default)
        {
            if (newUserLevels == default)
            {
                newUserLevels = new UserLevels();
            }

            string json      = JsonUtility.ToJson(newUserLevels);
            string folder    = Application.persistentDataPath + "/UserLevels";
            string levelFile = "_UserLevelInfo.json";

            string path = Path.Combine(folder, levelFile);

            if (!Directory.Exists(folder))
            {
                Directory.CreateDirectory(folder);
            }

            if (File.Exists(path))
            {
                File.Delete(path);
            }
            File.WriteAllText(path, json);
        }