コード例 #1
0
        //Use this function when you want to login into an existing account.
        public void AccountLogin()
        {
            //First it will check if the inputfields are empty, if they are empty it will immidiatly stop the function.
            if (loginUsername.text == "" || loginPassword.text == "")
            {
                RespondText.text = "<color=red>You got to put something in the inputfield, otherwise it wont work.</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;

                        //First it will check if the current information taken from the file equals the information from the inputfields.
                        //if it is true it will load the data from that account and end the loop.
                        if (accountHolder.ContainsKey(loginUsername.text) && accountHolder.ContainsValue(loginPassword.text))
                        {
                            RespondText.text = "<color=blue>Account information correct.</color>";
                            Data.LoadData(LoadFileName);
                            StartCoroutine(RemoveText(3));
                            Data.SaveUsername();
                            ResetValues();
                            SceneManager.LoadScene("Level 1");
                            return;
                        }
                        //if the information doesn't exist in the files it will give an error message that the password or username is incorrect.
                        else if (!accountHolder.ContainsKey(loginUsername.text) || !accountHolder.ContainsValue(loginPassword.text))
                        {
                            RespondText.text = "<color=red>Username or password is not correct.</color>";
                            StartCoroutine(RemoveText(3));
                        }
                        accountHolder.Clear();
                    }
                    ResetValues();
                }
                //if there are no files in the directory it will give an error that there are no files found.
                else
                {
                    RespondText.text = "<color=red>No save files found. Please register your account first.</color>";
                    ResetValues();
                    StartCoroutine(RemoveText(3));
                }
            }
        }
コード例 #2
0
    private IEnumerator LoadSceneRoutine(string saveName)
    {
        bool     destory  = false;
        GameData saveGame = SaveGameData.LoadData(saveName);

        if (saveGame == null)
        {
            yield break;
        }

        if (!SceneManager.GetActiveScene().name.Equals(saveGame.level))
        {
            destory = true;
            DontDestroyOnLoad(this);
            SceneManager.LoadScene(saveGame.level);
        }



        while (!SceneManager.GetActiveScene().name.Equals(saveGame.level))
        {
            new WaitForSecondsRealtime(.5f);
            yield return(null);
        }
        //GameObject[] newSceneObj = SceneManager.GetSceneByName(saveGame.level).GetRootGameObjects();

        PlayerController2D player = GameObject.Find("BurgerMan").GetComponent <PlayerController2D>();

        player.maxHealth              = saveGame.maxHealth;
        player.currentHealth          = saveGame.currentHealth;
        player.currentLives           = saveGame.currentLives;
        PlayerController2D.livesValue = saveGame.currentLives;
        player.moveSpeed              = saveGame.moveSpeed;
        player.jumpForce              = saveGame.jumpForce;
        player.transform.position     = new Vector3(saveGame.playerPosition[0], saveGame.playerPosition[1], saveGame.playerPosition[2]);

        if (saveGame.level.Equals("Level1"))
        {
            SpawnSaveObj("Mouse", "Mouse", "", saveGame.mousePosition, saveGame.mouseScale);
            SpawnSaveObj("Enemy", "Enemy", "", saveGame.enemyPosistion, saveGame.enemyScale);
            SpawnSaveObj("Tomato", "FallingObjects", saveGame.fallingObjPosition, saveGame.fallingObjScale);
            SpawnSaveObj("dropFloor", "Floor", saveGame.droppingFloorPos, saveGame.droppingFloorScale);
        }
        else if (saveGame.level.Equals("Level2"))
        {
            SpawnSaveObj("TomatoSlice1.", "TomatoSlices", saveGame.tomatoSlicePos1, saveGame.tomatoSliceScale1);
            SpawnSaveObj("TomatoSlice2.", "TomatoSlices", saveGame.tomatoSlicePos2, saveGame.tomatoSliceScale2);
            SpawnSaveObj("Enemy", "BurgerEnemies", saveGame.burgerEnemiesPos, saveGame.burgerEnemiesScale);
            SpawnSaveObj("dropFloor", "Dropping floors", saveGame.droppingFloorPos, saveGame.droppingFloorScale);
        }

        ResumeGame();
        if (destory)
        {
            Destroy(this);
        }
    }
コード例 #3
0
 public void LoadGame()
 {
     if (SaveGameData.LoadData("/save.dat") != null)
     {
         PauseMenu pauseMenu = GameObject.FindObjectOfType <PauseMenu>();
         pauseMenu.LoadGame("/save.dat");
     }
     else
     {
         Debug.Log("No save file found");
     }
 }
コード例 #4
0
 public void Back()
 {
     if (SaveGameData.LoadData("/temp.dat") == null)
     {
         SceneManager.LoadScene(1);
     }
     else
     {
         PauseMenu pauseMenu = GameObject.FindObjectOfType <PauseMenu>();
         pauseMenu.LoadGame("/temp.dat");
         SaveGameData.DeleteSave("/temp.dat");
     }
 }
コード例 #5
0
 /// <summary>
 /// Lädt den letzten Speicherpunkt.
 /// </summary>
 private void LoadLastSaveGame()
 {
     SaveGameData.current = SaveGameData.LoadData();
 }