123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157 |
- using System;
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- using UnityEngine.EventSystems;
- using UnityEngine.UI;
- using XCharts.Runtime;
- using static Manager;
- public class DataTypeManager : MonoBehaviour
- {
- public Text runttext;
- public RingChart pc2;
- JsonData jsonData;
- public Text TimeText;
- public List<GameObject> typelist;
- List<GameObject> objlist=new List<GameObject>();
- float total =0;
- float runct =0;
- public void init(JsonData data)
- {
- jsonData=data;
- int max =this.transform.childCount;
- for (int i = 0;i<objlist.Count;i++)
- {
- Destroy( objlist[i]);
- }
- total =0;
- runct=0;
- Debug.Log("init===>"+data["value"].Count);
- for (int i = 0;i<data["value"].Count;i++)
- {
- total+=float.Parse(data["value"][i]["count"].ToString());
- if(int.Parse(data["value"][i]["status"].ToString())==1)
- {
- runct+=float.Parse(data["value"][i]["count"].ToString());
- }
- }
- for (int i = 0;i<data["value"].Count;i++)
- {
- GameObject go =new GameObject("item_"+i);
- objlist.Add(go);
- go.transform.parent=this.transform;
- go.transform.localPosition = Vector3.zero;
- go.transform.localScale = Vector3.one;
- RawImage rw = go.AddComponent<RawImage>();
- FKItem rfkw = go.AddComponent<FKItem>();
- rfkw.init(data["value"][i]);
- rw.color = GetColor(int.Parse(data["value"][i]["status"].ToString()));
- go.GetComponent<RectTransform>().sizeDelta = new Vector2(float.Parse(data["value"][i]["count"].ToString())/total*100f, go.GetComponent<RectTransform>().sizeDelta.y);
- go.GetComponent<RectTransform>().pivot = new Vector2(0,0.5f);
- if(TimeText!=null)
- {
-
- EventTrigger trigger = go.AddComponent<EventTrigger>();
-
-
- EventTrigger.Entry entry = new EventTrigger.Entry();
- entry.eventID = EventTriggerType.PointerEnter;
-
-
- entry.callback.AddListener((data) => { OnButtonEnter((PointerEventData)data); });
-
-
- trigger.triggers.Add(entry);
-
- EventTrigger.Entry entry2 = new EventTrigger.Entry();
- entry2.eventID = EventTriggerType.PointerExit;
-
-
- entry2.callback.AddListener((data) => { OnButtonExit((PointerEventData)data); });
-
-
- trigger.triggers.Add(entry2);
- }
- }
- if(pc2!=null)
- {
- if(total==0)
- {
- total=1;
- }
- int guzhanglv =(int)(100-runct/total*100);
- int runlv =(int)100-guzhanglv;
- SerieData data1 = pc2.series[0].GetSerieData(0);
- data1.data[0] = float.Parse(jsonData["ratio"]["value"].ToString())*100 ;
- data1.data[1] = 100;
- Debug.Log("运行率:"+runlv+"%");
-
- if(runttext!=null)
- {
- runttext.text = "累计运行时长:"+(int)(1440*float.Parse(jsonData["ratio"]["value"].ToString()))+"分钟";
- }
- pc2.RefreshChart();
- }
- }
- private void OnButtonEnter(PointerEventData data)
- {
- float bz = data.pointerEnter.GetComponent<RectTransform>().anchoredPosition.x/100f * 23f;
- int fz = (int)bz;
- int miao = (int)((bz - fz)*60f);
- string miaostr =miao.ToString();
- if(miao<10)
- {
- miaostr="0"+miao;
- }
- string fzstr =fz.ToString();
- if(fz<10)
- {
- fzstr="0"+fz;
- }
- string timestr = fzstr+":"+miaostr;
- Debug.Log("time====>"+timestr );
-
- for (int i = 0;i<typelist.Count;i++)
- {
- typelist[i].SetActive(false);
- }
- TimeText.text = "时间:"+timestr;
- typelist[int.Parse(data.pointerEnter.GetComponent<FKItem>().data["status"].ToString())-1].SetActive(true);
-
- }
- private void OnButtonExit(PointerEventData data)
- {
- for (int i = 0;i<typelist.Count;i++)
- {
- typelist[i].SetActive(false);
- }
- TimeText.text = "";
- }
- public static Color GetColor(int colorid)
- {
- switch(colorid)
- {
- case 1:
- return Color.green;
- break;
- case 2:
- return Color.yellow;
- break;
- case 3:
- return Color.red;
- break;
- case 4:
- return Color.gray;
- break;
- }
- return Color.gray;
- }
- }
|