Example03_ChartAnimation.cs 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. using UnityEngine;
  2. using XCharts.Runtime;
  3. namespace XCharts.Example
  4. {
  5. [DisallowMultipleComponent]
  6. [ExecuteInEditMode]
  7. public class Example03_ChartAnimation : MonoBehaviour
  8. {
  9. BaseChart chart;
  10. void Awake()
  11. {
  12. chart = gameObject.GetComponent<BaseChart>();
  13. if (chart == null)
  14. {
  15. chart = gameObject.AddComponent<BarChart>();
  16. chart.Init();
  17. }
  18. var serie = chart.GetSerie(0);
  19. serie.animation.enable = true;
  20. //自定义每个数据项的渐入延时
  21. serie.animation.fadeIn.delayFunction = CustomFadeInDelay;
  22. //自定义每个数据项的渐入时长
  23. serie.animation.fadeIn.durationFunction = CustomFadeInDuration;
  24. }
  25. float CustomFadeInDelay(int dataIndex)
  26. {
  27. return dataIndex * 1000;
  28. }
  29. float CustomFadeInDuration(int dataIndex)
  30. {
  31. return dataIndex * 1000 + 1000;
  32. }
  33. }
  34. }