DoTweenPathHelper.cs 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System.Collections;
  2. using System.Collections.Generic;
  3. using DG.Tweening;
  4. using DG.Tweening.Core;
  5. using DG.Tweening.Plugins.Core.PathCore;
  6. using DG.Tweening.Plugins.Options;
  7. using UnityEngine;
  8. using UnityEngine.Events;
  9. public class DoTweenPathHelper : MonoBehaviour {
  10. public void DoPath(DOTweenPath sourcePath)
  11. {
  12. if (sourcePath == null)
  13. {
  14. return;
  15. }
  16. TweenerCore<Vector3, Path, PathOptions> t = sourcePath.isLocal ? sourcePath.transform.DOLocalPath(sourcePath.wps.ToArray(), sourcePath.duration, sourcePath.pathType,sourcePath.pathMode).SetOptions(sourcePath.isClosedPath, AxisConstraint.None, sourcePath.lockRotation) : sourcePath.transform.DOPath(sourcePath.wps.ToArray(), sourcePath.duration, sourcePath.pathType, sourcePath.pathMode).SetOptions(sourcePath.isClosedPath, AxisConstraint.None, sourcePath.lockRotation);
  17. switch (sourcePath.orientType)
  18. {
  19. case OrientType.ToPath:
  20. if (sourcePath.assignForwardAndUp)
  21. {
  22. t.SetLookAt(sourcePath.lookAhead, new Vector3?(sourcePath.forwardDirection), new Vector3?(sourcePath.upDirection));
  23. break;
  24. }
  25. t.SetLookAt(sourcePath.lookAhead, new Vector3?(), new Vector3?());
  26. break;
  27. case OrientType.LookAtTransform:
  28. if ((Object)sourcePath.lookAtTransform != (Object)null)
  29. {
  30. if (sourcePath.assignForwardAndUp)
  31. {
  32. t.SetLookAt(sourcePath.lookAtTransform, new Vector3?(sourcePath.forwardDirection), new Vector3?(sourcePath.upDirection));
  33. break;
  34. }
  35. t.SetLookAt(sourcePath.lookAtTransform, new Vector3?(), new Vector3?());
  36. break;
  37. }
  38. break;
  39. case OrientType.LookAtPosition:
  40. if (sourcePath.assignForwardAndUp)
  41. {
  42. t.SetLookAt(sourcePath.lookAtPosition, new Vector3?(sourcePath.forwardDirection), new Vector3?(sourcePath.upDirection));
  43. break;
  44. }
  45. t.SetLookAt(sourcePath.lookAtPosition, new Vector3?(), new Vector3?());
  46. break;
  47. }
  48. t.SetDelay<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.delay).SetLoops<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.loops, sourcePath.loopType).SetAutoKill<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.autoKill).SetUpdate<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.updateType).OnKill<TweenerCore<Vector3, Path, PathOptions>>((TweenCallback)(() => sourcePath.tween = (Tween)null));
  49. if (sourcePath.isSpeedBased)
  50. t.SetSpeedBased<TweenerCore<Vector3, Path, PathOptions>>();
  51. if (sourcePath.easeType == Ease.INTERNAL_Custom)
  52. t.SetEase<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.easeCurve);
  53. else
  54. t.SetEase<TweenerCore<Vector3, Path, PathOptions>>(sourcePath.easeType);
  55. if (!string.IsNullOrEmpty(sourcePath.id))
  56. t.SetId<TweenerCore<Vector3, Path, PathOptions>>((object)sourcePath.id);
  57. if (sourcePath.hasOnStart)
  58. {
  59. if (sourcePath.onStart != null)
  60. t.OnStart<TweenerCore<Vector3, Path, PathOptions>>(new TweenCallback(sourcePath.onStart.Invoke));
  61. }
  62. else
  63. sourcePath.onStart = (UnityEvent)null;
  64. if (sourcePath.hasOnPlay)
  65. {
  66. if (sourcePath.onPlay != null)
  67. t.OnPlay<TweenerCore<Vector3, Path, PathOptions>>(new TweenCallback(sourcePath.onPlay.Invoke));
  68. }
  69. else
  70. sourcePath.onPlay = (UnityEvent)null;
  71. if (sourcePath.hasOnUpdate)
  72. {
  73. if (sourcePath.onUpdate != null)
  74. t.OnUpdate<TweenerCore<Vector3, Path, PathOptions>>(new TweenCallback(sourcePath.onUpdate.Invoke));
  75. }
  76. else
  77. sourcePath.onUpdate = (UnityEvent)null;
  78. if (sourcePath.hasOnStepComplete)
  79. {
  80. if (sourcePath.onStepComplete != null)
  81. t.OnStepComplete<TweenerCore<Vector3, Path, PathOptions>>(new TweenCallback(sourcePath.onStepComplete.Invoke));
  82. }
  83. else
  84. sourcePath.onStepComplete = (UnityEvent)null;
  85. if (sourcePath.hasOnComplete)
  86. {
  87. if (sourcePath.onComplete != null)
  88. t.OnComplete<TweenerCore<Vector3, Path, PathOptions>>(new TweenCallback(sourcePath.onComplete.Invoke));
  89. }
  90. else
  91. sourcePath.onComplete = (UnityEvent)null;
  92. t.Play<TweenerCore<Vector3, Path, PathOptions>>();
  93. sourcePath.tween = (Tween)t;
  94. if (!sourcePath.hasOnTweenCreated || sourcePath.onTweenCreated == null)
  95. return;
  96. sourcePath.onTweenCreated.Invoke();
  97. }
  98. }