hjfagkaj

fkagjfjkahfahfhabf

Sep 10th, 2016
41
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.66 KB | None | 0 0
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4.  
  5. public class LoginRegisterUser : MonoBehaviour {
  6. public string urlController = "http://www.n32fps2016.dx.am/controller.php?";
  7. public InputField inputUserLogin, inputPassLogin;
  8. public Text Aviso;
  9. public Button Login_Button,Register_Button;
  10.  
  11. public GameObject LoginPrefab, RegisterPrefab;
  12. [HideInInspector]
  13. public string username, email, newuser;
  14. bool logado,logando;
  15. float tempoErro;
  16.  
  17. void Awake(){
  18. DontDestroyOnLoad(gameObject);
  19. }
  20. public void Login(){
  21. if (logando) return;
  22. logando = true;
  23. if (logado){
  24. logando = false;
  25. return;
  26. }
  27. if (inputUserLogin.text.Trim() == "" || inputPassLogin.text.Trim() == ""){
  28. // ta faltando digitar senha ou usuario
  29. StartCoroutine(FadeAviso(false, 2,"Digite todos os campos!"));
  30. logando = false;
  31. return;
  32. }
  33. if (inputUserLogin.text.Contains(" ")){
  34. // campo preenchido de forma incorreta
  35. StartCoroutine(FadeAviso(false, 2, "Campo preenchido incorretamente!"));
  36. logando = false;
  37. return;
  38. }
  39. inputPassLogin.text = inputPassLogin.text.Replace(" ", "%20");
  40. string url = urlController + "request=login&user=" + inputUserLogin.text + "&pass=" + inputPassLogin.text;
  41. WWW www = new WWW(url);
  42. tempoErro = 0;
  43. while (!www.isDone){
  44. tempoErro += Time.deltaTime * .01f;
  45. Wait(Time.deltaTime);
  46. if (tempoErro > 10000){
  47. StartCoroutine(FadeAviso(false, 2, "Sem conexão com a internet!"));
  48. logando = false;
  49. return;
  50. }
  51. }
  52. string result = www.text;
  53. if (result == "Erro"){
  54. //erro de conexao com banco de dados
  55. StartCoroutine(FadeAviso(false, 2, "Ops! Erro em nosso datacenter!"));
  56. logando = false;
  57. return;
  58. }
  59. if (result == "Inexistente"){
  60. // usuario e ou senha invalidos
  61. StartCoroutine(FadeAviso(false,2, "Usuario informado incorreto ou inexistente!"));
  62. logando = false;
  63. return;
  64. }
  65. // ususario logado com sucesso, pegando dados
  66. string[] dados = result.Split('/');
  67. username = dados[0]; // nome de usuario
  68. email = dados[1]; // email
  69. newuser = dados[2];
  70. logado = true;
  71. StartCoroutine(FadeAviso(true,2, "Logado com sucesso!"));
  72. UnityEngine.SceneManagement.SceneManager.LoadSceneAsync(1);
  73. }
  74. void Register(){
  75.  
  76. }
  77. void Wait(float t){
  78. while (t > 0){
  79. t -= Time.deltaTime;
  80. }
  81. }
  82. IEnumerator FadeAviso(bool type, float t, string text) {
  83. Image Painel = Aviso.GetComponentInChildren<Image>();
  84. if (type) Painel.color = Painel.color = new Color32(0, 255, 150, 90); else Painel.color = new Color32(255, 0, 0, 90);
  85. Aviso.gameObject.SetActive(true); // ativando
  86. Aviso.text = text; // setando texto
  87. Aviso.CrossFadeAlpha(0, 0, true);
  88. Painel.CrossFadeAlpha(0, 0, true);
  89. Aviso.CrossFadeAlpha(1, .25f, true); // alpha em 0 pra 1
  90. Painel.CrossFadeAlpha(1, .25f, true);
  91. yield return new WaitForSeconds(.25f);
  92. yield return new WaitForSeconds(t); // esperando tempo de vida
  93. Aviso.CrossFadeAlpha(0, .25f, true);
  94. Painel.CrossFadeAlpha(0, .25f, true); // alpha em 1 pra 0
  95. yield return new WaitForSeconds(.25f);
  96. Aviso.gameObject.SetActive(false); // desativando
  97.  
  98. }
  99. }
Add Comment
Please, Sign In to add comment