/// <summary>Tweens a Rigidbody2D's localPosition through the given path waypoints, using the chosen path algorithm.
        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations
        /// <para>NOTE: to tween a Rigidbody2D correctly it should be set to kinematic at least while being tweened.</para>
        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
        /// If you plan to publish there you should use a regular transform.DOLocalPath.</para></summary>
        /// <param name="path">The waypoint to go through</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or CubicBezier (curved with control points)</param>
        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
        /// <param name="resolution">The resolution of the path: higher resolutions make for more detailed curved paths but are more expensive.
        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints</param>
        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween is running)</param>
        public static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(
            this Rigidbody2D target, Vector2[] path, float duration, PathType pathType = PathType.Linear,
            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = null
            )
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            int len = path.Length;

            Vector3[] path3D = new Vector3[len];
            for (int i = 0; i < len; ++i)
            {
                path3D[i] = path[i];
            }
            Transform trans = target.transform;
            TweenerCore <Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => target.MovePosition(trans.parent == null ? x : trans.parent.TransformPoint(x)), new Path(pathType, path3D, resolution, gizmoColor), duration)
                                                         .SetTarget(target).SetUpdate(UpdateType.Fixed);

            t.plugOptions.isRigidbody      = true;
            t.plugOptions.mode             = pathMode;
            t.plugOptions.useLocalPosition = true;
            return(t);
        }
示例#2
0
        internal static TweenerCore <Vector3, Path, PathOptions> DOPath(this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D)
        {
            TweenerCore <Vector3, Path, PathOptions> tweenerCore = DOTween.To(PathPlugin.Get(), () => target.position, target.MovePosition, path, duration).SetTarget(target);

            tweenerCore.plugOptions.isRigidbody = true;
            tweenerCore.plugOptions.mode        = pathMode;
            return(tweenerCore);
        }
示例#3
0
        internal static TweenerCore <Vector3, Path, PathOptions> DOPath(this Transform target, Path path, float duration, PathMode pathMode = PathMode.Full3D)
        {
            TweenerCore <Vector3, Path, PathOptions> tweenerCore = DOTween.To(PathPlugin.Get(), () => target.position, delegate(Vector3 x)
            {
                target.position = x;
            }, path, duration).SetTarget(target);

            tweenerCore.plugOptions.mode = pathMode;
            return(tweenerCore);
        }
示例#4
0
        internal static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(
            this Transform target, Path path, float duration, PathMode pathMode = PathMode.Full3D
            )
        {
            TweenerCore <Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.localPosition, x => target.localPosition = x, path, duration)
                                                         .SetTarget(target);

            t.plugOptions.mode = pathMode;
            return(t);
        }
示例#5
0
        public static TweenerCore <Vector3, Path, PathOptions> DOPath(this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear, PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = default(Color?))
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            TweenerCore <Vector3, Path, PathOptions> tweenerCore = DOTween.To(PathPlugin.Get(), () => target.position, target.MovePosition, new Path(pathType, path, resolution, gizmoColor), duration).SetTarget(target).SetUpdate(UpdateType.Fixed);

            tweenerCore.plugOptions.isRigidbody = true;
            tweenerCore.plugOptions.mode        = pathMode;
            return(tweenerCore);
        }
        internal static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(
            this Rigidbody target, Path path, float duration, PathMode pathMode = PathMode.Full3D
            )
        {
            Transform trans = target.transform;
            TweenerCore <Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => trans.localPosition, x => target.MovePosition(trans.parent == null ? x : trans.parent.TransformPoint(x)), path, duration)
                                                         .SetTarget(target);

            t.plugOptions.isRigidbody      = true;
            t.plugOptions.mode             = pathMode;
            t.plugOptions.useLocalPosition = true;
            return(t);
        }
示例#7
0
        public static TweenerCore <Vector3, Path, PathOptions> DOPath(this Transform target, Vector3[] path, float duration, PathType pathType = PathType.Linear, PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = default(Color?))
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            TweenerCore <Vector3, Path, PathOptions> tweenerCore = DOTween.To(PathPlugin.Get(), () => target.position, delegate(Vector3 x)
            {
                target.position = x;
            }, new Path(pathType, path, resolution, gizmoColor), duration).SetTarget(target);

            tweenerCore.plugOptions.mode = pathMode;
            return(tweenerCore);
        }
示例#8
0
        /// <summary>Tweens a Transform's localPosition through the given path waypoints, using the chosen path algorithm.
        /// Also stores the transform as the tween's target so it can be used for filtered operations</summary>
        /// <param name="path">The waypoint to go through</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="pathType">The type of path: Linear (straight path) or CatmullRom (curved CatmullRom path)</param>
        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
        /// <param name="resolution">The resolution of the path: higher resolutions make for more detailed curved paths but are more expensive.
        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints</param>
        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween is running)</param>
        public static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(
            this Transform target, Vector3[] path, float duration, PathType pathType = PathType.Linear,
            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = null
            )
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            TweenerCore <Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.localPosition, x => target.localPosition = x, new Path(pathType, path, resolution, gizmoColor), duration)
                                                         .SetTarget(target);

            t.plugOptions.mode = pathMode;
            return(t);
        }
示例#9
0
        /// <summary>
        /// Grab tweener, create if it doesn't exists. keyInd is the index of this key in the track.
        /// </summary>
        TweenerCore <Vector3, Path, PathOptions> GetPathTween(int frameRate)
        {
            if ((mPathTween == null || !mPathTween.active) && path.Length > 1)
            {
                //if all points are equal, then set to Linear to prevent error from DOTween
                var pathType = path.Length == 2 || IsPathPointsEqual() ? PathType.Linear : PathType.CatmullRom;

                var pathData = new Path(pathType, path, pathResolution);

                mPathTween = DOTween.To(PathPlugin.Get(), _PathGetter, _PathSetterNull, pathData, getTime(frameRate));

                mPathTween.SetRelative(false).SetOptions(isClosed);
            }

            return(mPathTween);
        }
示例#10
0
        /// <summary>Tweens a Rigidbody2D's position through the given path waypoints, using the chosen path algorithm.
        /// Also stores the Rigidbody2D as the tween's target so it can be used for filtered operations.
        /// <para>NOTE: to tween a Rigidbody2D correctly it should be set to kinematic at least while being tweened.</para>
        /// <para>BEWARE: doesn't work on Windows Phone store (waiting for Unity to fix their own bug).
        /// If you plan to publish there you should use a regular transform.DOPath.</para></summary>
        /// <param name="path">The waypoints to go through</param>
        /// <param name="duration">The duration of the tween</param>
        /// <param name="pathType">The type of path: Linear (straight path), CatmullRom (curved CatmullRom path) or CubicBezier (curved with control points)</param>
        /// <param name="pathMode">The path mode: 3D, side-scroller 2D, top-down 2D</param>
        /// <param name="resolution">The resolution of the path (useless in case of Linear paths): higher resolutions make for more detailed curved paths but are more expensive.
        /// Defaults to 10, but a value of 5 is usually enough if you don't have dramatic long curves between waypoints</param>
        /// <param name="gizmoColor">The color of the path (shown when gizmos are active in the Play panel and the tween is running)</param>
        public static TweenerCore<Vector3, Path, PathOptions> DOPath(
            this Rigidbody2D target, Vector2[] path, float duration, PathType pathType = PathType.Linear,
            PathMode pathMode = PathMode.Full3D, int resolution = 10, Color? gizmoColor = null
        )
        {
            if (resolution < 1) resolution = 1;
            int len = path.Length;
            Vector3[] path3D = new Vector3[len];
            for (int i = 0; i < len; ++i) path3D[i] = path[i];
            TweenerCore<Vector3, Path, PathOptions> t = DOTween.To(PathPlugin.Get(), () => target.position, x => target.MovePosition(x), new Path(pathType, path3D, resolution, gizmoColor), duration)
                .SetTarget(target).SetUpdate(UpdateType.Fixed);

            t.plugOptions.isRigidbody = true;
            t.plugOptions.mode = pathMode;
            return t;
        }
示例#11
0
        public static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(this Rigidbody target, Vector3[] path, float duration, PathType pathType = PathType.Linear, PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = default(Color?))
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            Transform trans = target.transform;
            TweenerCore <Vector3, Path, PathOptions> tweenerCore = DOTween.To(PathPlugin.Get(), () => trans.localPosition, delegate(Vector3 x)
            {
                target.MovePosition((!(trans.parent == null)) ? trans.parent.TransformPoint(x) : x);
            }, new Path(pathType, path, resolution, gizmoColor), duration).SetTarget(target).SetUpdate(UpdateType.Fixed);

            tweenerCore.plugOptions.isRigidbody      = true;
            tweenerCore.plugOptions.mode             = pathMode;
            tweenerCore.plugOptions.useLocalPosition = true;
            return(tweenerCore);
        }
示例#12
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            int frameRate = seq.take.frameRate;

            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }

            Transform trans = obj as Transform;

            var   tTrack    = track as TranslationTrack;
            bool  pixelSnap = tTrack.pixelSnap;
            float ppu       = tTrack.pixelPerUnit;

            if (!canTween)
            {
                //TODO: world position
                Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position;

                var tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => pos, (x) => trans.localPosition = x, pos, 1.0f / frameRate); //getTime(frameRate)
                tweener.plugOptions.SetSequence(seq);

                seq.Insert(this, tweener);
            }
            else
            {
                if (path.Length <= 1)
                {
                    return;
                }
                if (getNumberOfFrames(seq.take.frameRate) <= 0)
                {
                    return;
                }

                Tweener ret = null;

                bool isRelative = false;

                PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom;

                if (pixelSnap)
                {
                    ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed);
                }
                else
                {
                    ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed);
                }

                if (hasCustomEase())
                {
                    ret.SetEase(easeCurve);
                }
                else
                {
                    ret.SetEase(easeType, amplitude, period);
                }

                seq.Insert(this, ret);
            }
        }
示例#13
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            int frameRate = seq.take.frameRate;

            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }

            var trans       = obj as Transform;
            var transParent = trans.parent;

            Rigidbody   body   = trans.GetComponent <Rigidbody>();
            Rigidbody2D body2D = !body?trans.GetComponent <Rigidbody2D>() : null;

            var   tTrack    = track as TranslationTrack;
            bool  pixelSnap = tTrack.pixelSnap;
            float ppu       = tTrack.pixelPerUnit;

            if (!canTween)
            {
                //TODO: world position
                Vector3 pos = pixelSnap ? new Vector3(Mathf.Round(position.x * ppu) / ppu, Mathf.Round(position.y * ppu) / ppu, Mathf.Round(position.z * ppu) / ppu) : position;

                TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweener;

                if (body2D)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body2D.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else if (body)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => trans.localPosition = x, pos, getTime(frameRate)); //1.0f / frameRate
                }
                seq.Insert(this, tweener);
            }
            else
            {
                if (path.Length <= 1)
                {
                    return;
                }
                if (getNumberOfFrames(seq.take.frameRate) <= 0)
                {
                    return;
                }

                TweenerCore <Vector3, Path, PathOptions> ret = null;

                bool isRelative = false;

                PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom;

                var pathTween = new Path(pathType, path, pathResolution);
                var timeTween = getTime(frameRate);

                if (body2D)
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu))), pathTween, timeTween).SetTarget(body2D);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body2D);
                    }
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu))), pathTween, timeTween).SetTarget(body);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body);
                    }
                }
                else
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), pathTween, timeTween).SetTarget(trans);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, pathTween, timeTween).SetTarget(trans);
                    }
                }

                ret.SetRelative(isRelative).SetOptions(isClosed);

                if (hasCustomEase())
                {
                    ret.SetEase(easeCurve);
                }
                else
                {
                    ret.SetEase(easeType, amplitude, period);
                }

                seq.Insert(this, ret);
            }
        }
        public static TweenerCore <Vector3, Path, PathOptions> DOPath(this Transform target, Path path, float duration, PathMode pathMode = PathMode.Full3D)
        {
            TweenerCore <Vector3, Path, PathOptions> local1 = DOTween.To <Vector3, Path, PathOptions>(PathPlugin.Get(), () => target.position, delegate(Vector3 x) {
                target.position = x;
            }, path, duration).SetTarget <TweenerCore <Vector3, Path, PathOptions> >(target);

            local1.plugOptions.mode = pathMode;
            return(local1);
        }
        public static TweenerCore <Vector3, Path, PathOptions> DOLocalPath(this Transform target, Vector3[] path, float duration, PathType pathType = PathType.Linear, PathMode pathMode = PathMode.Full3D, int resolution = 10, Color?gizmoColor = null)
        {
            if (resolution < 1)
            {
                resolution = 1;
            }
            Path temp = new Path(pathType, path, resolution, gizmoColor);
            TweenerCore <Vector3, Path, PathOptions> local1 = DOTween.To <Vector3, Path, PathOptions>(PathPlugin.Get(), () => target.localPosition, delegate(Vector3 x) {
                target.localPosition = x;
            }, temp, duration).SetTarget <TweenerCore <Vector3, Path, PathOptions> >(target);

            local1.plugOptions.mode             = pathMode;
            local1.plugOptions.useLocalPosition = true;
            return(local1);
        }