Exemple #1
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;
        }
Exemple #2
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;
        }