Ejemplo n.º 1
0
        public AnimationAction(Transform target) : base(100)
        {
            _target = target;

            var posSK = new AnimKey(0, _target.position);
            var rotSK = new AnimKey(0, _target.eulerAngles);
            var sclSK = new AnimKey(0, _target.localScale);

            _tracks.Add(EAKey.Position, new List <AnimKey> {
                posSK
            });
            _tracks.Add(EAKey.Rotation, new List <AnimKey> {
                rotSK
            });
            _tracks.Add(EAKey.Scale, new List <AnimKey> {
                sclSK
            });
        }
Ejemplo n.º 2
0
        private Vector3 Interpolate(float relT, List <AnimKey> keys)
        {
            if (keys.Count == 1)
            {
                return(keys[0].Val);
            }

            AnimKey current   = AnimKey.Zero;
            AnimKey next      = AnimKey.Zero;
            bool    nextFound = false;

            for (int i = 0; i < keys.Count; ++i)
            {
                if (keys[i].Mark <= relT)
                {
                    current = keys[i];
                    bool last = (i + 1) >= keys.Count;

                    if (!last && keys[i + 1].Mark >= relT)
                    {
                        nextFound = true;
                        next      = keys[i + 1];
                        break;
                    }
                }
            }
            if (!nextFound)
            {
                return(current.Val);
            }

            float localTime = (relT - current.Mark) / (next.Mark - current.Mark);

            if (current.Type == EAnimType.Linear)
            {
                return(InterpolateLinear(current.Val, next.Val, localTime));
            }
            else
            {
                Debug.LogError("..not yet implemented..");
            }

            return(Vector3.one);
        }