AnimationStyleHelper.cs 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using UnityEngine;
  2. using XUGL;
  3. namespace XCharts.Runtime
  4. {
  5. public static class AnimationStyleHelper
  6. {
  7. public static float CheckDataAnimation(BaseChart chart, Serie serie, int dataIndex, float destProgress, float startPorgress = 0)
  8. {
  9. if (!serie.animation.IsDataAnimation())
  10. {
  11. serie.animation.context.isAllItemAnimationEnd = false;
  12. return destProgress;
  13. }
  14. if (serie.animation.IsFinish())
  15. {
  16. serie.animation.context.isAllItemAnimationEnd = false;
  17. return destProgress;
  18. }
  19. var isDataAnimationEnd = true;
  20. var currHig = serie.animation.CheckItemProgress(dataIndex, destProgress, ref isDataAnimationEnd, startPorgress);
  21. if (!isDataAnimationEnd)
  22. {
  23. serie.animation.context.isAllItemAnimationEnd = false;
  24. }
  25. return currHig;
  26. }
  27. public static void UpdateSerieAnimation(Serie serie)
  28. {
  29. var serieType = serie.GetType();
  30. var animationType = AnimationType.LeftToRight;
  31. var enableSerieDataAnimation = true;
  32. if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
  33. {
  34. var attribute = serieType.GetAttribute<DefaultAnimationAttribute>();
  35. animationType = attribute.type;
  36. enableSerieDataAnimation = attribute.enableSerieDataAddedAnimation;
  37. }
  38. UpdateAnimationType(serie.animation, animationType,enableSerieDataAnimation);
  39. }
  40. public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType, bool enableSerieDataAnimation)
  41. {
  42. animation.context.type = animation.type == AnimationType.Default ?
  43. defaultType :
  44. animation.type;
  45. animation.context.enableSerieDataAddedAnimation = enableSerieDataAnimation;
  46. }
  47. public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip)
  48. {
  49. if (animation.context.type == AnimationType.AlongPath)
  50. {
  51. var dist = Vector3.Distance(lp, cp);
  52. var rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
  53. ip = Vector3.Lerp(lp, cp, rate);
  54. return true;
  55. }
  56. else
  57. {
  58. var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
  59. var endPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);
  60. return UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip);
  61. }
  62. }
  63. }
  64. }