Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System.Collections.Generic;
- using System.Runtime.Serialization.Formatters.Binary;
- using System.IO;
- [System.Serializable]
- public class Login : MonoBehaviour {
- public ArrayList PlayerNames;
- public ArrayList PlayerPass;
- public GameObject LoginName;
- public GameObject Password;
- public string Playname;
- public string Playerpass;
- // Use this for initialization
- void Start () {
- Load();
- PlayerNames = new ArrayList();
- PlayerPass = new ArrayList();
- }
- // Update is called once per frame
- void Update () {
- }
- public void Save()
- {
- BinaryFormatter bf = new BinaryFormatter();
- FileStream username = File.Create(Application.persistentDataPath + "/username.gd");
- FileStream password = File.Create(Application.persistentDataPath + "/password.gd");
- bf.Serialize(username, PlayerNames);
- bf.Serialize(password, PlayerPass);
- username.Close();
- password.Close();
- Debug.Log("Saved");
- Debug.Log(PlayerNames);
- }
- public void Load()
- {
- if (File.Exists(Application.persistentDataPath + "/username.gd") && File.Exists(Application.persistentDataPath + "/password.gd"))
- {
- Debug.LogError("Loaded");
- BinaryFormatter bf = new BinaryFormatter();
- FileStream username = File.Open(Application.persistentDataPath + "/username.gd", FileMode.Open);
- FileStream password = File.Open(Application.persistentDataPath + "/password.gd", FileMode.Open);
- PlayerNames = (ArrayList)bf.Deserialize(username);
- PlayerPass = (ArrayList)bf.Deserialize(password);
- username.Close();
- password.Close();
- }
- }
- int i;
- string Playerpasz;
- public void CheckRegister()
- {
- Playname = LoginName.GetComponent<InputField>().text;
- Playerpass = Password.GetComponent<InputField>().text;
- if (PlayerNames.Contains(Playname))
- {
- int indexItem = PlayerNames.IndexOf(Playname);
- string pass = PlayerPass.IndexOf(indexItem).ToString();
- foreach(var Passworz in PlayerPass)
- {
- if (i == indexItem) {
- Playerpasz = Passworz.ToString();
- Debug.Log(Playerpasz);
- i = 0;
- }
- indexItem++;
- }
- Debug.Log("Username found: " + PlayerNames.IndexOf(Playname));
- // Debug.Log("Pass1:" + Playerpasz);
- // Debug.Log("Pass2:" + Playerpass);
- if (Playerpasz == Playerpass)
- {
- Debug.LogError("Pasword found");
- LoginSucess();
- }
- else
- {
- Debug.LogError("Falsches Passwort");
- }
- }
- else
- {
- Register();
- }
- }
- public void Register() {
- Debug.Log("Reg");
- PlayerNames.Add(Playname);
- PlayerPass.Add(Playerpass);
- Save();
- LoginSucess();
- }
- void LoginSucess()
- {
- Debug.LogError("Eingeloggt");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement