コード例 #1
0
        // copy properties from key
        public override void CopyTo(AMKey key)
        {
            AMAnimationKey a = key as AMAnimationKey;

            a.enabled   = false;
            a.frame     = frame;
            a.wrapMode  = wrapMode;
            a.amClip    = amClip;
            a.crossfade = crossfade;
        }
コード例 #2
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            GameObject go = GetTarget(target) as GameObject;

            if (!go || keys.Count == 0)
            {
                return;
            }

            Animation anim = go.GetComponent <Animation>();

            if (frame < keys[0].frame)
            {
                AMAnimationKey amKey = keys[0] as AMAnimationKey;
                if (amKey.amClip)
                {
                    Utility.SampleAnimation(anim, amKey.amClip.name, amKey.wrapMode, amKey.crossfade ? 0.0f : 1.0f, 0.0f);
                }
                return;
            }

            for (int i = keys.Count - 1; i >= 0; i--)
            {
                if (keys[i].frame <= frame)
                {
                    AMAnimationKey amKey = keys[i] as AMAnimationKey;
                    if (amKey.amClip)
                    {
                        float t = (frame - (float)amKey.frame) / (float)frameRate;

                        if (amKey.crossfade)
                        {
                            if (i > 0)
                            {
                                AMAnimationKey amPrevKey = keys[i - 1] as AMAnimationKey;
                                if (amPrevKey.amClip)
                                {
                                    float prevT = (frame - (float)amPrevKey.frame) / (float)frameRate;
                                    Utility.SampleAnimationCrossFade(anim, amKey.crossfadeTime, amPrevKey.amClip.name, amPrevKey.wrapMode, prevT, amKey.amClip.name, amKey.wrapMode, t);
                                }
                            }
                            else
                            {
                                Utility.SampleAnimationFadeIn(anim, amKey.amClip.name, amKey.wrapMode, amKey.crossfadeTime, t);
                            }
                        }
                        else
                        {
                            Utility.SampleAnimation(anim, amKey.amClip.name, amKey.wrapMode, 1.0f, t);
                        }
                    }
                    break;
                }
            }
        }
コード例 #3
0
        // copy properties from key
        public override void CopyTo(AMKey key)
        {
            base.CopyTo(key);

            AMAnimationKey a = key as AMAnimationKey;

            a.wrapMode      = wrapMode;
            a.amClip        = amClip;
            a.crossfade     = crossfade;
            a.crossfadeTime = crossfadeTime;
        }
コード例 #4
0
        // add a new key
        public void addKey(AMITarget itarget, OnAddKey addCall, int _frame, AnimationClip _clip, WrapMode _wrapMode)
        {
            foreach (AMAnimationKey key in keys)
            {
                // if key exists on frame, update key
                if (key.frame == _frame)
                {
                    key.amClip   = _clip;
                    key.wrapMode = _wrapMode;
                    // update cache
                    updateCache(itarget);
                    return;
                }
            }
            AMAnimationKey a = addCall(gameObject, typeof(AMAnimationKey)) as AMAnimationKey;

            a.frame    = _frame;
            a.amClip   = _clip;
            a.wrapMode = _wrapMode;
            // add a new key
            keys.Add(a);
            // update cache
            updateCache(itarget);
        }
コード例 #5
0
        public override void build(AMSequence seq, AMTrack track, int index, UnityEngine.Object target)
        {
            int       frameRate = seq.take.frameRate;
            float     waitTime  = getWaitTime(frameRate, 0.0f);
            Animation 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)
                {
                    AMAnimationKey prevKey = track.keys[index - 1] as AMAnimationKey;

                    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);
            }
        }