using System.Collections; using System.Collections.Generic; using UnityEngine; using DG.Tweening; using UnityEngine.UI; using UnityEngine.Networking; using System; using System.Text; using LitJson; public class PlayAnManager : MonoBehaviour { int ct = 0; public List niunailist; bool isJi; public GameObject mike; public Animation animation; // Start is called before the first frame update void Start() { StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/total", new JsonData(), (string msg) => { JsonData data = JsonMapper.ToObject(msg); int ct2 = int.Parse(data["data"]["list"]["001"].ToString())%14; ct = ct2 % 7; tongct = (ct / 7); })); } public bool isplayend; public void playan(string str) { Debug.Log("jinai====>"); if(!isJi) { isplayend = true; Debug.Log("jinai====2>"); isJi = true; mike.transform.DOScale(new Vector3(mike.transform.localScale.x, 0.25f, mike.transform.localScale.z), 1f).OnComplete(() => { mike.transform.localScale = new Vector3(mike.transform.localScale.x, 0, mike.transform.localScale.z); }); ; animation.Play(str); Invoke("stopPlayan", 2f); } } int tongct=0; void stopPlayan() { isJi = false; animation.Stop(); niunailist[ct].SetActive(true); ct++; JsonData fromDic = new JsonData(); fromDic["device"]= "001"; StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle", fromDic, (string msg)=> { })); if(ct>= niunailist.Count) { for (int i = 0; i < niunailist.Count; i++) { niunailist[i].SetActive(false); } ct = 0; tongct++; } TaskManager.sj.endtime = DateTime.Now.ToString(); TaskManager.sj.xlct = ct; TaskManager.sj.wczs = tongct; TaskManager.sj.mcsc = (int)timecr; TaskManager.creatcsvAsync(); timecr = 0; } public IEnumerator SendHttp(string methodName, JsonData fromDic, Action CallBack, bool isPost = true) { Debug.Log("Start Queue SendHttp " + methodName); string url = "https://api-fat2.ghz-tech.com/" + methodName; UnityWebRequest webRequest; if (!isPost) { url += "?"; foreach (var item in fromDic.Keys) { url += item + "=" + fromDic[item] + "&"; } webRequest = UnityWebRequest.Get(url); } else { webRequest = UnityWebRequest.Post(url, "Post"); webRequest.uploadHandler = new UploadHandlerRaw(Encoding.UTF8.GetBytes(fromDic.ToJson()));//添加raw类型的body,内容为json的byte[] webRequest.SetRequestHeader("Content-Type", "application/json"); webRequest.SetRequestHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8"); } yield return webRequest.SendWebRequest(); if (webRequest.result == UnityWebRequest.Result.ConnectionError) { Debug.Log(webRequest.error); } else { string result = webRequest.downloadHandler.text; Debug.Log(result); CallBack(result); } } public float timecr; public Text t; // Update is called once per frame void Update() { if (Input.GetKeyDown(KeyCode.K)) { playan("pawL"); } t.text = "当前进度" + ct + "/" + niunailist.Count + "\n 完成桶数:" + tongct; timecr = timecr + Time.deltaTime; } }