using System.Collections; using System.Collections.Generic; using System.Linq; using UnityEngine; using UnityEngine.UI; namespace Kill.UI.Components { public class Barchart : MonoBehaviour { public int dataCount = 10; public List data = new List(); public Text[] yAxisTexts; public GameObject sonPrefab; public Transform parent; void Start() { Init(new List() {}); } public void Init(List data) { if(parent.childCount>0) { for (int i = 0; i < parent.childCount; i++) { Destroy(parent.GetChild(i).gameObject); } } if(data==null||data.Count==0) return; this.data = data; float max= data.Max(); if(max==0) max = 3; if(max%3!=0) { max=max+3-max%3; } for (int i = 0; i < 3; i++) { yAxisTexts[i].text =(max/3*(i+1)).ToString(); } for (int i = 0; i < dataCount; i++) { GameObject go = Instantiate(sonPrefab, parent); go.SetActive(true); float value = data[i]/max; go.GetComponent().fillAmount = value; } } } }