Advertisement
Guest User

Untitled

a guest
Jun 17th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UI;
  5. using SimpleJSON;
  6. using System.IO;
  7.  
  8. public class Loginform : MonoBehaviour
  9. {
  10. public GameObject inputUsername;
  11. public GameObject inputPassword;
  12. public Text displayText;
  13. private const string URL = "http://cameri.kivi-tv.net/api/login?username=";
  14. public Animator anim;
  15.  
  16. string writePath;
  17.  
  18. public List<string> writeList = new List<string> ();
  19.  
  20. void Start () {
  21. writePath = Application.dataPath + "/TestFile.txt";
  22.  
  23. AppendFile(writePath);
  24.  
  25. anim = GetComponent<Animator>();
  26. }
  27. public void Onclick () {
  28. string username = inputUsername.GetComponent<InputField>().text;
  29. string password = inputPassword.GetComponent<InputField>().text;
  30. WWW www = new WWW(URL + username + "&password=" + password);
  31.  
  32. StartCoroutine (request (www));
  33. }
  34. public void Button () {
  35. Onclick();
  36. }
  37.  
  38. IEnumerator request (WWW www)
  39. {
  40. yield return www;
  41.  
  42. JSONObject jsonstring = (JSONObject)JSON.Parse(www.data);
  43. string session = jsonstring["session_id"];
  44. string message = jsonstring["message"];
  45.  
  46. displayText.text = message;
  47. if (displayText.text == "Successful login")
  48. {
  49. anim.Play("Main anim");
  50. writeList.Add(session);
  51. }
  52. }
  53. void Update()
  54. {
  55.  
  56. }
  57. void AppendFile(string filePath)
  58. {
  59. StreamWriter sWriter;
  60.  
  61. if(!File.Exists(filePath))
  62. {
  63. sWriter = File.CreateText(Application.dataPath + "/TestFile.txt");
  64. }
  65. else
  66. {
  67. sWriter = new StreamWriter(filePath, append: true);
  68. }
  69. for (int k = 0; k < writeList.Count; k++)
  70. {
  71. sWriter.WriteLine(writeList[k]);
  72. }
  73. sWriter.Close();
  74. }
  75. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement