Example #1
0
        public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target)
        {
            AMMaterialTrack matTrack = track as AMMaterialTrack;

            AMMaterialTrack.ValueType 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;
            AMMaterialKey endKey     = index + 1 < keyCount ? track.keys[index + 1] as AMMaterialKey : null;
            float         frameCount = endKey != null ? endKey.frame - frame + 1 : 1f;

            switch (propType)
            {
            case AMMaterialTrack.ValueType.Float:
            case AMMaterialTrack.ValueType.Range:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var setTween = DOTween.To(new AMPlugValueSet <float>(), () => val, (x) => matInst.SetFloat(propId, x), val, frameCount / frameRate);
                    setTween.plugOptions.SetSequence(seq);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

                    tween = DOTween.To(new FloatPlugin(), () => matInst.GetFloat(propId), (x) => matInst.SetFloat(propId, x), endKey.val, getTime(frameRate));
                }
                break;

            case AMMaterialTrack.ValueType.Vector:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var setTween = DOTween.To(new AMPlugValueSet <Vector4>(), () => vector, (x) => matInst.SetVector(propId, x), vector, frameCount / frameRate);
                    setTween.plugOptions.SetSequence(seq);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

                    tween = DOTween.To(AMPluginFactory.CreateVector4(), () => matInst.GetVector(propId), (x) => matInst.SetVector(propId, x), endKey.vector, getTime(frameRate));
                }
                break;

            case AMMaterialTrack.ValueType.Color:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var val      = color;
                    var setTween = DOTween.To(new AMPlugValueSet <Color>(), () => val, (x) => matInst.SetColor(propId, x), val, frameCount / frameRate);
                    setTween.plugOptions.SetSequence(seq);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

                    tween = DOTween.To(AMPluginFactory.CreateColor(), () => matInst.GetColor(propId), (x) => matInst.SetColor(propId, x), endKey.color, getTime(frameRate));
                }
                break;

            case AMMaterialTrack.ValueType.TexOfs:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var val      = texOfs;
                    var setTween = DOTween.To(new AMPlugValueSet <Vector2>(), () => val, (x) => matInst.SetTextureOffset(prop, x), val, frameCount / frameRate);
                    setTween.plugOptions.SetSequence(seq);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

                    tween = DOTween.To(AMPluginFactory.CreateVector2(), () => matInst.GetTextureOffset(prop), (x) => matInst.SetTextureOffset(prop, x), endKey.texOfs, getTime(frameRate));
                }
                break;

            case AMMaterialTrack.ValueType.TexScale:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var val      = texScale;
                    var setTween = DOTween.To(new AMPlugValueSet <Vector2>(), () => val, (x) => matInst.SetTextureScale(prop, x), val, frameCount / frameRate);
                    setTween.plugOptions.SetSequence(seq);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

                    tween = DOTween.To(AMPluginFactory.CreateVector2(), () => matInst.GetTextureScale(prop), (x) => matInst.SetTextureScale(prop, x), endKey.texScale, getTime(frameRate));
                }
                break;

            case AMMaterialTrack.ValueType.TexEnv:
                var texEnvTween = DOTween.To(new AMPlugValueSet <Texture>(), () => texture, (x) => matInst.SetTexture(propId, x), texture, frameCount / frameRate);
                texEnvTween.plugOptions.SetSequence(seq);
                seq.Insert(this, texEnvTween);
                break;
            }

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

                seq.Insert(this, tween);
            }
        }
Example #2
0
        public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target)
        {
            AMPropertyTrack propTrack = track as AMPropertyTrack;

            if (endFrame == -1 && canTween && propTrack.canTween)
            {
                return;
            }

            int 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, GenerateTweener(seq, propTrack, frameRate, comp));
                }
                else
                {
                    //grab end frame
                    AMPropertyKey endKey = track.keys[index + 1] as AMPropertyKey;

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

                    Tweener tween = null;

                    PropertyInfo propInfo = propTrack.GetCachedPropertyInfo();
                    if (propInfo != null)
                    {
                        switch ((AMPropertyTrack.ValueType)valueType)
                        {
                        case AMPropertyTrack.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 AMPropertyTrack.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 AMPropertyTrack.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 AMPropertyTrack.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 AMPropertyTrack.ValueType.Vector2:
                            tween = DOTween.To(AMPluginFactory.CreateVector2(), () => (Vector2)propInfo.GetValue(comp, null), (x) => propInfo.SetValue(comp, x, null), endKey.vect2, getTime(frameRate)); break;

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

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

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

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

                        case AMPropertyTrack.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 ((AMPropertyTrack.ValueType)valueType)
                            {
                            case AMPropertyTrack.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 AMPropertyTrack.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 AMPropertyTrack.ValueType.Double:
                                tween = DOTween.To(new DoublePlugin(), () => System.Convert.ToDouble(fieldInfo.GetValue(comp)), (x) => fieldInfo.SetValue(comp, x), endKey.val, getTime(frameRate)); break;

                            case AMPropertyTrack.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 AMPropertyTrack.ValueType.Vector2:
                                tween = DOTween.To(AMPluginFactory.CreateVector2(), () => (Vector2)fieldInfo.GetValue(comp), (x) => fieldInfo.SetValue(comp, x), endKey.vect2, getTime(frameRate)); break;

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

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

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

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

                            case AMPropertyTrack.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;
        }