56 lines
1.4 KiB
C#
56 lines
1.4 KiB
C#
|
|
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<int> data = new List<int>();
|
||
|
|
public Text[] yAxisTexts;
|
||
|
|
public GameObject sonPrefab;
|
||
|
|
public Transform parent;
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
Init(new List<int>() {});
|
||
|
|
}
|
||
|
|
public void Init(List<int> 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<Image>().fillAmount = value;
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|