//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)); } } }
//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(); } }