< Summary

Class:DG.Tweening.DOTweenModulePhysics
Assembly:DOTween.Modules
File(s):/tmp/workspace/unity-renderer/unity-renderer/Assets/Plugins/DOTween/Modules/DOTweenModulePhysics.cs
Covered lines:0
Uncovered lines:60
Coverable lines:60
Total lines:216
Line coverage:0% (0 of 60)
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%
DOMoveZ(...)0%2100%
DORotate(...)0%2100%
DOLookAt(...)0%6200%
DOJump(...)0%6200%
DOPath(...)0%6200%
DOLocalPath(...)0%6200%
DOPath(...)0%2100%
DOLocalPath(...)0%2100%

File(s)

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

#LineLine coverage
 1// Author: Daniele Giardini - http://www.demigiant.com
 2// Created: 2018/07/13
 3
 4#if true // MODULE_MARKER
 5using System;
 6using DG.Tweening.Core;
 7using DG.Tweening.Core.Enums;
 8using DG.Tweening.Plugins;
 9using DG.Tweening.Plugins.Core.PathCore;
 10using DG.Tweening.Plugins.Options;
 11using UnityEngine;
 12
 13#pragma warning disable 1591
 14namespace DG.Tweening
 15{
 16  public static class DOTweenModulePhysics
 17    {
 18        #region Shortcuts
 19
 20        #region Rigidbody
 21
 22        /// <summary>Tweens a Rigidbody's position to the given value.
 23        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 24        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 25        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 26        public static TweenerCore<Vector3, Vector3, VectorOptions> DOMove(this Rigidbody target, Vector3 endValue, float
 27        {
 028            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, endV
 029            t.SetOptions(snapping).SetTarget(target);
 030            return t;
 31        }
 32
 33        /// <summary>Tweens a Rigidbody's X position to the given value.
 34        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 35        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 36        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 37        public static TweenerCore<Vector3, Vector3, VectorOptions> DOMoveX(this Rigidbody target, float endValue, float 
 38        {
 039            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, new 
 040            t.SetOptions(AxisConstraint.X, snapping).SetTarget(target);
 041            return t;
 42        }
 43
 44        /// <summary>Tweens a Rigidbody's Y position to the given value.
 45        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 46        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 47        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 48        public static TweenerCore<Vector3, Vector3, VectorOptions> DOMoveY(this Rigidbody target, float endValue, float 
 49        {
 050            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, new 
 051            t.SetOptions(AxisConstraint.Y, snapping).SetTarget(target);
 052            return t;
 53        }
 54
 55        /// <summary>Tweens a Rigidbody's Z position to the given value.
 56        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 57        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 58        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 59        public static TweenerCore<Vector3, Vector3, VectorOptions> DOMoveZ(this Rigidbody target, float endValue, float 
 60        {
 061            TweenerCore<Vector3, Vector3, VectorOptions> t = DOTween.To(() => target.position, target.MovePosition, new 
 062            t.SetOptions(AxisConstraint.Z, snapping).SetTarget(target);
 063            return t;
 64        }
 65
 66        /// <summary>Tweens a Rigidbody's rotation to the given value.
 67        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 68        /// <param name="endValue">The end value to reach</param><param name="duration">The duration of the tween</param
 69        /// <param name="mode">Rotation mode</param>
 70        public static TweenerCore<Quaternion, Vector3, QuaternionOptions> DORotate(this Rigidbody target, Vector3 endVal
 71        {
 072            TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotatio
 073            t.SetTarget(target);
 074            t.plugOptions.rotateMode = mode;
 075            return t;
 76        }
 77
 78        /// <summary>Tweens a Rigidbody's rotation so that it will look towards the given position.
 79        /// Also stores the rigidbody as the tween's target so it can be used for filtered operations</summary>
 80        /// <param name="towards">The position to look at</param><param name="duration">The duration of the tween</param
 81        /// <param name="axisConstraint">Eventual axis constraint for the rotation</param>
 82        /// <param name="up">The vector that defines in which direction up is (default: Vector3.up)</param>
 83        public static TweenerCore<Quaternion, Vector3, QuaternionOptions> DOLookAt(this Rigidbody target, Vector3 toward
 84        {
 085            TweenerCore<Quaternion, Vector3, QuaternionOptions> t = DOTween.To(() => target.rotation, target.MoveRotatio
 86                .SetTarget(target).SetSpecialStartupMode(SpecialStartupMode.SetLookAt);
 087            t.plugOptions.axisConstraint = axisConstraint;
 088            t.plugOptions.up = (up == null) ? Vector3.up : (Vector3)up;
 089            return t;
 90        }
 91
 92        #region Special
 93
 94        /// <summary>Tweens a Rigidbody's position to the given value, while also applying a jump effect along the Y axi
 95        /// Returns a Sequence instead of a Tweener.
 96        /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations</summary>
 97        /// <param name="endValue">The end value to reach</param>
 98        /// <param name="jumpPower">Power of the jump (the max height of the jump is represented by this plus the final 
 99        /// <param name="numJumps">Total number of jumps</param>
 100        /// <param name="duration">The duration of the tween</param>
 101        /// <param name="snapping">If TRUE the tween will smoothly snap all values to integers</param>
 102        public static Sequence DOJump(this Rigidbody target, Vector3 endValue, float jumpPower, int numJumps, float dura
 103        {
 0104            if (numJumps < 1) numJumps = 1;
 0105            float startPosY = 0;
 0106            float offsetY = -1;
 0107            bool offsetYSet = false;
 0108            Sequence s = DOTween.Sequence();
 0109            Tween yTween = DOTween.To(() => target.position, target.MovePosition, new Vector3(0, jumpPower, 0), duration
 110                .SetOptions(AxisConstraint.Y, snapping).SetEase(Ease.OutQuad).SetRelative()
 111                .SetLoops(numJumps * 2, LoopType.Yoyo)
 0112                .OnStart(() => startPosY = target.position.y);
 0113            s.Append(DOTween.To(() => target.position, target.MovePosition, new Vector3(endValue.x, 0, 0), duration)
 114                    .SetOptions(AxisConstraint.X, snapping).SetEase(Ease.Linear)
 0115                ).Join(DOTween.To(() => target.position, target.MovePosition, new Vector3(0, 0, endValue.z), duration)
 116                    .SetOptions(AxisConstraint.Z, snapping).SetEase(Ease.Linear)
 117                ).Join(yTween)
 118                .SetTarget(target).SetEase(DOTween.defaultEaseType);
 0119            yTween.OnUpdate(() => {
 0120                if (!offsetYSet) {
 0121                    offsetYSet = true;
 0122                    offsetY = s.isRelative ? endValue.y : endValue.y - startPosY;
 123                }
 0124                Vector3 pos = target.position;
 0125                pos.y += DOVirtual.EasedValue(0, offsetY, yTween.ElapsedPercentage(), Ease.OutQuad);
 0126                target.MovePosition(pos);
 0127            });
 0128            return s;
 129        }
 130
 131        /// <summary>Tweens a Rigidbody's position through the given path waypoints, using the chosen path algorithm.
 132        /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations.
 133        /// <para>NOTE: to tween a rigidbody correctly it should be set to kinematic at least while being tweened.</para
 134        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
 135        /// If you plan to publish there you should use a regular transform.DOPath.</para></summary>
 136        /// <param name="path">The waypoints to go through</param>
 137        /// <param name="duration">The duration of the tween</param>
 138        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or Cubi
 139        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
 140        /// <param name="resolution">The resolution of the path (useless in case of Linear paths): higher resolutions ma
 141        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints<
 142        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween
 143        public static TweenerCore<Vector3, Path, PathOptions> DOPath(
 144            this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear,
 145            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null
 146        )
 147        {
 0148            if (resolution < 1) resolution = 1;
 0149            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.position, target.MoveP
 150                .SetTarget(target).SetUpdate(UpdateType.Fixed);
 151
 0152            t.plugOptions.isRigidbody = true;
 0153            t.plugOptions.mode = pathMode;
 0154            return t;
 155        }
 156        /// <summary>Tweens a Rigidbody's localPosition through the given path waypoints, using the chosen path algorith
 157        /// Also stores the Rigidbody as the tween's target so it can be used for filtered operations
 158        /// <para>NOTE: to tween a rigidbody correctly it should be set to kinematic at least while being tweened.</para
 159        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
 160        /// If you plan to publish there you should use a regular transform.DOLocalPath.</para></summary>
 161        /// <param name="path">The waypoint to go through</param>
 162        /// <param name="duration">The duration of the tween</param>
 163        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or Cubi
 164        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
 165        /// <param name="resolution">The resolution of the path: higher resolutions make for more detailed curved paths 
 166        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints<
 167        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween
 168        public static TweenerCore<Vector3, Path, PathOptions> DOLocalPath(
 169            this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear,
 170            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null
 171        )
 172        {
 0173            if (resolution < 1) resolution = 1;
 0174            Transform trans = target.transform;
 0175            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => tar
 176                .SetTarget(target).SetUpdate(UpdateType.Fixed);
 177
 0178            t.plugOptions.isRigidbody = true;
 0179            t.plugOptions.mode = pathMode;
 0180            t.plugOptions.useLocalPosition = true;
 0181            return t;
 182        }
 183        // Used by path editor when creating the actual tween, so it can pass a pre-compiled path
 184        internal static TweenerCore<Vector3, Path, PathOptions> DOPath(
 185            this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D
 186        )
 187        {
 0188            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.position, target.MoveP
 189                .SetTarget(target);
 190
 0191            t.plugOptions.isRigidbody = true;
 0192            t.plugOptions.mode = pathMode;
 0193            return t;
 194        }
 195        internal static TweenerCore<Vector3, Path, PathOptions> DOLocalPath(
 196            this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D
 197        )
 198        {
 0199            Transform trans = target.transform;
 0200            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => tar
 201                .SetTarget(target);
 202
 0203            t.plugOptions.isRigidbody = true;
 0204            t.plugOptions.mode = pathMode;
 0205            t.plugOptions.useLocalPosition = true;
 0206            return t;
 207        }
 208
 209        #endregion
 210
 211        #endregion
 212
 213        #endregion
 214  }
 215}
 216#endif