Bez popisu
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

AnimationStyleHelper.cs 2.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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.IsItemAnimation())
  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. if (serieType.IsDefined(typeof(DefaultAnimationAttribute), false))
  32. {
  33. animationType = serieType.GetAttribute<DefaultAnimationAttribute>().type;
  34. }
  35. UpdateAnimationType(serie.animation, animationType);
  36. }
  37. public static void UpdateAnimationType(AnimationStyle animation, AnimationType defaultType)
  38. {
  39. animation.context.type = animation.type == AnimationType.Default ?
  40. defaultType :
  41. animation.type;
  42. }
  43. public static bool GetAnimationPosition(AnimationStyle animation, bool isY, Vector3 lp, Vector3 cp, float progress, ref Vector3 ip)
  44. {
  45. if (animation.context.type == AnimationType.AlongPath)
  46. {
  47. var dist = Vector3.Distance(lp, cp);
  48. var rate = (dist - animation.context.currentPathDistance + animation.GetCurrDetail()) / dist;
  49. ip = Vector3.Lerp(lp, cp, rate);
  50. return true;
  51. }
  52. else
  53. {
  54. var startPos = isY ? new Vector3(-10000, progress) : new Vector3(progress, -10000);
  55. var endPos = isY ? new Vector3(10000, progress) : new Vector3(progress, 10000);
  56. return UGLHelper.GetIntersection(lp, cp, startPos, endPos, ref ip);
  57. }
  58. }
  59. }
  60. }