Esempio n. 1
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            if (!obj || (canTween && endFrame == -1))
            {
                return;
            }

            int frameRate = seq.take.frameRate;

            Transform trans = obj as Transform;

            Transform sTarget = GetTarget(seq.target);
            Transform eTarget = canTween ? (track.keys[index + 1] as OrientationKey).GetTarget(seq.target) : null;

            var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => {
                if (sTarget == null && eTarget == null)
                {
                    return;
                }
                else if (sTarget == null)
                {
                    trans.LookAt(eTarget);
                }
                else if (eTarget == null || sTarget == eTarget)
                {
                    trans.LookAt(sTarget);
                }
                else
                {
                    Quaternion s = Quaternion.LookRotation(sTarget.position - trans.position);
                    Quaternion e = Quaternion.LookRotation(eTarget.position - trans.position);

                    trans.rotation = Quaternion.Lerp(s, e, x);
                }
            }, 1f, getTime(frameRate));

            if (sTarget != eTarget)
            {
                if (hasCustomEase())
                {
                    tween.SetEase(easeCurve);
                }
                else
                {
                    tween.SetEase(easeType, amplitude, period);
                }
            }
            else
            {
                tween.SetEase(Ease.Linear);
            }

            seq.Insert(this, tween);
        }
Esempio n. 2
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            Transform target = obj as Transform;

            int frameRate = seq.take.frameRate;

            var scaleTrack = (ScaleTrack)track;
            var axis       = scaleTrack.axis;

            float timeLength = getTime(frameRate);

            if (interp == Interpolation.None)
            {
                if (axis == AxisFlags.X)
                {
                    float _x     = scale.x;
                    var   tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localScale.x, (x) => { var a = target.localScale; a.x = x; target.localScale = a; }, _x, timeLength);
                    seq.Insert(this, tweenX);
                }
                else if (axis == AxisFlags.Y)
                {
                    float _y     = scale.y;
                    var   tweenY = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localScale.y, (y) => { var a = target.localScale; a.y = y; target.localScale = a; }, _y, timeLength);
                    seq.Insert(this, tweenY);
                }
                else if (axis == AxisFlags.Z)
                {
                    float _z     = scale.z;
                    var   tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localScale.z, (z) => { var a = target.localScale; a.z = z; target.localScale = a; }, _z, timeLength);
                    seq.Insert(this, tweenZ);
                }
                else if (axis == AxisFlags.All)
                {
                    var tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localScale, (s) => { target.localScale = s; }, scale, timeLength);
                    seq.Insert(this, tweenV);
                }
                else
                {
                    var tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(),
                                            () => {
                        var ls    = scale;
                        var curls = target.localScale;
                        if ((axis & AxisFlags.X) != AxisFlags.None)
                        {
                            ls.x = curls.x;
                        }
                        if ((axis & AxisFlags.Y) != AxisFlags.None)
                        {
                            ls.y = curls.y;
                        }
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            ls.z = curls.z;
                        }
                        return(ls);
                    },
                                            (s) => {
                        var ls = target.localScale;
                        if ((axis & AxisFlags.X) != AxisFlags.None)
                        {
                            ls.x = s.x;
                        }
                        if ((axis & AxisFlags.Y) != AxisFlags.None)
                        {
                            ls.y = s.y;
                        }
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            ls.z = s.z;
                        }
                        target.localScale = ls;
                    }, scale, timeLength);
                    seq.Insert(this, tweenV);
                }
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                Vector3 endScale = ((ScaleKey)track.keys[index + 1]).scale;

                Tweener tween;

                if (axis == AxisFlags.X)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.x, (x) => { var a = target.localScale; a.x = x; target.localScale = a; }, endScale.x, timeLength);
                }
                else if (axis == AxisFlags.Y)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.y, (y) => { var a = target.localScale; a.y = y; target.localScale = a; }, endScale.y, timeLength);
                }
                else if (axis == AxisFlags.Z)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => scale.z, (z) => { var a = target.localScale; a.z = z; target.localScale = a; }, endScale.z, timeLength);
                }
                else if (axis == AxisFlags.All)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => scale, (s) => target.localScale = s, endScale, timeLength);
                }
                else
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => scale, (s) => {
                        var ls = target.localScale;
                        if ((axis & AxisFlags.X) != AxisFlags.None)
                        {
                            ls.x = s.x;
                        }
                        if ((axis & AxisFlags.Y) != AxisFlags.None)
                        {
                            ls.y = s.y;
                        }
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            ls.z = s.z;
                        }
                        target.localScale = ls;
                    }, endScale, timeLength);
                }

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

                seq.Insert(this, tween);
            }
            else if (interp == Interpolation.Curve)
            {
                DOSetter <Vector3> setter;

                if (axis == AxisFlags.X)
                {
                    setter = (s) => { var a = target.localScale; a.x = s.x; target.localScale = a; }
                }
                ;
                else if (axis == AxisFlags.Y)
                {
                    setter = (s) => { var a = target.localScale; a.y = s.y; target.localScale = a; }
                }
                ;
                else if (axis == AxisFlags.Z)
                {
                    setter = (s) => { var a = target.localScale; a.z = s.z; target.localScale = a; }
                }
                ;
                else if (axis == AxisFlags.All)
                {
                    setter = (s) => target.localScale = s;
                }
                else
                {
                    setter = (s) => {
                        var ls = target.localScale;
                        if ((axis & AxisFlags.X) != AxisFlags.None)
                        {
                            ls.x = s.x;
                        }
                        if ((axis & AxisFlags.Y) != AxisFlags.None)
                        {
                            ls.y = s.y;
                        }
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            ls.z = s.z;
                        }
                        target.localScale = ls;
                    }
                };

                var tweenPath = DOTween.To(TweenPlugPathVector3.Get(), () => scale, setter, path, timeLength);

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

                seq.Insert(this, tweenPath);
            }
        }

        #endregion
    }
Esempio n. 3
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            PropertyTrack propTrack = track as PropertyTrack;

            string varName = propTrack.getMemberName();

            if (string.IsNullOrEmpty(varName))
            {
                Debug.LogError("Animator: No FieldInfo or PropertyInfo set."); return;
            }

            PropertyTrack.ValueType valueType = propTrack.valueType;

            //get component and fill the cached method info
            Component comp = propTrack.GetTargetComp(target as GameObject);

            if (comp == null)
            {
                return;
            }

            propTrack.RefreshData(comp);

            var time = getTime(seq.take.frameRate);

            Tweener tween = null;

            if (interp == Interpolation.None)
            {
                tween = GenerateSingleValueTweener(seq, propTrack, time, comp);
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                //grab end frame
                var endKey = track.keys[index + 1] as PropertyKey;

                switch (valueType)
                {
                case PropertyTrack.ValueType.Integer:
                    tween = DOTween.To(TweenPluginFactory.CreateInt(), () => System.Convert.ToInt32(val), GenerateSetter <int>(propTrack, comp), System.Convert.ToInt32(endKey.val), time); break;

                case PropertyTrack.ValueType.Float:
                    tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => System.Convert.ToSingle(val), GenerateSetter <float>(propTrack, comp), System.Convert.ToSingle(endKey.val), time); break;

                case PropertyTrack.ValueType.Double:
                    tween = DOTween.To(TweenPluginFactory.CreateDouble(), () => val, GenerateSetter <double>(propTrack, comp), endKey.val, time); break;

                case PropertyTrack.ValueType.Long:
                    tween = DOTween.To(TweenPluginFactory.CreateLong(), () => System.Convert.ToInt64(val), GenerateSetter <long>(propTrack, comp), System.Convert.ToInt64(endKey.val), time); break;

                case PropertyTrack.ValueType.Vector2:
                    tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => vect2, GenerateSetter <Vector2>(propTrack, comp), endKey.vect2, time); break;

                case PropertyTrack.ValueType.Vector3:
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => vect3, GenerateSetter <Vector3>(propTrack, comp), endKey.vect3, time); break;

                case PropertyTrack.ValueType.Color:
                    tween = DOTween.To(TweenPluginFactory.CreateColor(), () => color, GenerateSetter <Color>(propTrack, comp), endKey.color, time); break;

                case PropertyTrack.ValueType.Rect:
                    tween = DOTween.To(TweenPluginFactory.CreateRect(), () => rect, (x) => GenerateSetter <Rect>(propTrack, comp), endKey.rect, time); break;

                case PropertyTrack.ValueType.Vector4:
                    tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => vect4, GenerateSetter <Vector4>(propTrack, comp), endKey.vect4, time); break;

                case PropertyTrack.ValueType.Quaternion:
                    tween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => quat, GenerateSetter <Quaternion>(propTrack, comp), endKey.quat, time); break;
                }
            }
            else
            {
                switch (valueType)
                {
                case PropertyTrack.ValueType.Integer:
                    tween = DOTween.To(TweenPlugPathInt.Get(), () => System.Convert.ToInt32(val), GenerateSetter <int>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Float:
                    tween = DOTween.To(TweenPlugPathFloat.Get(), () => System.Convert.ToSingle(val), GenerateSetter <float>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Double:
                    tween = DOTween.To(TweenPlugPathDouble.Get(), () => val, GenerateSetter <double>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Long:
                    tween = DOTween.To(TweenPlugPathLong.Get(), () => System.Convert.ToInt64(val), GenerateSetter <long>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Vector2:
                    tween = DOTween.To(TweenPlugPathVector2.Get(), () => vect2, GenerateSetter <Vector2>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Vector3:
                    tween = DOTween.To(TweenPlugPathVector3.Get(), () => vect3, GenerateSetter <Vector3>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Color:
                    tween = DOTween.To(TweenPlugPathColor.Get(), () => color, GenerateSetter <Color>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Rect:
                    tween = DOTween.To(TweenPlugPathRect.Get(), () => rect, GenerateSetter <Rect>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Vector4:
                    tween = DOTween.To(TweenPlugPathVector4.Get(), () => vect4, GenerateSetter <Vector4>(propTrack, comp), path, time); break;

                case PropertyTrack.ValueType.Quaternion:
                    tween = DOTween.To(TweenPlugPathEuler.Get(), () => quat, GenerateSetter <Quaternion>(propTrack, comp), path, time); break;
                }
            }

            if (tween != null)
            {
                if (canTween)
                {
                    if (hasCustomEase())
                    {
                        tween.SetEase(easeCurve);
                    }
                    else
                    {
                        tween.SetEase(easeType, amplitude, period);
                    }
                }

                seq.Insert(this, tween);
            }
            return;
        }
Esempio n. 4
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            Transform target = obj as Transform;

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

            int frameRate = seq.take.frameRate;

            var rotTrack = (RotationEulerTrack)track;
            var axis     = rotTrack.axis;

            float timeLength = getTime(frameRate);//1.0f / frameRate;

            if (interp == Interpolation.None)
            {
                if (axis == AxisFlags.X)
                {
                    float _x = rotation.x;
                    TweenerCore <float, float, TWeenPlugNoneOptions> tweenX;

                    if (body)
                    {
                        tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.x,
                                            (x) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.rotation = Quaternion.Euler(x, a.y, a.z) * parent.rotation;
                            }
                            else
                            {
                                body.rotation = Quaternion.Euler(x, a.y, a.z);
                            }
                        }, _x, timeLength);
                    }
                    else
                    {
                        tweenX = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, _x, timeLength);
                    }

                    seq.Insert(this, tweenX);
                }
                else if (axis == AxisFlags.Y)
                {
                    float _y = rotation.y;
                    TweenerCore <float, float, TWeenPlugNoneOptions> tweenY;

                    if (body)
                    {
                        tweenY = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.y,
                                            (y) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.rotation = Quaternion.Euler(a.x, y, a.z) * parent.rotation;
                            }
                            else
                            {
                                body.rotation = Quaternion.Euler(a.x, y, a.z);
                            }
                        }, _y, timeLength);
                    }
                    else
                    {
                        tweenY = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, _y, timeLength);
                    }

                    seq.Insert(this, tweenY);
                }
                else if (axis == AxisFlags.Z)
                {
                    float _z = rotation.z;
                    TweenerCore <float, float, TWeenPlugNoneOptions> tweenZ;

                    if (body2D)
                    {
                        tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z,
                                            (z) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.rotation = z + parent.eulerAngles.z;
                            }
                            else
                            {
                                body2D.rotation = z;
                            }
                        }, _z, timeLength);
                    }
                    else if (body)
                    {
                        tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z,
                                            (z) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.rotation = Quaternion.Euler(a.x, a.y, z) * parent.rotation;
                            }
                            else
                            {
                                body.rotation = Quaternion.Euler(a.x, a.y, z);
                            }
                        }, _z, timeLength);
                    }
                    else
                    {
                        tweenZ = DOTween.To(TweenPlugValueSet <float> .Get(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, _z, timeLength);
                    }

                    seq.Insert(this, tweenZ);
                }
                else if (axis == AxisFlags.All)
                {
                    TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweenV;

                    if (body2D)
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles,
                                            (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.rotation = r.z + parent.eulerAngles.z;
                            }
                            else
                            {
                                body2D.rotation = r.z;
                            }
                        }, rotation, timeLength);
                    }
                    else if (body)
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles,
                                            (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body.rotation = Quaternion.Euler(r) * parent.rotation;
                            }
                            else
                            {
                                body.rotation = Quaternion.Euler(r);
                            }
                        }, rotation, timeLength);
                    }
                    else
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => target.localEulerAngles, (r) => { target.localEulerAngles = r; }, rotation, timeLength);
                    }

                    seq.Insert(this, tweenV);
                }
                else
                {
                    TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweenV;

                    DOGetter <Vector3> getter = () => {
                        var ret = rotation;
                        var rot = target.localEulerAngles;
                        if ((axis & AxisFlags.X) != AxisFlags.None)
                        {
                            ret.x = rot.x;
                        }
                        if ((axis & AxisFlags.Y) != AxisFlags.None)
                        {
                            ret.y = rot.y;
                        }
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            ret.z = rot.z;
                        }
                        return(ret);
                    };

                    if (body2D)
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (r) => {
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                var parent = target.parent;
                                if (parent)
                                {
                                    body2D.rotation = r.z + parent.eulerAngles.z;
                                }
                                else
                                {
                                    body2D.rotation = r.z;
                                }
                            }
                        }, rotation, timeLength);
                    }
                    else if (body)
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }

                            var parent = target.parent;
                            if (parent)
                            {
                                body.rotation = Quaternion.Euler(rot) * parent.rotation;
                            }
                            else
                            {
                                body.rotation = Quaternion.Euler(rot);
                            }
                        }, rotation, timeLength);
                    }
                    else
                    {
                        tweenV = DOTween.To(TweenPlugValueSet <Vector3> .Get(), getter, (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }
                            target.localEulerAngles = rot;
                        }, rotation, timeLength);
                    }

                    seq.Insert(this, tweenV);
                }
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                Vector3 endRotation = (track.keys[index + 1] as RotationEulerKey).rotation;

                Tweener tween;

                if (axis == AxisFlags.X)
                {
                    if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.x, (x) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(x, a.y, a.z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(x, a.y, a.z));
                            }
                        }, endRotation.x, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, endRotation.x, timeLength);
                    }
                }
                else if (axis == AxisFlags.Y)
                {
                    if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.y, (y) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, y, a.z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, y, a.z));
                            }
                        }, endRotation.y, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, endRotation.y, timeLength);
                    }
                }
                else if (axis == AxisFlags.Z)
                {
                    if (body2D)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.MoveRotation(z + parent.eulerAngles.z);
                            }
                            else
                            {
                                body2D.MoveRotation(z);
                            }
                        }, endRotation.z, timeLength);
                    }
                    else if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, a.y, z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, a.y, z));
                            }
                        }, endRotation.z, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => rotation.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, endRotation.z, timeLength);
                    }
                }
                else if (axis == AxisFlags.All)
                {
                    if (body2D)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.MoveRotation(r.z + parent.eulerAngles.z);
                            }
                            else
                            {
                                body2D.MoveRotation(r.z);
                            }
                        }, endRotation, timeLength);
                    }
                    else if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(r) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(r));
                            }
                        }, endRotation, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => target.localEulerAngles = r, endRotation, timeLength);
                    }
                }
                else
                {
                    if (body2D)
                    {
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => {
                                var parent = target.parent;
                                if (parent)
                                {
                                    body2D.MoveRotation(r.z + parent.eulerAngles.z);
                                }
                                else
                                {
                                    body2D.MoveRotation(r.z);
                                }
                            }, endRotation, timeLength);
                        }
                        else
                        {
                            tween = null;
                        }
                    }
                    else if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(rot) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(rot));
                            }
                        }, endRotation, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => rotation, (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }
                            target.localEulerAngles = rot;
                        }, endRotation, timeLength);
                    }
                }

                if (tween != null)
                {
                    if (hasCustomEase())
                    {
                        tween.SetEase(easeCurve);
                    }
                    else
                    {
                        tween.SetEase(easeType, amplitude, period);
                    }

                    seq.Insert(this, tween);
                }
            }
            else if (interp == Interpolation.Curve)
            {
                DOSetter <Vector3> setter;
                if (axis == AxisFlags.X)
                {
                    if (body)
                    {
                        setter = (x) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(x.x, a.y, a.z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(x.x, a.y, a.z));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = (x) => { var a = target.localEulerAngles; a.x = x.x; target.localEulerAngles = a; }
                    };
                }
                else if (axis == AxisFlags.Y)
                {
                    if (body)
                    {
                        setter = (x) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, x.y, a.z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, x.y, a.z));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = (x) => { var a = target.localEulerAngles; a.y = x.y; target.localEulerAngles = a; }
                    };
                }
                else if (axis == AxisFlags.Z)
                {
                    if (body2D)
                    {
                        setter = (x) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.MoveRotation(x.z + parent.eulerAngles.z);
                            }
                            else
                            {
                                body2D.MoveRotation(x.z);
                            }
                        }
                    }
                    ;
                    else if (body)
                    {
                        setter = (x) => {
                            var a      = target.localEulerAngles;
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, a.y, x.z) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(a.x, a.y, x.z));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = (x) => { var a = target.localEulerAngles; a.z = x.z; target.localEulerAngles = a; }
                    };
                }
                else if (axis == AxisFlags.All)
                {
                    if (body2D)
                    {
                        setter = (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body2D.MoveRotation(r.z + parent.eulerAngles.z);
                            }
                            else
                            {
                                body2D.MoveRotation(r.z);
                            }
                        }
                    }
                    ;
                    else if (body)
                    {
                        setter = (r) => {
                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(r) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(r));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = (r) => target.localEulerAngles = r;
                    }
                }
                else
                {
                    if (body2D)
                    {
                        if ((axis & AxisFlags.Z) != AxisFlags.None)
                        {
                            setter = (r) => {
                                var parent = target.parent;
                                if (parent)
                                {
                                    body2D.MoveRotation(r.z + parent.eulerAngles.z);
                                }
                                else
                                {
                                    body2D.MoveRotation(r.z);
                                }
                            }
                        }
                        ;
                        else
                        {
                            return;
                        }
                    }
                    else if (body)
                    {
                        setter = (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }

                            var parent = target.parent;
                            if (parent)
                            {
                                body.MoveRotation(Quaternion.Euler(rot) * parent.rotation);
                            }
                            else
                            {
                                body.MoveRotation(Quaternion.Euler(rot));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = (r) => {
                            var rot = target.localEulerAngles;
                            if ((axis & AxisFlags.X) != AxisFlags.None)
                            {
                                rot.x = r.x;
                            }
                            if ((axis & AxisFlags.Y) != AxisFlags.None)
                            {
                                rot.y = r.y;
                            }
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                rot.z = r.z;
                            }
                            target.localEulerAngles = rot;
                        }
                    };
                }

                var tweenPath = DOTween.To(TweenPlugPathVector3.Get(), () => rotation, setter, path, timeLength);

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

                seq.Insert(this, tweenPath);
            }
        }

        #endregion
    }
Esempio n. 5
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            int   frameRate = seq.take.frameRate;
            float waitTime  = getWaitTime(frameRate, 0.0f);
            var   anim      = (target as GameObject).GetComponent <Animation>();

            float duration = wrapMode == WrapMode.Once ? amClip.length : ((seq.take.getLastFrame() - frame) + 1) / (float)frameRate;

            if (crossfade)
            {
                if (index > 0)
                {
                    var prevKey = track.keys[index - 1] as UnityAnimationKey;

                    var prevAnimState = anim[prevKey.amClip.name];
                    var prevWrap      = prevKey.wrapMode;
                    var prevStartTime = prevKey.getWaitTime(frameRate, 0.0f);
                    var animState     = anim[amClip.name];

                    var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => {
                        if (x < crossfadeTime)
                        {
                            float weight = x / crossfadeTime;

                            prevAnimState.enabled  = true;
                            prevAnimState.wrapMode = prevWrap;
                            prevAnimState.weight   = 1.0f - weight;
                            prevAnimState.time     = (waitTime + x) - prevStartTime;

                            animState.enabled  = true;
                            animState.wrapMode = wrapMode;
                            animState.weight   = weight;
                            animState.time     = x;

                            anim.Sample();

                            prevAnimState.enabled = false;
                            animState.enabled     = false;
                        }
                        else
                        {
                            animState.enabled  = true;
                            animState.wrapMode = wrapMode;
                            animState.weight   = 1.0f;
                            animState.time     = x;

                            anim.Sample();

                            animState.enabled = false;
                        }
                    }, duration, duration);

                    seq.Insert(this, tween);
                }
                else
                {
                    var animState = anim[amClip.name];

                    var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => {
                        animState.enabled  = true;
                        animState.wrapMode = wrapMode;
                        animState.time     = x;

                        if (x < crossfadeTime)
                        {
                            animState.weight = x / crossfadeTime;
                        }
                        else
                        {
                            animState.weight = 1.0f;
                        }

                        anim.Sample();
                        animState.enabled = false;
                    }, duration, duration);

                    seq.Insert(this, tween);
                }
            }
            else
            {
                var animState = anim[amClip.name];

                var tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => 0f, (x) => {
                    animState.enabled  = true;
                    animState.wrapMode = wrapMode;
                    animState.time     = x;
                    animState.weight   = 1.0f;
                    anim.Sample();
                    animState.enabled = false;
                }, duration, duration);

                seq.Insert(this, tween);
            }
        }
Esempio n. 6
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            var matTrack = track as MaterialTrack;
            var propType = matTrack.propertyType;

            Material matInst = matTrack.materialInstance;

            string prop   = matTrack.property;
            int    propId = Shader.PropertyToID(prop);

            int frameRate = seq.take.frameRate;

            Tweener tween = null;

            int   keyCount = track.keys.Count;
            float time     = getTime(frameRate);

            if (interp == Interpolation.None)
            {
                switch (propType)
                {
                case MaterialTrack.ValueType.Float:
                case MaterialTrack.ValueType.Range:
                    tween = DOTween.To(TweenPlugValueSet <float> .Get(), () => matInst.GetFloat(propId), (x) => matInst.SetFloat(propId, x), val, time);
                    break;

                case MaterialTrack.ValueType.Vector:
                    tween = DOTween.To(TweenPlugValueSet <Vector4> .Get(), () => matInst.GetVector(propId), (x) => matInst.SetVector(propId, x), vector, time);
                    break;

                case MaterialTrack.ValueType.Color:
                    tween = DOTween.To(TweenPlugValueSet <Color> .Get(), () => matInst.GetColor(propId), (x) => matInst.SetColor(propId, x), color, time);
                    break;

                case MaterialTrack.ValueType.TexOfs:
                    tween = DOTween.To(TweenPlugValueSet <Vector2> .Get(), () => matInst.GetTextureOffset(prop), (x) => matInst.SetTextureOffset(prop, x), texOfs, time);
                    break;

                case MaterialTrack.ValueType.TexScale:
                    tween = DOTween.To(TweenPlugValueSet <Vector2> .Get(), () => matInst.GetTextureScale(prop), (x) => matInst.SetTextureScale(prop, x), texScale, time);
                    break;

                case MaterialTrack.ValueType.TexEnv:
                    tween = DOTween.To(TweenPlugValueSet <Texture> .Get(), () => matInst.GetTexture(propId), (x) => matInst.SetTexture(propId, x), texture, time);
                    break;
                }
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                var endKey = track.keys[index + 1] as MaterialKey;

                switch (propType)
                {
                case MaterialTrack.ValueType.Float:
                case MaterialTrack.ValueType.Range:
                    tween = DOTween.To(TweenPluginFactory.CreateFloat(), () => val, (x) => matInst.SetFloat(propId, x), endKey.val, time);
                    break;

                case MaterialTrack.ValueType.Vector:
                    tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => vector, (x) => matInst.SetVector(propId, x), endKey.vector, time);
                    break;

                case MaterialTrack.ValueType.Color:
                    tween = DOTween.To(TweenPluginFactory.CreateColor(), () => color, (x) => matInst.SetColor(propId, x), endKey.color, time);
                    break;

                case MaterialTrack.ValueType.TexOfs:
                    tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => texOfs, (x) => matInst.SetTextureOffset(prop, x), endKey.texOfs, time);
                    break;

                case MaterialTrack.ValueType.TexScale:
                    tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => texScale, (x) => matInst.SetTextureScale(prop, x), endKey.texScale, time);
                    break;
                }
            }
            else
            {
                switch (propType)
                {
                case MaterialTrack.ValueType.Float:
                case MaterialTrack.ValueType.Range:
                    tween = DOTween.To(TweenPlugPathFloat.Get(), () => val, (x) => matInst.SetFloat(propId, x), path, time);
                    break;

                case MaterialTrack.ValueType.Vector:
                    tween = DOTween.To(TweenPlugPathVector4.Get(), () => vector, (x) => matInst.SetVector(propId, x), path, time);
                    break;

                case MaterialTrack.ValueType.Color:
                    tween = DOTween.To(TweenPlugPathColor.Get(), () => color, (x) => matInst.SetColor(propId, x), path, time);
                    break;

                case MaterialTrack.ValueType.TexOfs:
                    tween = DOTween.To(TweenPlugPathVector2.Get(), () => texOfs, (x) => matInst.SetTextureOffset(propId, x), path, time);
                    break;

                case MaterialTrack.ValueType.TexScale:
                    tween = DOTween.To(TweenPlugPathVector2.Get(), () => texScale, (x) => matInst.SetTextureScale(propId, x), path, time);
                    break;
                }
            }

            if (tween != null)
            {
                if (canTween)
                {
                    if (hasCustomEase())
                    {
                        tween.SetEase(easeCurve);
                    }
                    else
                    {
                        tween.SetEase((Ease)easeType, amplitude, period);
                    }
                }

                seq.Insert(this, tween);
            }
        }