< Summary

Class:DG.Tweening.DOTweenModulePhysics2D
Assembly:PluginScripts
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModulePhysics2D.cs
Covered lines:0
Uncovered lines:57
Coverable lines:57
Total lines:193
Line coverage:0% (0 of 57)
Covered branches:0
Total branches:0

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity NPath complexity Sequence coverage
DOMove(...)0%2100%
DOMoveX(...)0%2100%
DOMoveY(...)0%2100%
DORotate(...)0%2100%
DOJump(...)0%6200%
DOPath(...)0%12300%
DOLocalPath(...)0%12300%
DOPath(...)0%2100%
DOLocalPath(...)0%2100%

File(s)

/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModulePhysics2D.cs

#LineLine coverage
 1// Author: Daniele Giardini - http://www.demigiant.com
 2// Created: 2018/07/13
 3
 4#if true && (UNITY_4_3 || UNITY_4_4 || UNITY_4_5 || UNITY_4_6 || UNITY_5 || UNITY_2017_1_OR_NEWER) // MODULE_MARKER
 5using System;
 6using DG.Tweening.Core;
 7using DG.Tweening.Plugins;
 8using DG.Tweening.Plugins.Core.PathCore;
 9using DG.Tweening.Plugins.Options;
 10using UnityEngine;
 11
 12#pragma warning disable 1591
 13namespace DG.Tweening
 14{
 15  public static class DOTweenModulePhysics2D
 16    {
 17        #region Shortcuts
 18
 19        #region Rigidbody2D Shortcuts
 20
 21        /// <summary>Tweens a Rigidbody2D's position to the given value.
 22        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
 23        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 24        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 25        public static TweenerCore<Vector2, Vector2, VectorOptions> DOMove(this Rigidbody2D target, Vector2 endValue, flo
 26        {
 027            TweenerCore<Vector2, Vector2, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, endV
 028            t.SetOptions(snapping).SetTarget(target);
 029            return t;
 30        }
 31
 32        /// <summary>Tweens a Rigidbody2D's X position to the given value.
 33        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
 34        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 35        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 36        public static TweenerCore<Vector2, Vector2, VectorOptions> DOMoveX(this Rigidbody2D target, float endValue, floa
 37        {
 038            TweenerCore<Vector2, Vector2, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, new 
 039            t.SetOptions(AxisConstraint.X, snapping).SetTarget(target);
 040            return t;
 41        }
 42
 43        /// <summary>Tweens a Rigidbody2D's Y position to the given value.
 44        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
 45        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 46        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 47        public static TweenerCore<Vector2, Vector2, VectorOptions> DOMoveY(this Rigidbody2D target, float endValue, floa
 48        {
 049            TweenerCore<Vector2, Vector2, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, new 
 050            t.SetOptions(AxisConstraint.Y, snapping).SetTarget(target);
 051            return t;
 52        }
 53
 54        /// <summary>Tweens a Rigidbody2D's rotation to the given value.
 55        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations</summary>
 56        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 57        public static TweenerCore<float, float, FloatOptions> DORotate(this Rigidbody2D target, float endValue, float du
 58        {
 059            TweenerCore<float, float, FloatOptions> t = DOTween.To(() => target.rotation, target.MoveRotation, endValue,
 060            t.SetTarget(target);
 061            return t;
 62        }
 63
 64        #region Special
 65
 66        /// <summary>Tweens a Rigidbody2D's position to the given value, while also applying a jump effect along the Y a
 67        /// Returns a Sequence instead of a Tweener.
 68        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations.
 69        /// <para>IMPORTANT: a rigidbody2D can't be animated in a jump arc using MovePosition, so the tween will directl
 70        /// <param name="endValue">The end value to reach</param>
 71        /// <param name="jumpPower">Power of the jump (the max height of the jump is represented by this plus the final 
 72        /// <param name="numJumps">Total number of jumps</param>
 73        /// <param name="duration">The duration of the tween</param>
 74        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 75        public static Sequence DOJump(this Rigidbody2D target, Vector2 endValue, float jumpPower, int numJumps, float du
 76        {
 077            if (numJumps < 1) numJumps = 1;
 078            float startPosY = 0;
 079            float offsetY = -1;
 080            bool offsetYSet = false;
 081            Sequence s = DOTween.Sequence();
 082            Tween yTween = DOTween.To(() => target.position, x => target.position = x, new Vector2(0, jumpPower), durati
 83                .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
 84                .SetLoops(numJumps * 2, LoopType.Yoyo)
 085                .OnStart(() => startPosY = target.position.y);
 086            s.Append(DOTween.To(() => target.position, x => target.position = x, new Vector2(endValue.x, 0), duration)
 87                    .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
 88                ).Join(yTween)
 89                .SetTarget(target).SetEase(DOTween.defaultEaseType);
 090            yTween.OnUpdate(() => {
 091                if (!offsetYSet) {
 092                    offsetYSet = true;
 093                    offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
 94                }
 095                Vector3 pos = target.position;
 096                pos.y += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad);
 097                target.MovePosition(pos);
 098            });
 099            return s;
 100        }
 101
 102        /// <summary>Tweens a Rigidbody2D's position through the given path waypoints, using the chosen path algorithm.
 103        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations.
 104        /// <para>NOTE: to tween a Rigidbody2D correctly it should be set to kinematic at least while being tweened.</pa
 105        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
 106        /// If you plan to publish there you should use a regular transform.DOPath.</para></summary>
 107        /// <param name="path">The waypoints to go through</param>
 108        /// <param name="duration">The duration of the tween</param>
 109        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or Cubi
 110        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
 111        /// <param name="resolution">The resolution of the path (useless in case of Linear paths): higher resolutions ma
 112        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints<
 113        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween
 114        public static TweenerCore<Vector3, Path, PathOptions> DOPath(
 115            this Rigidbody2D target, Vector2[] path, float duration, PathType pathType = PathType.Linear,
 116            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null
 117        )
 118        {
 0119            if (resolution < 1) resolution = 1;
 0120            int len = path.Length;
 0121            Vector3[] path3D = new Vector3[len];
 0122            for (int i = 0; i < len; ++i) path3D[i] = path[i];
 0123            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.position, x => target.
 124                .SetTarget(target).SetUpdate(UpdateType.Fixed);
 125
 0126            t.plugOptions.isRigidbody2D = true;
 0127            t.plugOptions.mode = pathMode;
 0128            return t;
 129        }
 130        /// <summary>Tweens a Rigidbody2D's localPosition through the given path waypoints, using the chosen path algori
 131        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations
 132        /// <para>NOTE: to tween a Rigidbody2D correctly it should be set to kinematic at least while being tweened.</pa
 133        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
 134        /// If you plan to publish there you should use a regular transform.DOLocalPath.</para></summary>
 135        /// <param name="path">The waypoint to go through</param>
 136        /// <param name="duration">The duration of the tween</param>
 137        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or Cubi
 138        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
 139        /// <param name="resolution">The resolution of the path: higher resolutions make for more detailed curved paths 
 140        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints<
 141        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween
 142        public static TweenerCore<Vector3, Path, PathOptions> DOLocalPath(
 143            this Rigidbody2D target, Vector2[] path, float duration, PathType pathType = PathType.Linear,
 144            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null
 145        )
 146        {
 0147            if (resolution < 1) resolution = 1;
 0148            int len = path.Length;
 0149            Vector3[] path3D = new Vector3[len];
 0150            for (int i = 0; i < len; ++i) path3D[i] = path[i];
 0151            Transform trans = target.transform;
 0152            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => tar
 153                .SetTarget(target).SetUpdate(UpdateType.Fixed);
 154
 0155            t.plugOptions.isRigidbody2D = true;
 0156            t.plugOptions.mode = pathMode;
 0157            t.plugOptions.useLocalPosition = true;
 0158            return t;
 159        }
 160        // Used by path editor when creating the actual tween, so it can pass a pre-compiled path
 161        internal static TweenerCore<Vector3, Path, PathOptions> DOPath(
 162            this Rigidbody2D target, Path path, float duration, PathMode pathMode = PathMode.Full3D
 163        )
 164        {
 0165            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.position, x => target.
 166                .SetTarget(target);
 167
 0168            t.plugOptions.isRigidbody2D = true;
 0169            t.plugOptions.mode = pathMode;
 0170            return t;
 171        }
 172        internal static TweenerCore<Vector3, Path, PathOptions> DOLocalPath(
 173            this Rigidbody2D target, Path path, float duration, PathMode pathMode = PathMode.Full3D
 174        )
 175        {
 0176            Transform trans = target.transform;
 0177            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => tar
 178                .SetTarget(target);
 179
 0180            t.plugOptions.isRigidbody2D = true;
 0181            t.plugOptions.mode = pathMode;
 0182            t.plugOptions.useLocalPosition = true;
 0183            return t;
 184        }
 185
 186        #endregion
 187
 188        #endregion
 189
 190        #endregion
 191  }
 192}
 193#endif