public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            var matTrack = track as MaterialTrack;
            var propType = matTrack.propertyType;

            Material matInst = matTrack.materialInstance;

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

            int frameRate = seq.take.frameRate;

            Tweener tween = null;

            int   keyCount   = track.keys.Count;
            var   endKey     = index + 1 < keyCount ? track.keys[index + 1] as MaterialKey : null;
            float frameCount = endKey != null ? endKey.frame - frame + 1 : 1f;

            switch (propType)
            {
            case MaterialTrack.ValueType.Float:
            case MaterialTrack.ValueType.Range:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var setTween = DOTween.To(new TweenPlugValueSet <float>(), () => matInst.GetFloat(propId), (x) => matInst.SetFloat(propId, x), val, frameCount / frameRate);
                    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 MaterialTrack.ValueType.Vector:
                if (!canTween || keyCount == 1)     //allow one key
                {
                    var setTween = DOTween.To(new TweenPlugValueSet <Vector4>(), () => matInst.GetVector(propId), (x) => matInst.SetVector(propId, x), vector, frameCount / frameRate);
                    seq.Insert(this, setTween);
                }
                else
                {
                    if (targetsAreEqual(propType, endKey))
                    {
                        return;
                    }

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

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

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

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

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

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

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

            case MaterialTrack.ValueType.TexEnv:
                var texEnvTween = DOTween.To(new TweenPlugValueSet <Texture>(), () => matInst.GetTexture(propId), (x) => matInst.SetTexture(propId, x), texture, frameCount / frameRate);
                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(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 #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;
                }
            }

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

            Material matInst = matTrack.materialInstance;

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

            int frameRate = seq.take.frameRate;

            Tweener tween = null;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                seq.Insert(this, tween);
            }
        }