Exemplo n.º 1
0
        // update cache (optimized)
        public override void updateCache(AMITarget target)
        {
            base.updateCache(target);

            for (int i = 0; i < keys.Count; i++)
            {
                AMRotationKey key = keys[i] as AMRotationKey;

                key.version = version;

                //a.type = (keys[i] as AMRotationKey).type;

                if (keys.Count > (i + 1))
                {
                    key.endFrame = keys[i + 1].frame;
                }
                else
                {
                    if (i > 0 && !keys[i - 1].canTween)
                    {
                        key.interp = (int)AMKey.Interpolation.None;
                    }

                    key.endFrame = -1;
                }
            }
        }
Exemplo n.º 2
0
        // add a new key
        public void addKey(AMITarget target, OnAddKey addCall, int _frame, Quaternion _rotation)
        {
            foreach (AMRotationKey key in keys)
            {
                // if key exists on frame, update key
                if (key.frame == _frame)
                {
                    key.rotation = _rotation;
                    // update cache
                    updateCache(target);
                    return;
                }
            }
            AMRotationKey a = addCall(gameObject, typeof(AMRotationKey)) as AMRotationKey;

            a.frame    = _frame;
            a.rotation = _rotation;
            // set default ease type to linear
            a.easeType = (int)Ease.Linear;

            // add a new key
            keys.Add(a);
            // update cache
            updateCache(target);
        }
Exemplo n.º 3
0
        // copy properties from key
        public override void CopyTo(AMKey key)
        {
            base.CopyTo(key);

            AMRotationKey a = key as AMRotationKey;

            //a.type = type;
            a.rotation = rotation;
        }
Exemplo n.º 4
0
        // copy properties from key
        public override void CopyTo(AMKey key)
        {
            AMRotationKey a = key as AMRotationKey;

            a.enabled = false;
            a.frame   = frame;
            //a.type = type;
            a.rotation   = rotation;
            a.easeType   = easeType;
            a.customEase = new List <float>(customEase);
        }
Exemplo n.º 5
0
        Quaternion getRotationAtFrame(int frame, int frameRate)
        {
            // if before or equal to first frame, or is the only frame
            AMRotationKey firstKey = keys[0] as AMRotationKey;

            if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween))
            {
                return(firstKey.rotation);
            }

            // if lies on rotation action
            for (int i = 0; i < keys.Count; i++)
            {
                AMRotationKey key     = keys[i] as AMRotationKey;
                AMRotationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMRotationKey : null;

                if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1))
                {
                    continue;
                }
                // if no ease
                if (!key.canTween || keyNext == null)
                {
                    return(key.rotation);
                }
                // else find Quaternion using easing function

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

                float framePositionInAction = Mathf.Clamp(frame - (float)key.frame, 0f, numFrames);

                Quaternion qStart = key.rotation;
                Quaternion qEnd   = keyNext.rotation;

                if (key.hasCustomEase())
                {
                    return(Quaternion.LerpUnclamped(qStart, qEnd, AMUtil.EaseCustom(0.0f, 1.0f, framePositionInAction / numFrames, key.easeCurve)));
                }
                else
                {
                    var ease = AMUtil.GetEasingFunction((Ease)key.easeType);
                    return(Quaternion.LerpUnclamped(qStart, qEnd, ease(framePositionInAction, numFrames, key.amplitude, key.period)));
                }
            }

            Debug.LogError("Animator: Could not get rotation at frame '" + frame + "'");
            return(Quaternion.identity);
        }
Exemplo n.º 6
0
        // preview a frame in the scene view
        public override void previewFrame(AMITarget target, float frame, int frameRate, bool play, float playSpeed)
        {
            Transform t = GetTarget(target) as Transform;

            int keyCount = keys.Count;

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

            // if before or equal to first frame, or is the only frame
            AMRotationKey firstKey = keys[0] as AMRotationKey;

            if (firstKey.endFrame == -1 || (frame <= (float)firstKey.frame && !firstKey.canTween))
            {
                t.localRotation = firstKey.rotation;
                return;
            }

            // if lies on rotation action
            for (int i = 0; i < keys.Count; i++)
            {
                AMRotationKey key     = keys[i] as AMRotationKey;
                AMRotationKey keyNext = i + 1 < keys.Count ? keys[i + 1] as AMRotationKey : null;

                if (frame >= (float)key.endFrame && keyNext != null && (!keyNext.canTween || keyNext.endFrame != -1))
                {
                    continue;
                }
                // if no ease
                if (!key.canTween || keyNext == null)
                {
                    t.localRotation = key.rotation;
                    return;
                }
                // else find Quaternion using easing function

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

                float framePositionInAction = Mathf.Clamp(frame - (float)key.frame, 0f, numFrames);

                Quaternion qStart = key.rotation;
                Quaternion qEnd   = keyNext.rotation;

                if (key.hasCustomEase())
                {
                    t.localRotation = Quaternion.LerpUnclamped(qStart, qEnd, AMUtil.EaseCustom(0.0f, 1.0f, framePositionInAction / numFrames, key.easeCurve));
                }
                else
                {
                    var ease = AMUtil.GetEasingFunction((Ease)key.easeType);
                    t.localRotation = Quaternion.LerpUnclamped(qStart, qEnd, ease(framePositionInAction, numFrames, key.amplitude, key.period));
                }

                return;
            }
        }