64 lines
1.5 KiB
C#
64 lines
1.5 KiB
C#
|
|
using System;
|
||
|
|
using System.Collections;
|
||
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
using UnityEngine.EventSystems;
|
||
|
|
using XCharts.Runtime;
|
||
|
|
using Random = UnityEngine.Random;
|
||
|
|
|
||
|
|
public class PieData : MonoBehaviour,IPointerClickHandler
|
||
|
|
{
|
||
|
|
private PieChart pieChart;
|
||
|
|
private Serie serie;
|
||
|
|
|
||
|
|
void Start()
|
||
|
|
{
|
||
|
|
/*pieChart = gameObject.GetComponent<PieChart>();
|
||
|
|
serie = pieChart.series[0];
|
||
|
|
serie.label.position = LabelStyle.Position.Inside;*/
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnEnable()
|
||
|
|
{
|
||
|
|
pieChart = gameObject.GetComponent<PieChart>();
|
||
|
|
serie = pieChart.series[0];
|
||
|
|
serie.label.position = LabelStyle.Position.Inside;
|
||
|
|
StartCoroutine(Data());
|
||
|
|
}
|
||
|
|
|
||
|
|
private IEnumerator Data()
|
||
|
|
{
|
||
|
|
while (true)
|
||
|
|
{
|
||
|
|
int range = Random.Range(0,3);
|
||
|
|
|
||
|
|
if (Random.Range(0,2)==0)
|
||
|
|
{
|
||
|
|
if (serie.data[range].data[1] < 50)
|
||
|
|
{
|
||
|
|
serie.data[range].data[1]++;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
else
|
||
|
|
{
|
||
|
|
if (serie.data[range].data[1] > 5)
|
||
|
|
{
|
||
|
|
serie.data[range].data[1]--;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
pieChart.RefreshChart();
|
||
|
|
int time = Random.Range(2, 5);
|
||
|
|
yield return new WaitForSeconds(time); // 等待两秒
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
public void OnPointerClick(PointerEventData eventData)
|
||
|
|
{
|
||
|
|
// serie.data[0].data[1]++;
|
||
|
|
}
|
||
|
|
}
|