123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354 |
- using System.Collections;
- using System.Collections.Generic;
- using LitJson;
- using UnityEngine;
- using UnityEngine.UI;
- public class DataTypeManager : MonoBehaviour
- {
- List<GameObject> objlist=new List<GameObject>();
- public void init(JsonData data)
- {
- int max =this.transform.childCount;
- for (int i = 0;i<objlist.Count;i++)
- {
- Destroy( objlist[i]);
- }
- float total =0;
- for (int i = 0;i<data["value"].Count;i++)
- {
- total+=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>();
- 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);
- }
- }
- 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;
- }
- }
|