Advertisement
Guest User

Untitled

a guest
Feb 15th, 2016
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. [System.Serializable]
  2. public class Login : MonoBehaviour {
  3.  
  4. public ArrayList PlayerNames;
  5. public ArrayList PlayerPass;
  6. public GameObject LoginName;
  7. public GameObject Password;
  8. public string Playname;
  9. public string Playerpass;
  10.  
  11.  
  12. // Use this for initialization
  13. void Start () {
  14. Load();
  15. PlayerNames = new ArrayList();
  16. PlayerPass = new ArrayList();
  17.  
  18.  
  19. }
  20.  
  21. // Update is called once per frame
  22. void Update () {
  23.  
  24.  
  25. }
  26.  
  27. public void Save()
  28. {
  29.  
  30. BinaryFormatter bf = new BinaryFormatter();
  31. FileStream username = File.Create(Application.persistentDataPath + "/username.gd");
  32. FileStream password = File.Create(Application.persistentDataPath + "/password.gd");
  33. bf.Serialize(username, PlayerNames);
  34. bf.Serialize(password, PlayerPass);
  35. username.Close();
  36. password.Close();
  37. Debug.Log("Saved");
  38. Debug.Log(PlayerNames);
  39.  
  40. }
  41.  
  42. public void Load()
  43. {
  44.  
  45. if (File.Exists(Application.persistentDataPath + "/username.gd") && File.Exists(Application.persistentDataPath + "/password.gd"))
  46. {
  47. Debug.LogError("Loaded");
  48.  
  49. BinaryFormatter bf = new BinaryFormatter();
  50. FileStream username = File.Open(Application.persistentDataPath + "/username.gd", FileMode.Open);
  51. FileStream password = File.Open(Application.persistentDataPath + "/password.gd", FileMode.Open);
  52. PlayerNames = (ArrayList)bf.Deserialize(username);
  53. PlayerPass = (ArrayList)bf.Deserialize(password);
  54. username.Close();
  55. password.Close();
  56.  
  57. }
  58. }
  59.  
  60. int i;
  61. string Playerpasz;
  62. public void CheckRegister()
  63. {
  64. Playname = LoginName.GetComponent<InputField>().text;
  65. Playerpass = Password.GetComponent<InputField>().text;
  66. if (PlayerNames.Contains(Playname))
  67. {
  68. int indexItem = PlayerNames.IndexOf(Playname);
  69. string pass = PlayerPass.IndexOf(indexItem).ToString();
  70.  
  71. foreach(var Passworz in PlayerPass)
  72. {
  73. if (i == indexItem) {
  74.  
  75. Playerpasz = Passworz.ToString();
  76. Debug.Log(Playerpasz);
  77. i = 0;
  78. }
  79. indexItem++;
  80. }
  81. Debug.Log("Username found: " + PlayerNames.IndexOf(Playname));
  82. // Debug.Log("Pass1:" + Playerpasz);
  83. // Debug.Log("Pass2:" + Playerpass);
  84.  
  85. if (Playerpasz == Playerpass)
  86. {
  87. Debug.LogError("Pasword found");
  88. LoginSucess();
  89. }
  90. else
  91. {
  92. Debug.LogError("Falsches Passwort");
  93. }
  94.  
  95. }
  96. else
  97. {
  98. Register();
  99.  
  100. }
  101. }
  102.  
  103. public void Register() {
  104. Debug.Log("Reg");
  105. PlayerNames.Add(Playname);
  106. PlayerPass.Add(Playerpass);
  107. Save();
  108. LoginSucess();
  109. }
  110. void LoginSucess()
  111. {
  112. Debug.LogError("Eingeloggt");
  113.  
  114. }
  115. }
  116. `
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement