Example_TestTime.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. public class Example_TestTime : MonoBehaviour
  8. {
  9. public int maxCache = 100;
  10. LineChart chart;
  11. int timestamp;
  12. void Awake()
  13. {
  14. chart = gameObject.GetComponent<LineChart>();
  15. AddData();
  16. chart.SetMaxCache(maxCache);
  17. }
  18. float m_LastTime = 0;
  19. double m_Value = 100;
  20. void Update()
  21. {
  22. if (Input.GetKeyDown(KeyCode.Space))
  23. {
  24. //AddData();
  25. }
  26. if (Time.time - m_LastTime > 0.1f)
  27. {
  28. timestamp += 3600;
  29. m_Value += 10;
  30. chart.AddData(0, timestamp, m_Value);
  31. m_LastTime = Time.time;
  32. }
  33. }
  34. void AddData()
  35. {
  36. chart.ClearData();
  37. timestamp = DateTimeUtil.GetTimestamp() - 10;
  38. for (int i = 0; i < 10; i++)
  39. {
  40. timestamp += i * 3600;
  41. double value = Random.Range(50, 200);
  42. chart.AddData(0, timestamp, value);
  43. }
  44. }
  45. }
  46. }