PlayAnManager.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using DG.Tweening;
  5. using UnityEngine.UI;
  6. using UnityEngine.Networking;
  7. using System;
  8. using System.Text;
  9. using LitJson;
  10. public class PlayAnManager : MonoBehaviour
  11. {
  12. int ct = 0;
  13. public List<GameObject> niunailist;
  14. bool isJi;
  15. public GameObject mike;
  16. public Animation animation;
  17. // Start is called before the first frame update
  18. void Start()
  19. {
  20. StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/total", new JsonData(), (string msg) => {
  21. JsonData data = JsonMapper.ToObject(msg);
  22. int ct2 = int.Parse(data["data"]["list"]["001"].ToString())%14;
  23. ct = ct2 % 7;
  24. tongct = (ct / 7);
  25. }));
  26. }
  27. public bool isplayend;
  28. public void playan(string str)
  29. {
  30. Debug.Log("jinai====>");
  31. if(!isJi)
  32. {
  33. isplayend = true;
  34. Debug.Log("jinai====2>");
  35. isJi = true;
  36. mike.transform.DOScale(new Vector3(mike.transform.localScale.x, 0.25f, mike.transform.localScale.z), 1f).OnComplete(() => {
  37. mike.transform.localScale = new Vector3(mike.transform.localScale.x, 0, mike.transform.localScale.z);
  38. }); ;
  39. animation.Play(str);
  40. Invoke("stopPlayan", 2f);
  41. }
  42. }
  43. int tongct=0;
  44. void stopPlayan()
  45. {
  46. isJi = false;
  47. animation.Stop();
  48. niunailist[ct].SetActive(true);
  49. ct++;
  50. JsonData fromDic = new JsonData();
  51. fromDic["device"]= "001";
  52. StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle", fromDic, (string msg)=> { }));
  53. if(ct>= niunailist.Count)
  54. {
  55. for (int i = 0; i < niunailist.Count; i++)
  56. {
  57. niunailist[i].SetActive(false);
  58. }
  59. ct = 0;
  60. tongct++;
  61. }
  62. TaskManager.sj.endtime = DateTime.Now.ToString();
  63. TaskManager.sj.xlct = ct;
  64. TaskManager.sj.wczs = tongct;
  65. TaskManager.sj.mcsc = (int)timecr;
  66. TaskManager.creatcsvAsync();
  67. timecr = 0;
  68. }
  69. public IEnumerator SendHttp(string methodName, JsonData fromDic, Action<string> CallBack, bool isPost = true)
  70. {
  71. Debug.Log("Start Queue SendHttp " + methodName);
  72. string url = "https://api-fat2.ghz-tech.com/" + methodName;
  73. UnityWebRequest webRequest;
  74. if (!isPost)
  75. {
  76. url += "?";
  77. foreach (var item in fromDic.Keys)
  78. {
  79. url += item + "=" + fromDic[item] + "&";
  80. }
  81. webRequest = UnityWebRequest.Get(url);
  82. }
  83. else
  84. {
  85. webRequest = UnityWebRequest.Post(url, "Post");
  86. webRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(fromDic.ToJson()));//添加raw类型的body,内容为json的byte[]
  87. webRequest.SetRequestHeader("Content-Type", "application/json");
  88. webRequest.SetRequestHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8");
  89. }
  90. yield return webRequest.SendWebRequest();
  91. if (webRequest.result == UnityWebRequest.Result.ConnectionError)
  92. {
  93. Debug.Log(webRequest.error);
  94. }
  95. else
  96. {
  97. string result = webRequest.downloadHandler.text;
  98. Debug.Log(result);
  99. CallBack(result);
  100. }
  101. }
  102. public float timecr;
  103. public Text t;
  104. // Update is called once per frame
  105. void Update()
  106. {
  107. if (Input.GetKeyDown(KeyCode.K))
  108. {
  109. playan("pawL");
  110. }
  111. t.text = "当前进度" + ct + "/" + niunailist.Count + "\n 完成桶数:" + tongct;
  112. timecr = timecr + Time.deltaTime;
  113. }
  114. }