Example #1
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            Transform target      = obj as Transform;
            var       transParent = target.parent;

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

            int frameRate = seq.take.frameRate;

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

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

            if (!canTween)
            {
                float timeLength = getTime(frameRate);//1.0f / frameRate;

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

                    if (body)
                    {
                        tweenX = DOTween.To(new TweenPlugValueSet <float>(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; body.rotation = Quaternion.Euler(x, a.y, a.z) * transParent.rotation; }, _x, timeLength);
                    }
                    else
                    {
                        tweenX = DOTween.To(new TweenPlugValueSet <float>(), () => 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(new TweenPlugValueSet <float>(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; body.rotation = Quaternion.Euler(a.x, y, a.z) * transParent.rotation; }, _y, timeLength);
                    }
                    else
                    {
                        tweenY = DOTween.To(new TweenPlugValueSet <float>(), () => 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(new TweenPlugValueSet <float>(), () => target.localEulerAngles.z, (z) => { body2D.rotation = z + transParent.eulerAngles.z; }, _z, timeLength);
                    }
                    else if (body)
                    {
                        tweenZ = DOTween.To(new TweenPlugValueSet <float>(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; body.rotation = Quaternion.Euler(a.x, a.y, z) * transParent.rotation; }, _z, timeLength);
                    }
                    else
                    {
                        tweenZ = DOTween.To(new TweenPlugValueSet <float>(), () => 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(new TweenPlugValueSet <Vector3>(), () => target.localEulerAngles, (r) => { body2D.rotation = r.z + transParent.eulerAngles.z; }, rotation, timeLength);
                    }
                    else if (body)
                    {
                        tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => target.localEulerAngles, (r) => { body.rotation = Quaternion.Euler(r) * transParent.rotation; }, rotation, timeLength);
                    }
                    else
                    {
                        tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => 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(new TweenPlugValueSet <Vector3>(), getter, (r) => {
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                body2D.rotation = r.z + transParent.eulerAngles.z;
                            }
                        }, rotation, timeLength);
                    }
                    else if (body)
                    {
                        tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), 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;
                            }
                            body.rotation = Quaternion.Euler(rot) * transParent.rotation;
                        }, rotation, timeLength);
                    }
                    else
                    {
                        tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), 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 (endFrame == -1)
            {
                return;
            }
            else
            {
                float   timeLength  = getTime(frameRate);
                Vector3 endRotation = (track.keys[index + 1] as RotationEulerKey).rotation;

                Tweener tween;

                if (axis == AxisFlags.X)
                {
                    if (body)
                    {
                        tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; body.MoveRotation(Quaternion.Euler(x, a.y, a.z) * transParent.rotation); }, endRotation.x, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.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(new FloatPlugin(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; body.MoveRotation(Quaternion.Euler(a.x, y, a.z) * transParent.rotation); }, endRotation.y, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.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(new FloatPlugin(), () => target.localEulerAngles.z, (z) => { body2D.rotation = z + transParent.eulerAngles.z; }, endRotation.z, timeLength);
                    }
                    else if (body)
                    {
                        tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; body.MoveRotation(Quaternion.Euler(a.x, a.y, z) * transParent.rotation); }, endRotation.z, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.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(), () => target.localEulerAngles, (r) => body2D.MoveRotation(r.z + transParent.eulerAngles.z), endRotation, timeLength);
                    }
                    else if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => body.MoveRotation(Quaternion.Euler(r) * transParent.rotation), endRotation, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => target.localEulerAngles = r, endRotation, timeLength);
                    }
                }
                else
                {
                    if (body2D)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => {
                            if ((axis & AxisFlags.Z) != AxisFlags.None)
                            {
                                body2D.MoveRotation(r.z + transParent.eulerAngles.z);
                            }
                        }, endRotation, timeLength);
                    }
                    else if (body)
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (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;
                            }
                            body.MoveRotation(Quaternion.Euler(rot) * transParent.rotation);
                        }, endRotation, timeLength);
                    }
                    else
                    {
                        tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (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 (hasCustomEase())
                {
                    tween.SetEase(easeCurve);
                }
                else
                {
                    tween.SetEase(easeType, amplitude, period);
                }

                seq.Insert(this, tween);
            }
        }
Example #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
    }
Example #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 && track.canTween)
            {
                //invalid or in-between keys
                if (endFrame == -1)
                {
                    return;
                }
            }

            PropertyTrack propTrack = track as PropertyTrack;

            PropertyTrack.ValueType valueType = propTrack.valueType;

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

            if (comp == null)
            {
                return;
            }

            string varName = propTrack.getMemberName();

            int frameRate = seq.take.frameRate;

            //change to use setvalue track in AMSequence
            if (!string.IsNullOrEmpty(varName))
            {
                propTrack.RefreshData(comp);

                //allow tracks with just one key
                if (!propTrack.canTween || !canTween)
                {
                    seq.Insert(this, GenerateSingleValueTweener(seq, propTrack, frameRate, comp));
                }
                else
                {
                    //grab end frame
                    var endKey = track.keys[index + 1] as PropertyKey;

                    if (targetsAreEqual(valueType, endKey))
                    {
                        return;
                    }

                    Tweener tween = null;

                    var time = getTime(frameRate);

                    PropertyInfo propInfo = propTrack.GetCachedPropertyInfo();
                    if (propInfo != null)
                    {
                        switch (valueType)
                        {
                        case PropertyTrack.ValueType.Integer:
                            tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(val), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt32(endKey.val), time); break;

                        case PropertyTrack.ValueType.Float:
                            tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(val), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToSingle(endKey.val), time); break;

                        case PropertyTrack.ValueType.Double:
                            tween = DOTween.To(new DoublePlugin(), () => val, (x) => propInfo.SetValue(comp, x, null), endKey.val, time); break;

                        case PropertyTrack.ValueType.Long:
                            tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(val), (x) => propInfo.SetValue(comp, x, null), System.Convert.ToInt64(endKey.val), time); break;

                        case PropertyTrack.ValueType.Vector2:
                            tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => vect2, (x) => propInfo.SetValue(comp, x, null), endKey.vect2, time); break;

                        case PropertyTrack.ValueType.Vector3:
                            tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => vect3, (x) => propInfo.SetValue(comp, x, null), endKey.vect3, time); break;

                        case PropertyTrack.ValueType.Color:
                            tween = DOTween.To(TweenPluginFactory.CreateColor(), () => color, (x) => propInfo.SetValue(comp, x, null), endKey.color, time); break;

                        case PropertyTrack.ValueType.Rect:
                            tween = DOTween.To(new RectPlugin(), () => rect, (x) => propInfo.SetValue(comp, x, null), endKey.rect, time); break;

                        case PropertyTrack.ValueType.Vector4:
                            tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => vect4, (x) => propInfo.SetValue(comp, x, null), endKey.vect4, time); break;

                        case PropertyTrack.ValueType.Quaternion:
                            tween = DOTween.To(new PureQuaternionPlugin(), () => quat, (x) => propInfo.SetValue(comp, x, null), endKey.quat, time); break;
                        }
                    }
                    else
                    {
                        FieldInfo fieldInfo = propTrack.GetCachedFieldInfo();
                        if (fieldInfo != null)
                        {
                            switch (valueType)
                            {
                            case PropertyTrack.ValueType.Integer:
                                tween = DOTween.To(new IntPlugin(), () => System.Convert.ToInt32(val), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt32(endKey.val), time); break;

                            case PropertyTrack.ValueType.Float:
                                tween = DOTween.To(new FloatPlugin(), () => System.Convert.ToSingle(val), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToSingle(endKey.val), time); break;

                            case PropertyTrack.ValueType.Double:
                                tween = DOTween.To(new DoublePlugin(), () => val, (x) => fieldInfo.SetValue(comp, x), endKey.val, time); break;

                            case PropertyTrack.ValueType.Long:
                                tween = DOTween.To(new LongPlugin(), () => System.Convert.ToInt64(val), (x) => fieldInfo.SetValue(comp, x), System.Convert.ToInt64(endKey.val), time); break;

                            case PropertyTrack.ValueType.Vector2:
                                tween = DOTween.To(TweenPluginFactory.CreateVector2(), () => vect2, (x) => fieldInfo.SetValue(comp, x), endKey.vect2, time); break;

                            case PropertyTrack.ValueType.Vector3:
                                tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => vect3, (x) => fieldInfo.SetValue(comp, x), endKey.vect3, time); break;

                            case PropertyTrack.ValueType.Color:
                                tween = DOTween.To(TweenPluginFactory.CreateColor(), () => color, (x) => fieldInfo.SetValue(comp, x), endKey.color, time); break;

                            case PropertyTrack.ValueType.Rect:
                                tween = DOTween.To(new RectPlugin(), () => (Rect)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.rect, time); break;

                            case PropertyTrack.ValueType.Vector4:
                                tween = DOTween.To(TweenPluginFactory.CreateVector4(), () => vect4, (x) => fieldInfo.SetValue(comp, x), endKey.vect4, time); break;

                            case PropertyTrack.ValueType.Quaternion:
                                tween = DOTween.To(new PureQuaternionPlugin(), () => quat, (x) => fieldInfo.SetValue(comp, x), endKey.quat, time); break;
                            }
                        }
                    }

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

                        seq.Insert(this, tween);
                    }
                }
            }
            else
            {
                Debug.LogError("Animator: No FieldInfo or PropertyInfo set.");
            }

            return;
        }
Example #4
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;
        }
Example #5
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            Transform target = obj as Transform;

            int frameRate = seq.take.frameRate;

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

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

            if (!canTween)
            {
                float timeLength = 1.0f / frameRate;

                if (axis == AxisFlags.X)
                {
                    float _x     = rotation.x;
                    var   tweenX = DOTween.To(new TweenPlugValueSet <float>(), () => _x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, _x, timeLength);
                    tweenX.plugOptions.SetSequence(seq);
                    seq.Insert(this, tweenX);
                }
                else if (axis == AxisFlags.Y)
                {
                    float _y     = rotation.y;
                    var   tweenY = DOTween.To(new TweenPlugValueSet <float>(), () => _y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, _y, timeLength);
                    tweenY.plugOptions.SetSequence(seq);
                    seq.Insert(this, tweenY);
                }
                else if (axis == AxisFlags.Z)
                {
                    float _z     = rotation.z;
                    var   tweenZ = DOTween.To(new TweenPlugValueSet <float>(), () => _z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, _z, timeLength);
                    tweenZ.plugOptions.SetSequence(seq);
                    seq.Insert(this, tweenZ);
                }
                else if (axis == AxisFlags.All)
                {
                    var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => rotation, (r) => { target.localEulerAngles = r; }, rotation, timeLength);
                    tweenV.plugOptions.SetSequence(seq);
                    seq.Insert(this, tweenV);
                }
                else
                {
                    var tweenV = DOTween.To(new TweenPlugValueSet <Vector3>(), () => 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;
                    }, rotation, timeLength);
                    tweenV.plugOptions.SetSequence(seq);
                    seq.Insert(this, tweenV);
                }
            }
            else if (endFrame == -1)
            {
                return;
            }
            else
            {
                float   timeLength  = getTime(frameRate);
                Vector3 endRotation = (track.keys[index + 1] as RotationEulerKey).rotation;

                Tweener tween;

                if (axis == AxisFlags.X)
                {
                    tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.x, (x) => { var a = target.localEulerAngles; a.x = x; target.localEulerAngles = a; }, endRotation.x, timeLength);
                }
                else if (axis == AxisFlags.Y)
                {
                    tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.y, (y) => { var a = target.localEulerAngles; a.y = y; target.localEulerAngles = a; }, endRotation.y, timeLength);
                }
                else if (axis == AxisFlags.Z)
                {
                    tween = DOTween.To(new FloatPlugin(), () => target.localEulerAngles.z, (z) => { var a = target.localEulerAngles; a.z = z; target.localEulerAngles = a; }, endRotation.z, timeLength);
                }
                else if (axis == AxisFlags.All)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (r) => target.localEulerAngles = r, endRotation, timeLength);
                }
                else
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => target.localEulerAngles, (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 (hasCustomEase())
                {
                    tween.SetEase(easeCurve);
                }
                else
                {
                    tween.SetEase(easeType, amplitude, period);
                }

                seq.Insert(this, tween);
            }
        }
Example #6
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;
                }
            }

            var trans = obj as Transform;

            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;

            int   frameRate = seq.take.frameRate;
            float time      = getTime(frameRate);

            Tweener tween = null;

            if (interp == Interpolation.None)
            {
                //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;

                if (body2D)
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body2D.position = parent.TransformPoint(x);
                        }
                        else
                        {
                            body2D.position = x;
                        }
                    }, pos, time); //1.0f / frameRate
                }
                else if (body)
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body.position = parent.TransformPoint(x);
                        }
                        else
                        {
                            body.position = x;
                        }
                    }, pos, time); //1.0f / frameRate
                }
                else
                {
                    tween = DOTween.To(TweenPlugValueSet <Vector3> .Get(), () => trans.localPosition, (x) => trans.localPosition = x, pos, time); //1.0f / frameRate
                }
            }
            else if (interp == Interpolation.Linear || path == null)
            {
                Vector3 endPos = (track.keys[index + 1] as TranslationKey).position;

                DOSetter <Vector3> setter;
                if (body2D)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)));
                            }
                            else
                            {
                                body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body2D.MovePosition(x);
                            }
                        }
                    };
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)));
                            }
                            else
                            {
                                body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body.MovePosition(x);
                            }
                        }
                    };
                }
                else
                {
                    if (pixelSnap)
                    {
                        setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu);
                    }
                    else
                    {
                        setter = x => trans.localPosition = x;
                    }
                }

                if (orientMode == OrientMode.None)
                {
                    tween = DOTween.To(TweenPluginFactory.CreateVector3(), () => position, setter, endPos, time);
                }
                else
                {
                    TweenerCore <Vector3, Vector3, TweenPlugVector3LookAtOptions> tweenOrient;

                    if (body)
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtRigidbody.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = body;
                    }
                    else if (body2D)
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtRigidbody2D.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = body2D;
                    }
                    else
                    {
                        tweenOrient        = DOTween.To(TweenPlugVector3LookAtTransform.Get(), () => position, setter, endPos, time);
                        tweenOrient.target = trans;
                    }

                    tweenOrient.plugOptions = new TweenPlugVector3LookAtOptions()
                    {
                        orientMode = orientMode, lockAxis = orientLockAxis, lookAtPt = endPos, lookAtIsLocal = true
                    };
                    tween = tweenOrient;
                }
            }
            else if (interp == Interpolation.Curve)
            {
                DOSetter <Vector3> setter;
                if (body2D)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)));
                            }
                            else
                            {
                                body2D.MovePosition(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body2D.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body2D.MovePosition(x);
                            }
                        }
                    };
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)));
                            }
                            else
                            {
                                body.MovePosition(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu));
                            }
                        }
                    }
                    ;
                    else
                    {
                        setter = x => {
                            var parent = trans.parent;
                            if (parent)
                            {
                                body.MovePosition(parent.TransformPoint(x));
                            }
                            else
                            {
                                body.MovePosition(x);
                            }
                        }
                    };
                }
                else
                {
                    if (pixelSnap)
                    {
                        setter = x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu);
                    }
                    else
                    {
                        setter = x => trans.localPosition = x;
                    }
                }

                if (orientMode == OrientMode.None)
                {
                    tween = DOTween.To(TweenPlugPathVector3.Get(), () => position, setter, path, time);
                }
                else
                {
                    TweenerCore <Vector3, TweenPlugPath, TweenPlugPathOrientOptions> tweenOrient;

                    if (body)
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientRigidbody.Get(), () => position, setter, path, time);
                        tweenOrient.target = body;
                    }
                    else if (body2D)
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientRigidbody2D.Get(), () => position, setter, path, time);
                        tweenOrient.target = body2D;
                    }
                    else
                    {
                        tweenOrient        = DOTween.To(TweenPlugPathOrientTransform.Get(), () => position, setter, path, time);
                        tweenOrient.target = trans;
                    }

                    tweenOrient.plugOptions = new TweenPlugPathOrientOptions {
                        orientMode = orientMode, lockAxis = orientLockAxis
                    };
                    tween = tweenOrient;
                }
            }

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

                seq.Insert(this, tween);
            }
        }