KangFuOne.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. using LitJson;
  2. using System;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. using UnityEngine;
  6. using UnityEngine.Networking;
  7. using UnityEngine.UI;
  8. public class KangFuOne : MonoBehaviour
  9. {
  10. public Toggle tg;
  11. public List<Toggle> dd =new List<Toggle>();
  12. public static string choosename;
  13. public void gotoSet()
  14. {
  15. for (int i = 0; i < WindowManager.Instance.KangFuDaList.Count; i++)
  16. {
  17. WindowManager.Instance.KangFuDaList[i].SetActive(false);
  18. }
  19. WindowManager.Instance.KangFuDaList[2].SetActive(true);
  20. }
  21. public void gotoinfo()
  22. {
  23. for (int j = 0; j < dd.Count;j++)
  24. {
  25. if(dd[j].isOn)
  26. {
  27. choosename = dd[j].GetComponentInChildren<Text>().text;
  28. for (int i = 0; i < WindowManager.Instance.KangFuDaList.Count; i++)
  29. {
  30. WindowManager.Instance.KangFuDaList[i].SetActive(false);
  31. }
  32. WindowManager.Instance.KangFuDaList[1].SetActive(true);
  33. return;
  34. }
  35. }
  36. }
  37. public void back()
  38. {
  39. WindowManager.Instance.back();
  40. }
  41. private void Start()
  42. {
  43. }
  44. public Text debugtxt;
  45. private void OnEnable()
  46. {
  47. for (int i = 0; i < dd.Count; i++)
  48. {
  49. Destroy(dd[i].gameObject);
  50. }
  51. dd.Clear();
  52. StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/userList",(string str)=> {
  53. debugtxt.text += "\n"+str;
  54. JsonData data = JsonMapper.ToObject(str);
  55. for (int i = 0; i < data["data"]["list"].Count; i++)
  56. {
  57. Toggle dddata = GameObject.Instantiate(tg,tg.transform.parent);
  58. dddata.gameObject.SetActive(true);
  59. dddata.GetComponentInChildren<Text>().text = data["data"]["list"][i].ToString();
  60. dd.Add(dddata);
  61. }
  62. // choosename = data["data"]["list"][0].ToString();
  63. }));
  64. }
  65. public IEnumerator SendHttp(string methodName, Action<string> CallBack)
  66. {
  67. string url = "https://api-fat2.ghz-tech.com/" + methodName;
  68. debugtxt.text += "\n"+url;
  69. UnityWebRequest webRequest = UnityWebRequest.Get(url);
  70. webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
  71. webRequest.SetRequestHeader("Content-Type", "application/json");
  72. webRequest.SetRequestHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8");
  73. yield return webRequest.SendWebRequest();
  74. if (webRequest.result == UnityWebRequest.Result.ConnectionError)
  75. {
  76. debugtxt.text += "\nwebRequest.error" + webRequest.error;
  77. Debug.Log(webRequest.error);
  78. }
  79. else
  80. {
  81. debugtxt.text += "\nwebRequest.text" + webRequest.downloadHandler.text;
  82. Debug.LogError(webRequest.downloadHandler.text);
  83. CallBack.Invoke(webRequest.downloadHandler.text);
  84. }
  85. }
  86. }