123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222 |
- using LitJson;
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using System.Text;
- using UnityEngine;
- using UnityEngine.Networking;
- using UnityEngine.UI;
- public class KangFuTwo : MonoBehaviour
- {
- List<KangFuItem> kangfulist = new List<KangFuItem>();
- public KangFuItem kitem;
- int sting;
- int fting;
- int zhen;
- int sji;
- int fji;
- int wo;
- public Text stingt;
- public Text ftingt;
- public Text zhent;
- public Text sjit;
- public Text fjit;
- public Text wot;
- public void add(int index)
- {
- switch(index)
- {
- case 0:
- sting++;
- break;
- case 1:
- fting++;
- break;
- case 2:
- zhen++;
- break;
- case 3:
- sji++;
- break;
- case 4:
- fji++;
- break;
- case 5:
- wo++;
- break;
- }
- initText();
- }
- void initText()
- {
- stingt.text = sting+"";
- ftingt.text = fting + "";
- zhent.text = zhen + "";
- sjit.text = sji + "";
- fjit.text = fji + "";
- wot.text = wo + "";
- }
- public void back()
- {
- for (int i = 1; i < WindowManager.Instance.KangFuDaList.Count; i++)
- {
- WindowManager.Instance.KangFuDaList[i].SetActive(false);
- }
- WindowManager.Instance.KangFuDaList[0].SetActive(true);
- }
- private void OnEnable()
- {
- initkangfulist();
- }
- public void shangbao()
- {
- StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/userInfo", (string str) => {
- JsonData datainfo = JsonMapper.ToObject(str);
- JsonData data = new JsonData();
- data["sting"] = sting;
- data["fting"] = fting;
- data["zhen"] = zhen;
- data["sji"] = sji;
- data["fji"] = fji;
- data["wo"] = wo;
- data["time"] = DateTime.Now.ToString();
- if (!datainfo["data"].Keys.Contains("info"))
- datainfo["data"]["info"] = new JsonData();
- try
- {
- datainfo["data"]["info"] = JsonMapper.ToObject(datainfo["data"]["info"].ToString());
- }
- catch
- {
- datainfo["data"]["info"] = new JsonData();
- }
- if (!datainfo["data"]["info"].IsArray)
- datainfo["data"]["info"] = new JsonData();
- datainfo["data"]["info"].Add(data);
- datainfo["data"]["info"] = datainfo["data"]["info"].ToJson();
- StartCoroutine(SendHttp2("cmcc-endustry/v1/report/dairyCattle/userInfo", datainfo["data"], (string msg) => {
- initkangfulist();
- }));
- }));
- }
- void initjishu()
- {
- sting = 0;
- fting = 0;
- zhen = 0;
- sji = 0;
- fji = 0;
- wo = 0;
- initText();
- }
- public void initkangfulist()
- {
- initjishu();
- for (int i = 0; i < kangfulist.Count; i++)
- {
- Destroy(kangfulist[i].gameObject);
- }
- kangfulist.Clear();
- StartCoroutine(SendHttp("cmcc-endustry/v1/report/dairyCattle/userInfo", (string str) => {
- JsonData data = JsonMapper.ToObject(str);
- if (!data["data"].Keys.Contains("info"))
- data["data"]["info"] = new JsonData();
-
- data["data"]["info"] = JsonMapper.ToObject(data["data"]["info"].ToString());
-
-
- if (!data["data"]["info"].IsArray)
- data["data"]["info"] = new JsonData();
- try
- {
- for (int i = 0; i < data["data"]["info"].Count; i++)
- {
- Debug.Log("jilu===>"+ data["data"]["info"].ToJson());
- if(data["data"]["info"][i].Keys.Contains("time"))
- {
- KangFuItem ki = GameObject.Instantiate(kitem, kitem.transform.parent);
- ki.setData(data["data"]["info"][i], i);
- ki.gameObject.SetActive(true);
- kangfulist.Add(ki);
- ki.transform.SetSiblingIndex(5);
- }
- }
- }
- catch
- {
- }
- }));
- }
- public IEnumerator SendHttp2(string methodName, JsonData fromDic, Action<string> CallBack)
- {
- Debug.Log("Start Queue SendHttp " + methodName + " fromDic===��"+ fromDic.ToJson());
- string url = "https://api-fat2.ghz-tech.com/" + methodName;
- UnityWebRequest webRequest;
- webRequest = UnityWebRequest.Post(url, "Post");
- byte[] bodyRaw = Encoding.UTF8.GetBytes(fromDic.ToJson());
- webRequest.uploadHandler = new UploadHandlerRaw(bodyRaw);
- webRequest.SetRequestHeader("Content-Type", "application/json");
- webRequest.SetRequestHeader("Authorization", "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8");
- yield return webRequest.SendWebRequest();
- if (webRequest.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.LogError(webRequest.error);
- }
- else
- {
- string result = webRequest.downloadHandler.text;
- CallBack.Invoke(result);
- }
- }
- public IEnumerator SendHttp(string methodName, Action<string> CallBack)
- {
- string url = "https://api-fat2.ghz-tech.com/" + methodName+"?name=" + KangFuOne.choosename;
- UnityWebRequest webRequest = UnityWebRequest.Get(url);
- string token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJleHAiOjMxNTM2MDAxNzEyNzQ0NjUxLCJpYXQiOjE3MTI3NDQ2NTEsInVzZXIiOnsiaWQiOjExLCJlbWFpbCI6IiIsInBob25lIjoieWIzIiwibmFtZSI6InliMyIsInJvbGVJZCI6M319.WGpVJHfbTr4Bp2cySjjlgCIon8nF4sJxkl58wcIion8";
- //UnityWebRequest webRequest = new UnityWebRequest(url, "GET");
- JsonData data = new JsonData();
- data["name"] = KangFuOne.choosename;
- webRequest.downloadHandler = (DownloadHandler)new DownloadHandlerBuffer();
- webRequest.SetRequestHeader("authorization", token);//����ͷ�ļ�����
- yield return webRequest.SendWebRequest();
- if (webRequest.result == UnityWebRequest.Result.ConnectionError)
- {
- Debug.Log(webRequest.error);
- }
- else
- {
- Debug.LogError(webRequest.downloadHandler.text);
- CallBack.Invoke(webRequest.downloadHandler.text);
- }
- }
- }
|