Unity XChart心跳图代码
using UnityEngine;
using XCharts.Runtime;
using Random = UnityEngine.Random;

public class TestControl : MonoBehaviour
{
LineChart chart;
float value;
float m_LastTime;
private bool _isStatus;

void Awake()
{
chart = gameObject.GetComponent<LineChart>();
// chart.SetMaxCache(maxCache);
AddData();
}

void Update()
{
if (Input.GetKeyDown(KeyCode.P))
{
_isStatus = !_isStatus;
AddData();
}
if (Time.time - m_LastTime >= 1f)
{
if (_isStatus)
{
RandomData();
}
else
{
RandomData2();
}
m_LastTime = Time.time;
}


}
void AddData()
{
chart.ClearData();
value = Random.Range(50, 60);
for (int i = 0; i < 100; i++)
{
RandomData();
}
}

void RandomData()
{
value = Random.Range(50, 60);
chart.AddData(0, value);
}
void RandomData2()
{
value = Random.Range(80, 100);
chart.AddData(0, value);
}
}
上一篇
下一篇