Beispiel #1
0
        // update cache (optimized)
        public override void updateCache()
        {
            // destroy cache
            destroyCache(); //undo handled inside
            // create new cache
            _clearCache();  //undo handled inside
            // sort keys
            sortKeys();     //undo handled inside

            for (int i = 0; i < keys.Count; i++)
            {
                AMAnimatorAction a = ScriptableObject.CreateInstance <AMAnimatorAction>();
                a.startFrame = keys[i].frame;
                //if (keys.Count > (i + 1))
                //    a.endFrame = keys[i + 1].frame;
                //else
                //    a.endFrame = -1;

                AMAnimatorKey k = (AMAnimatorKey)keys[i];
                a.obj = obj;
                a.CopyKeyInfos(k.infos);

                a.easeType   = (keys[i] as AMAnimatorKey).easeType;
                a.customEase = new List <float>(keys[i].customEase);
                // add to cache
                cache.Add(a);
            }
        }
Beispiel #2
0
        // preview a frame in the scene view
        // 1. revert all layer's cur-state to normalizedTime = 0
        // 2. re-evaluate all parameters setting from head to specified frame
        public void previewFrame(float frame, float frameRate, AMTrack extraTrack = null)
        {
            if (!obj)
            {
                return;
            }
            if (cache.Count == 0)
            {
                return;
            }

            // 1. revert
            var ator = this.animator;

            ator.Rebind(); //revert back to default states + default parameters
            ator.Update(0);

            // 2. re-evaluate
            float prevFrame = 0;

            for (int i = 0; i <= cache.Count - 1; ++i)
            {
                AMAnimatorAction action = cache[i] as AMAnimatorAction;
                if (action.startFrame > frame)
                { //update from prevFrame to frame, over
                    float time = (frame - prevFrame) / frameRate;
                    prevFrame = frame;
                    ator.Update(time);
                    break;
                }
                else if (action.startFrame <= frame)
                { //update from prevFrame to startFrame, keep on
                    float time = (action.startFrame - prevFrame) / frameRate;
                    prevFrame = action.startFrame;
                    ator.Update(time);

                    // apply the action's modification to ator
                    for (int iidx = 0; iidx < action.m_infos.Count; ++iidx)
                    {
                        var oneInfo = action.m_infos[iidx];
                        oneInfo.Apply(ator, true);
                    }

                    // check same
                    if (Mathf.Approximately(action.startFrame, frame))
                    {
                        break;
                    }
                }
            }

            if (frame > prevFrame)
            {
                float time = (frame - prevFrame) / frameRate;
                prevFrame = frame;
                ator.Update(time);
            }
        }