Exemple #1
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            //float sTime = getWaitTime(seq.take.frameRate, 0.0f);

            Sequence    _seq       = seq.sequence;
            AudioSource _src       = target as AudioSource;
            float       frameRate  = seq.take.frameRate;
            float       frameCount = Mathf.Ceil(audioClip.length * frameRate);

            var tweenV = DOTween.To(new TweenPlugValueSetElapsed(), () => 0f, (t) => {
                if (t >= 1f)
                {
                    return;
                }

                float fFrame = Mathf.RoundToInt(t * frameCount);
                _src.time    = (fFrame / frameRate) % audioClip.length;

                _src.pitch = _seq.timeScale;

                if (oneShot)
                {
                    _src.PlayOneShot(audioClip);
                }
                else
                {
                    if ((_src.isPlaying && _src.clip == audioClip))
                    {
                        return;
                    }
                    _src.loop = loop;
                    _src.clip = audioClip;
                    _src.Play();
                }
            }, 0, (loop && !oneShot) ? 1f / frameRate : getTime(seq.take.frameRate));

            tweenV.plugOptions.SetSequence(seq);

            seq.Insert(this, tweenV);

            /*
             * _seq.InsertCallback(sTime, () => {
             *  //don't play when going backwards
             *  if(_seq.isBackwards) return;
             *
             *  _src.pitch = _seq.timeScale;
             *
             *  if(oneShot)
             *      _src.PlayOneShot(audioClip);
             *  else {
             *      if((_src.isPlaying && _src.clip == audioClip)) return;
             *      _src.loop = loop;
             *      _src.clip = audioClip;
             *      _src.Play();
             *  }
             * });*/
        }
Exemple #2
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            if (methodName == null)
            {
                return;
            }

            float duration = 1.0f / seq.take.frameRate;

            //can't send message if it's not a component
            Component compSendMsg = null;

            if (useSendMessage)
            {
                compSendMsg = target as Component;
            }

            if (compSendMsg)
            {
                if (parameters == null || parameters.Count <= 0)
                {
                    var tween = DOTween.To(new TweenPlugValueSetElapsed(), () => 0, (x) => compSendMsg.SendMessage(methodName, null, SendMessageOptions.DontRequireReceiver), 0, duration);
                    tween.plugOptions.SetSequence(seq);
                    seq.Insert(this, tween);
                }
                else
                {
                    var tween = DOTween.To(new TweenPlugValueSetElapsed(), () => 0, (x) => compSendMsg.SendMessage(methodName, parameters[0].toObject(seq.target), SendMessageOptions.DontRequireReceiver), 0, duration);
                    tween.plugOptions.SetSequence(seq);
                    seq.Insert(this, tween);
                }
            }
            else
            {
                var method = cachedMethodInfo != null ? cachedMethodInfo : target.GetType().GetMethod(methodName, GetParamTypes());

                object[] parms = buildParams(seq.target);

                var tween = DOTween.To(new TweenPlugValueSetElapsed(), () => 0, (x) => method.Invoke(target, parms), 0, duration);
                tween.plugOptions.SetSequence(seq);
                seq.Insert(this, tween);
            }
        }
 public override void buildSequenceStart(SequenceControl seq)
 {
     //need to add activate game object on start to 'reset' properly during reverse
     if (keys.Count > 0 && keys[0].frame > 0)
     {
         GameObject go    = GetTarget(seq.target) as GameObject;
         var        tween = DG.Tweening.DOTween.To(new TweenPlugValueSet <bool>(), () => go.activeSelf, (x) => go.SetActive(x), startActive, keys[0].getWaitTime(seq.take.frameRate, 0.0f));
         seq.Insert(0f, tween);
     }
 }
Exemple #4
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            if (!obj || (canTween && endFrame == -1))
            {
                return;
            }

            int frameRate = seq.take.frameRate;

            Transform trans = obj as Transform;

            Transform sTarget = GetTarget(seq.target);
            Transform eTarget = canTween ? (track.keys[index + 1] as OrientationKey).GetTarget(seq.target) : null;

            var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => {
                if (sTarget == null && eTarget == null)
                {
                    return;
                }
                else if (sTarget == null)
                {
                    trans.LookAt(eTarget);
                }
                else if (eTarget == null || sTarget == eTarget)
                {
                    trans.LookAt(sTarget);
                }
                else
                {
                    Quaternion s = Quaternion.LookRotation(sTarget.position - trans.position);
                    Quaternion e = Quaternion.LookRotation(eTarget.position - trans.position);

                    trans.rotation = Quaternion.Lerp(s, e, x);
                }
            }, 1f, getTime(frameRate));

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

            seq.Insert(this, tween);
        }
Exemple #5
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            Transform trans     = obj as Transform;
            int       frameRate = seq.take.frameRate;

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

            if (!canTween)
            {
                var tween = DOTween.To(new TweenPlugValueSet <Quaternion>(), () => rotation, (x) => trans.localRotation = x, rotation, getTime(frameRate));
                tween.plugOptions.SetSequence(seq);

                seq.Insert(this, tween);
            }
            else if (endFrame == -1)
            {
                return;
            }
            else
            {
                Quaternion endRotation = (track.keys[index + 1] as RotationKey).rotation;

                var tween = DOTween.To(new PureQuaternionPlugin(), () => trans.localRotation, (x) => trans.localRotation = x, endRotation, getTime(frameRate));

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

                seq.Insert(this, tween);
            }
        }
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            GameObject go = target as GameObject;

            if (go == null)
            {
                return;
            }

            var tween = DOTween.To(new TweenPlugValueSet <bool>(), () => go.activeSelf, (x) => go.SetActive(x), setActive, getTime(seq.take.frameRate));

            seq.Insert(this, tween);
        }
Exemple #7
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            //float sTime = getWaitTime(seq.take.frameRate, 0.0f);

            Sequence    _seq       = seq.sequence;
            AudioSource _src       = target as AudioSource;
            float       frameRate  = seq.take.frameRate;
            float       frameCount = Mathf.Ceil(audioClip.length * frameRate);

            if (oneShot)
            {
                seq.InsertCallback(this, () => {
                    //don't play when going backwards
                    if (_seq.isBackwards)
                    {
                        return;
                    }

                    _src.pitch = _seq.timeScale;
                    _src.PlayOneShot(audioClip);
                });
            }
            else
            {
                var tweenV = DOTween.To(TweenPlugElapsed.Get(), () => 0f, (t) => {
                    //don't play when going backwards
                    if (_seq.isBackwards)
                    {
                        return;
                    }

                    _src.time = t % audioClip.length;

                    _src.pitch = _seq.timeScale;

                    if ((_src.isPlaying && _src.clip == audioClip))
                    {
                        return;
                    }
                    _src.loop = loop;
                    _src.clip = audioClip;
                    _src.Play();
                }, 0, audioClip.length);

                tweenV.plugOptions = new TweenPlugElapsedOptions(new TweenPlugElapsedCounter());

                seq.Insert(this, tweenV);
            }
        }
Exemple #8
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            // if targets are equal do nothing
            if (endFrame == -1 || !hasTargets(seq.target) || targetsAreEqual(seq.target))
            {
                return;
            }

            Camera[] allCameras = (track as CameraSwitcherTrack).GetCachedCameras(seq.target);
            int      frameRate  = seq.take.frameRate;
            float    frameCount = getNumberOfFrames(frameRate);
            var      itarget    = seq.target;
            var      _seq       = seq.sequence;

            var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => {
                CameraFade cf = CameraFade.getCameraFade();

                PlayParam param = cf.playParam;
                if (param == null)
                {
                    param = cf.playParam = new PlayParam();
                }
                param.Apply(this, frameRate, itarget, allCameras, _seq.IsBackwards());

                cf.percent = x / frameCount;
                cf.value   = 1.0f - cf.percent;
            }, frameCount, frameCount / frameRate);

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

            seq.Insert(this, tween);
        }
        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);
            }
        }
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            Transform trans       = obj as Transform;
            var       transParent = trans.parent;

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

            int frameRate = seq.take.frameRate;

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

            if (!canTween)
            {
                TweenerCore <Quaternion, Quaternion, TWeenPlugNoneOptions> tween;

                if (body2D)
                {
                    tween = DOTween.To(new TweenPlugValueSet <Quaternion>(), () => trans.localRotation, (x) => body2D.rotation = (x * transParent.rotation).eulerAngles.z, rotation, getTime(frameRate));
                }
                else if (body)
                {
                    tween = DOTween.To(new TweenPlugValueSet <Quaternion>(), () => trans.localRotation, (x) => body.rotation = x * transParent.rotation, rotation, getTime(frameRate));
                }
                else
                {
                    tween = DOTween.To(new TweenPlugValueSet <Quaternion>(), () => trans.localRotation, (x) => trans.localRotation = x, rotation, getTime(frameRate));
                }

                seq.Insert(this, tween);
            }
            else if (endFrame == -1)
            {
                return;
            }
            else
            {
                Quaternion endRotation = (track.keys[index + 1] as RotationKey).rotation;

                TweenerCore <Quaternion, Quaternion, DG.Tweening.Plugins.Options.NoOptions> tween;

                if (body2D)
                {
                    tween = DOTween.To(new PureQuaternionPlugin(), () => trans.localRotation, (x) => body2D.MoveRotation((x * transParent.rotation).eulerAngles.z), endRotation, getTime(frameRate));
                }
                else if (body)
                {
                    tween = DOTween.To(new PureQuaternionPlugin(), () => trans.localRotation, (x) => body.MoveRotation(x * transParent.rotation), endRotation, getTime(frameRate));
                }
                else
                {
                    tween = DOTween.To(new PureQuaternionPlugin(), () => trans.localRotation, (x) => trans.localRotation = x, endRotation, getTime(frameRate));
                }

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

                seq.Insert(this, tween);
            }
        }
Exemple #11
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);
            }
        }
Exemple #12
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
    }
Exemple #13
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 #14
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;
        }
Exemple #15
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            int frameRate = seq.take.frameRate;

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

            var trans       = obj as Transform;
            var transParent = trans.parent;

            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;

            if (!canTween)
            {
                //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;

                TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweener;

                if (body2D)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body2D.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else if (body)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => trans.localPosition = x, pos, getTime(frameRate)); //1.0f / frameRate
                }
                seq.Insert(this, tweener);
            }
            else
            {
                if (path.Length <= 1)
                {
                    return;
                }
                if (getNumberOfFrames(seq.take.frameRate) <= 0)
                {
                    return;
                }

                TweenerCore <Vector3, Path, PathOptions> ret = null;

                bool isRelative = false;

                PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom;

                var pathTween = new Path(pathType, path, pathResolution);
                var timeTween = getTime(frameRate);

                if (body2D)
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu))), pathTween, timeTween).SetTarget(body2D);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body2D.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body2D);
                    }
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu))), pathTween, timeTween).SetTarget(body);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => body.MovePosition(transParent.TransformPoint(x)), pathTween, timeTween).SetTarget(body);
                    }
                }
                else
                {
                    if (pixelSnap)
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), pathTween, timeTween).SetTarget(trans);
                    }
                    else
                    {
                        ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, pathTween, timeTween).SetTarget(trans);
                    }
                }

                ret.SetRelative(isRelative).SetOptions(isClosed);

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

                seq.Insert(this, ret);
            }
        }
Exemple #16
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;
                }
                if (interp == Interpolation.Curve && path.Length <= 1)
                {
                    return;
                }
            }

            Transform trans       = obj as Transform;
            var       transParent = trans.parent;

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

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

            switch (interp)
            {
            case Interpolation.None:
                TweenerCore <Quaternion, Quaternion, TWeenPlugNoneOptions> valueTween;

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

                seq.Insert(this, valueTween);
                break;

            case Interpolation.Linear:
                Quaternion endRotation = (track.keys[index + 1] as RotationKey).rotation;

                TweenerCore <Quaternion, Quaternion, NoOptions> linearTween;

                if (body2D)
                {
                    linearTween = DOTween.To(new PureQuaternionPlugin(), () => rotation, (x) => body2D.MoveRotation((x * transParent.rotation).eulerAngles.z), endRotation, time);
                }
                else if (body)
                {
                    linearTween = DOTween.To(new PureQuaternionPlugin(), () => rotation, (x) => body.MoveRotation(x * transParent.rotation), endRotation, time);
                }
                else
                {
                    linearTween = DOTween.To(new PureQuaternionPlugin(), () => rotation, (x) => trans.localRotation = x, endRotation, time);
                }

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

                seq.Insert(this, linearTween);
                break;

            case Interpolation.Curve:
                var pathTween = GetPathTween(frameRate);

                if (body2D)
                {
                    pathTween.setter = x => body2D.MoveRotation(transParent.eulerAngles.z + x.z);
                    pathTween.SetTarget(body2D);
                }
                else if (body)
                {
                    pathTween.setter = x => body.MoveRotation(Quaternion.Euler(x) * transParent.rotation);
                    pathTween.SetTarget(body);
                }
                else
                {
                    pathTween.setter = x => trans.localRotation = Quaternion.Euler(x);
                    pathTween.SetTarget(trans);
                }

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

                seq.Insert(this, pathTween);
                break;
            }
        }
Exemple #17
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            int frameRate = seq.take.frameRate;

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

            Transform trans = obj as Transform;

            var   tTrack    = track as TranslationTrack;
            bool  pixelSnap = tTrack.pixelSnap;
            float ppu       = tTrack.pixelPerUnit;

            if (!canTween)
            {
                //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;

                var tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => pos, (x) => trans.localPosition = x, pos, 1.0f / frameRate); //getTime(frameRate)
                tweener.plugOptions.SetSequence(seq);

                seq.Insert(this, tweener);
            }
            else
            {
                if (path.Length <= 1)
                {
                    return;
                }
                if (getNumberOfFrames(seq.take.frameRate) <= 0)
                {
                    return;
                }

                Tweener ret = null;

                bool isRelative = false;

                PathType pathType = path.Length == 2 ? PathType.Linear : PathType.CatmullRom;

                if (pixelSnap)
                {
                    ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu), new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed);
                }
                else
                {
                    ret = DOTween.To(PathPlugin.Get(), () => path[0], x => trans.localPosition = x, new Path(pathType, path, pathResolution), getTime(frameRate)).SetTarget(trans).SetRelative(isRelative).SetOptions(isClosed);
                }

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

                seq.Insert(this, ret);
            }
        }
Exemple #18
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);
            }
        }
Exemple #19
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);
            }
        }
Exemple #20
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object target)
        {
            int   frameRate = seq.take.frameRate;
            float waitTime  = getWaitTime(frameRate, 0.0f);
            var   anim      = (target as GameObject).GetComponent <Animation>();

            float duration = wrapMode == WrapMode.Once ? amClip.length : ((seq.take.getLastFrame() - frame) + 1) / (float)frameRate;

            if (crossfade)
            {
                if (index > 0)
                {
                    var prevKey = track.keys[index - 1] as UnityAnimationKey;

                    var prevAnimState = anim[prevKey.amClip.name];
                    var prevWrap      = prevKey.wrapMode;
                    var prevStartTime = prevKey.getWaitTime(frameRate, 0.0f);
                    var animState     = anim[amClip.name];

                    var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => {
                        if (x < crossfadeTime)
                        {
                            float weight = x / crossfadeTime;

                            prevAnimState.enabled  = true;
                            prevAnimState.wrapMode = prevWrap;
                            prevAnimState.weight   = 1.0f - weight;
                            prevAnimState.time     = (waitTime + x) - prevStartTime;

                            animState.enabled  = true;
                            animState.wrapMode = wrapMode;
                            animState.weight   = weight;
                            animState.time     = x;

                            anim.Sample();

                            prevAnimState.enabled = false;
                            animState.enabled     = false;
                        }
                        else
                        {
                            animState.enabled  = true;
                            animState.wrapMode = wrapMode;
                            animState.weight   = 1.0f;
                            animState.time     = x;

                            anim.Sample();

                            animState.enabled = false;
                        }
                    }, duration, duration);

                    seq.Insert(this, tween);
                }
                else
                {
                    var animState = anim[amClip.name];

                    var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => {
                        animState.enabled  = true;
                        animState.wrapMode = wrapMode;
                        animState.time     = x;

                        if (x < crossfadeTime)
                        {
                            animState.weight = x / crossfadeTime;
                        }
                        else
                        {
                            animState.weight = 1.0f;
                        }

                        anim.Sample();
                        animState.enabled = false;
                    }, duration, duration);

                    seq.Insert(this, tween);
                }
            }
            else
            {
                var animState = anim[amClip.name];

                var tween = DOTween.To(new FloatPlugin(), () => 0f, (x) => {
                    animState.enabled  = true;
                    animState.wrapMode = wrapMode;
                    animState.time     = x;
                    animState.weight   = 1.0f;
                    anim.Sample();
                    animState.enabled = false;
                }, duration, duration);

                seq.Insert(this, tween);
            }
        }
Exemple #21
0
        public override void build(SequenceControl seq, Track track, int index, UnityEngine.Object obj)
        {
            int frameRate = seq.take.frameRate;

            //allow tracks with just one key
            if (track.keys.Count == 1)
            {
                interp = Interpolation.None;
            }
            else if (canTween)
            {
                //invalid or in-between keys
                if (path.Length <= 1)
                {
                    return;
                }
                if (getNumberOfFrames(frameRate) <= 0)
                {
                    return;
                }
            }

            var trans       = obj as Transform;
            var transParent = trans.parent;

            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;

            if (!canTween)
            {
                //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;

                TweenerCore <Vector3, Vector3, TWeenPlugNoneOptions> tweener;

                if (body2D)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body2D.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else if (body)
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => body.position = transParent.TransformPoint(x), pos, getTime(frameRate)); //1.0f / frameRate
                }
                else
                {
                    tweener = DOTween.To(new TweenPlugValueSet <Vector3>(), () => trans.localPosition, (x) => trans.localPosition = x, pos, getTime(frameRate)); //1.0f / frameRate
                }
                seq.Insert(this, tweener);
            }
            else
            {
                var tween = GetPathTween(frameRate);

                if (body2D)
                {
                    if (pixelSnap)
                    {
                        tween.setter = x => body2D.MovePosition(transParent.TransformPoint(new Vector2(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu)));
                    }
                    else
                    {
                        tween.setter = x => body2D.MovePosition(transParent.TransformPoint(x));
                    }

                    tween.SetTarget(body2D);
                }
                else if (body)
                {
                    if (pixelSnap)
                    {
                        tween.setter = x => body.MovePosition(transParent.TransformPoint(new Vector3(Mathf.Round(x.x * ppu) / ppu, Mathf.Round(x.y * ppu) / ppu, Mathf.Round(x.z * ppu) / ppu)));
                    }
                    else
                    {
                        tween.setter = x => body.MovePosition(transParent.TransformPoint(x));
                    }

                    tween.SetTarget(body);
                }
                else
                {
                    if (pixelSnap)
                    {
                        tween.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
                    {
                        tween.setter = x => trans.localPosition = x;
                    }

                    tween.SetTarget(trans);
                }

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

                seq.Insert(this, tween);
            }
        }
Exemple #22
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);
            }
        }
Exemple #23
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);
            }
        }