Exemple #1
0
        public Vector3 getPositionAtFrame(Transform t, int frame, int frameRate, bool forceWorld)
        {
            int keyCount = keys.Count;

            if (keyCount <= 0)
            {
                return(GetPosition(t));
            }

            AMTranslationKey firstKey = keys[0] as AMTranslationKey;

            //check if behind first key
            if (frame <= firstKey.frame && (!firstKey.canTween || firstKey.path.Length == 1))
            {
                return(convertPosition(t, firstKey.position, forceWorld));
            }

            AMTranslationKey lastKey = keyCount == 1 ? firstKey : keys[keyCount - 1] as AMTranslationKey;

            //check if past last key
            if (frame >= lastKey.endFrame && !lastKey.canTween)
            {
                return(convertPosition(t, lastKey.position, forceWorld));
            }

            //check in-between
            for (int i = 0; i < keyCount; i++)
            {
                AMTranslationKey key     = keys[i] as AMTranslationKey;
                AMTranslationKey keyNext = i < keyCount - 1 ? keys[i + 1] as AMTranslationKey : null;

                if (frame >= key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.path.Length > 1))
                {
                    continue;
                }

                if (!key.canTween || key.path.Length == 1)
                {
                    return(convertPosition(t, key.position, forceWorld));
                }
                else if (key.path.Length == 0)
                {
                    continue;
                }

                float fNumFrames = (float)key.getNumberOfFrames(frameRate);

                float _value;

                float framePositionInPath = Mathf.Clamp(frame - (float)key.frame, 0f, fNumFrames);

                if (key.hasCustomEase())
                {
                    _value = AMUtil.EaseCustom(0.0f, 1.0f, framePositionInPath / fNumFrames, key.easeCurve);
                }
                else
                {
                    var ease = AMUtil.GetEasingFunction((Ease)key.easeType);
                    _value = ease(framePositionInPath, fNumFrames, key.amplitude, key.period);
                    if (float.IsNaN(_value)) //this really shouldn't happen...
                    {
                        break;
                    }
                }

                return(convertPosition(t, key.GetPoint(Mathf.Clamp01(_value)), forceWorld));
            }

            Debug.LogError("Animator: Could not get " + t.name + " position at frame '" + frame + "'");
            return(GetPosition(t));
        }
Exemple #2
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget itarget, float frame, int frameRate, bool play, float playSpeed)
        {
            Transform t = GetTarget(itarget) as Transform;

            if (!t)
            {
                return;
            }

            int keyCount = keys.Count;

            if (keys == null || keyCount <= 0)
            {
                return;
            }

            int iFrame = Mathf.RoundToInt(frame);

            AMTranslationKey firstKey = keys[0] as AMTranslationKey;

            //check if behind first key
            if (iFrame <= firstKey.frame && (!firstKey.canTween || firstKey.path.Length == 1))
            {
                SetPosition(t, firstKey.position);
                return;
            }

            AMTranslationKey lastKey = keyCount == 1 ? firstKey : keys[keyCount - 1] as AMTranslationKey;

            //check if past last key
            if (iFrame >= lastKey.endFrame && !lastKey.canTween)
            {
                SetPosition(t, lastKey.position);
                return;
            }

            //check in-between
            for (int i = 0; i < keyCount; i++)
            {
                AMTranslationKey key = keys[i] as AMTranslationKey;

                if (iFrame >= key.endFrame && i < keyCount - 1)
                {
                    continue;
                }

                if (!key.canTween || key.path.Length == 1)
                {
                    SetPosition(t, key.position);
                    return;
                }
                else if (key.path.Length == 0)
                {
                    continue;
                }

                float fNumFrames = (float)key.getNumberOfFrames(frameRate);

                float _value;

                float framePositionInPath = Mathf.Clamp(frame - (float)key.frame, 0f, fNumFrames);

                if (key.hasCustomEase())
                {
                    _value = AMUtil.EaseCustom(0.0f, 1.0f, framePositionInPath / fNumFrames, key.easeCurve);
                }
                else
                {
                    var ease = AMUtil.GetEasingFunction((Ease)key.easeType);
                    _value = ease(framePositionInPath, fNumFrames, key.amplitude, key.period);
                    if (float.IsNaN(_value)) //this really shouldn't happen...
                    {
                        return;
                    }
                }

                SetPosition(t, key.GetPoint(Mathf.Clamp01(_value)));

                return;
            }
        }