Esempio n. 1
0
        ///----------------------------------------------------------------------------------------------

        //The root motion must be baked if required.
        void BakeRootMotion()
        {
            masterMixer.Pause(); //pause while baking
            useBakedRootMotion       = false;
            animator.applyRootMotion = true;
            rmPositions = new List <Vector3>();
            rmRotations = new List <Quaternion>();
            var tempActiveClips = 0;
            var updateInterval  = (1f / ROOTMOTION_FRAMERATE);

            for (var time = startTime - updateInterval; time <= endTime + updateInterval; time += updateInterval)
            {
                EvaluateTrackClips(time, time - updateInterval, ref tempActiveClips);

                if (tempActiveClips > 0)
                {
                    graph.Evaluate(updateInterval);
                }

                rmPositions.Add(animator.transform.localPosition);
                rmRotations.Add(animator.transform.localRotation);
            }
            animator.applyRootMotion = false;
            useBakedRootMotion       = true;
            masterMixer.Play(); //resume play. if keep paused, prevents from AnimationEvents from firing
        }