Advertisement
Guest User

Untitled

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