DOTweenProShortcuts.cs 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // Author: Daniele Giardini - http://www.demigiant.com
  2. // Created: 2018/07/13
  3. using System;
  4. using DG.Tweening.Core;
  5. using DG.Tweening.Plugins;
  6. using UnityEngine;
  7. #pragma warning disable 1591
  8. namespace DG.Tweening
  9. {
  10. public static class DOTweenProShortcuts
  11. {
  12. static DOTweenProShortcuts()
  13. {
  14. // Create stub instances of custom plugins, in order to allow IL2CPP to understand they must be included in the build
  15. #pragma warning disable 219
  16. SpiralPlugin stub = new SpiralPlugin();
  17. #pragma warning restore 219
  18. }
  19. #region Shortcuts
  20. #region Transform
  21. /// <summary>Tweens a Transform's localPosition in a spiral shape.
  22. /// Also stores the transform as the tween's target so it can be used for filtered operations</summary>
  23. /// <param name="duration">The duration of the tween</param>
  24. /// <param name="axis">The axis around which the spiral will rotate</param>
  25. /// <param name="mode">The type of spiral movement</param>
  26. /// <param name="speed">Speed of the rotations</param>
  27. /// <param name="frequency">Frequency of the rotation. Lower values lead to wider spirals</param>
  28. /// <param name="depth">Indicates how much the tween should move along the spiral's axis</param>
  29. /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
  30. public static Tweener DOSpiral(
  31. this Transform target, float duration, Vector3? axis = null, SpiralMode mode = SpiralMode.Expand,
  32. float speed = 1, float frequency = 10, float depth = 0, bool snapping = false
  33. ) {
  34. if (Mathf.Approximately(speed, 0)) speed = 1;
  35. if (axis == null || axis == Vector3.zero) axis = Vector3.forward;
  36. TweenerCore<Vector3, Vector3, SpiralOptions> t = DOTween.To(SpiralPlugin.Get(), () => target.localPosition, x => target.localPosition = x, (Vector3)axis, duration)
  37. .SetTarget(target);
  38. t.plugOptions.mode = mode;
  39. t.plugOptions.speed = speed;
  40. t.plugOptions.frequency = frequency;
  41. t.plugOptions.depth = depth;
  42. t.plugOptions.snapping = snapping;
  43. return t;
  44. }
  45. #endregion
  46. #if true // PHYSICS_MARKER
  47. #region Rigidbody
  48. /// <summary>Tweens a Rigidbody's position in a spiral shape.
  49. /// Also stores the transform as the tween's target so it can be used for filtered operations</summary>
  50. /// <param name="duration">The duration of the tween</param>
  51. /// <param name="axis">The axis around which the spiral will rotate</param>
  52. /// <param name="mode">The type of spiral movement</param>
  53. /// <param name="speed">Speed of the rotations</param>
  54. /// <param name="frequency">Frequency of the rotation. Lower values lead to wider spirals</param>
  55. /// <param name="depth">Indicates how much the tween should move along the spiral's axis</param>
  56. /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
  57. public static Tweener DOSpiral(
  58. this Rigidbody target, float duration, Vector3? axis = null, SpiralMode mode = SpiralMode.Expand,
  59. float speed = 1, float frequency = 10, float depth = 0, bool snapping = false
  60. ) {
  61. if (Mathf.Approximately(speed, 0)) speed = 1;
  62. if (axis == null || axis == Vector3.zero) axis = Vector3.forward;
  63. TweenerCore<Vector3, Vector3, SpiralOptions> t = DOTween.To(SpiralPlugin.Get(), () => target.position, target.MovePosition, (Vector3)axis, duration)
  64. .SetTarget(target);
  65. t.plugOptions.mode = mode;
  66. t.plugOptions.speed = speed;
  67. t.plugOptions.frequency = frequency;
  68. t.plugOptions.depth = depth;
  69. t.plugOptions.snapping = snapping;
  70. return t;
  71. }
  72. #endregion
  73. #endif
  74. #endregion
  75. }
  76. }