Пример #1
0
        //Use this function when you want to register your account.
        public void RegisterAccount()
        {
            //First it will check if the inputfields are empty, if they are empty it will immidiatly stop the function.
            if (registerUsername.text == "" || registerPassword.text == "" || SaveFileName.text == "")
            {
                RespondText.text = "<color=red>Username, password or save file name has not been filled in.</color>";
                StartCoroutine(RemoveText(3));
                return;
            }
            else
            {
                SearchNewSaveFiles();
                //checks if files exist in the current directory it's checking.
                if (saveInfo.Length > 0)
                {
                    //foreach file found it will run the code below.
                    foreach (FileInfo Fi in saveInfo)
                    {
                        //it will load the current file the foreach has taken.
                        json = File.ReadAllText(Fi.ToString());

                        //it will get the information saved in the file and put the information in the dictionary and a string.
                        DataInfo = JsonConvert.DeserializeObject <SaveGameDataInfo>(json);
                        //the dictionary
                        accountHolder = DataInfo.Accounts;
                        //the string
                        LoadFileName = DataInfo.saveFileName;

                        //checks if the save file name of the username used for the account already exists, if it does it will stop the loop.
                        if (accountHolder.ContainsKey(registerUsername.text) || LoadFileName == DataInfo.saveFileName)
                        {
                            RespondText.text = "<color=red> account already exists.</color>";
                            StartCoroutine(RemoveText(3));
                            return;
                        }
                        //if that isn't the case it will register the account and stop the loop.
                        else
                        {
                            accountHolder.Add(registerUsername.text, registerPassword.text);
                            RespondText.text = "<color=blue>Account has been registered.</color>";
                            Data.SaveData();
                            StartCoroutine(RemoveText(3));
                            return;
                        }
                    }
                    ResetValues();
                }
                //if there are no files in the directory it will run the code below.
                else
                {
                    accountHolder.Add(registerUsername.text, registerPassword.text);
                    RespondText.text = "<color=blue>Account has been registered.</color>";
                    Data.SaveData();
                    ResetValues();
                    StartCoroutine(RemoveText(3));
                }
                accountHolder.Clear();
            }
        }
Пример #2
0
    public void SaveGame(string saveName)
    {
        GameData gameData = new GameData(GameObject.Find("BurgerMan").GetComponentInChildren <PlayerController2D>());

        if (gameData.level.Equals("Level1"))
        {
            gameData.AddMouse(GameObject.Find("Mouse"));
            gameData.AddEnemy(GameObject.Find("Enemy"));
            gameData.AddFallingObjs(new GameObject[3] {
                GameObject.Find("Tomato1"), GameObject.Find("Tomato2"), GameObject.Find("Tomato3")
            });
            gameData.AddDroppingFloors(new GameObject[5] {
                GameObject.Find("dropFloor1"), GameObject.Find("dropFloor2"), GameObject.Find("dropFloor3"), GameObject.Find("dropFloor4"), GameObject.Find("dropFloor5")
            });
        }
        else if (gameData.level.Equals("Level2"))
        {
            gameData.AddTomatoSlices1(new GameObject[3] {
                GameObject.Find("TomatoSlice1.1"), GameObject.Find("TomatoSlice1.2"), GameObject.Find("TomatoSlice1.3")
            });
            gameData.AddTomatoSlices2(new GameObject[3] {
                GameObject.Find("TomatoSlice2.1"), GameObject.Find("TomatoSlice2.2"), GameObject.Find("TomatoSlice2.3")
            });
            gameData.AddBurgerEnemies(new GameObject[6] {
                GameObject.Find("Enemy1"), GameObject.Find("Enemy2"), GameObject.Find("Enemy3"), GameObject.Find("Enemy4"), GameObject.Find("Enemy5"), GameObject.Find("Enemy6")
            });
            gameData.AddDroppingFloors(new GameObject[5] {
                GameObject.Find("dropFloor1"), GameObject.Find("dropFloor2"), GameObject.Find("dropFloor3"), GameObject.Find("dropFloor4"), GameObject.Find("dropFloor5"),
            });
        }

        SaveGameData.SaveData(gameData, saveName);
    }