public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            PropertyTrack propTrack = track as PropertyTrack;

            if (endFrame == -1 && canTween && propTrack.canTween)
            {
                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;
            }

            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 || track.keys.Count == 1)
                {
                    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;

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

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

                        case PropertyTrack.ValueType.Double:
                            tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(propInfo.GetValue(comp, null)), (x) => propInfo.SetValue(comp, x, null), endKey.val, getTime(frameRate)); break;

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

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

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

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

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

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

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

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

                            case PropertyTrack.ValueType.Double:
                                tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), endKey.val, getTime(frameRate)); break;

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

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

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

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

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

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

                            case PropertyTrack.ValueType.Quaternion:
                                tween = DOTween.To(new PureQuaternionPlugin(), () => (Quaternion)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.quat, getTime(frameRate)); 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;
        }
Exemple #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 trans = obj as Transform;

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

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

            if (interp == Interpolation.None)
            {
                TweenerCore <Quaternion, Quaternion, TWeenPlugNoneOptions> valueTween;

                if (body2D)
                {
                    valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body2D.rotation = (x * parent.rotation).eulerAngles.z;
                        }
                        else
                        {
                            body2D.rotation = x.eulerAngles.z;
                        }
                    }, rotation, time);
                }
                else if (body)
                {
                    valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body.rotation = x * parent.rotation;
                        }
                        else
                        {
                            body.rotation = x;
                        }
                    }, rotation, time);
                }
                else
                {
                    valueTween = DOTween.To(TweenPlugValueSet <Quaternion> .Get(), () => trans.localRotation, (x) => trans.localRotation = x, rotation, time);
                }

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

                TweenerCore <Quaternion, Quaternion, NoOptions> linearTween;

                if (body2D)
                {
                    linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body2D.MoveRotation((x * parent.rotation).eulerAngles.z);
                        }
                        else
                        {
                            body2D.MoveRotation(x.eulerAngles.z);
                        }
                    }, endRotation, time);
                }
                else if (body)
                {
                    linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body.MoveRotation(x * parent.rotation);
                        }
                        else
                        {
                            body.MoveRotation(x);
                        }
                    }, endRotation, time);
                }
                else
                {
                    linearTween = DOTween.To(TweenPluginFactory.CreateQuaternion(), () => rotation, (x) => trans.localRotation = x, endRotation, time);
                }

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

                seq.Insert(this, linearTween);
            }
            else if (interp == Interpolation.Curve)
            {
                DOSetter <Quaternion> setter;
                if (body2D)
                {
                    setter = x => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body2D.MoveRotation((x * parent.rotation).eulerAngles.z);
                        }
                        else
                        {
                            body2D.MoveRotation(x.eulerAngles.z);
                        }
                    }
                }
                ;
                else if (body)
                {
                    setter = x => {
                        var parent = trans.parent;
                        if (parent)
                        {
                            body.MoveRotation(x * parent.rotation);
                        }
                        else
                        {
                            body.MoveRotation(x);
                        }
                    }
                }
                ;
                else
                {
                    setter = x => trans.localRotation = x;
                }

                var pathTween = DOTween.To(TweenPlugPathEuler.Get(), () => rotation, setter, path, time);

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

                seq.Insert(this, pathTween);
            }
        }