/// <summary>
 /// Revert all data that has been manipulated by the Cutscene.
 /// </summary>
 private void revert()
 {
     for (int i = 0; i < revertCache.Count; i++)
     {
         RevertInfo revertable = revertCache[i];
         if (revertable != null)
         {
             if ((revertable.EditorRevert == RevertMode.Revert && !Application.isPlaying) ||
                 (revertable.RuntimeRevert == RevertMode.Revert && Application.isPlaying))
             {
                 revertable.Revert();
             }
         }
     }
 }
Beispiel #2
0
        /// <summary>
        /// Revert all data that has been manipulated by the Cutscene.
        /// </summary>
        private void revert()
        {
#if PROFILE_FILE
            Profiler.BeginSample("Cutscene.revert");
#endif // PROFILE_FILE
            for (var i = 0; i < revertCache.Count; ++i)
            {
                RevertInfo revertable = revertCache[i];
                if (revertable != null)
                {
                    if ((revertable.EditorRevert == RevertMode.Revert && !Application.isPlaying) ||
                        (revertable.RuntimeRevert == RevertMode.Revert && Application.isPlaying))
                    {
                        revertable.Revert();
                    }
                }
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
        }
Beispiel #3
0
        /// <summary>
        /// Bake the Mecanim preview data.
        /// </summary>
        public void Bake()
        {
#if PROFILE_FILE
            Profiler.BeginSample("CharacterTrackGroup.Bake");
#endif // PROFILE_FILE
            if (Actor == null || Application.isPlaying)
            {
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return;
            }
            Animator animator = Actor.GetComponent <Animator>();
            if (animator == null)
            {
#if PROFILE_FILE
                Profiler.EndSample();
#endif // PROFILE_FILE
                return;
            }

            List <RevertInfo> revertCache = new List <RevertInfo>();

            // Build the cache of revert info.
            var comps = this.GetComponentsInChildren <MonoBehaviour>();
            for (var i = 0; i < comps.Length; ++i)
            {
                MonoBehaviour mb         = comps[i];
                IRevertable   revertable = mb as IRevertable;
                if (revertable != null)
                {
                    revertCache.AddRange(revertable.CacheState());
                }
            }

            Vector3    position = Actor.transform.localPosition;
            Quaternion rotation = Actor.transform.localRotation;
            Vector3    scale    = Actor.transform.localScale;

            float frameRate  = 30;
            int   frameCount = (int)((Cutscene.Duration * frameRate) + 2);
            animator.StopPlayback();
            animator.recorderStartTime = 0;
            animator.StartRecording(frameCount);

            base.SetRunningTime(0);

            for (int i = 0; i < frameCount - 1; i++)
            {
                var tracks = GetTracks();
                for (int j = 0; j < tracks.Length; ++j)
                {
                    TimelineTrack track = tracks[j];
                    if (!(track is DialogueTrack))
                    {
                        track.UpdateTrack(i * (1.0f / frameRate), (1.0f / frameRate));
                    }
                }
                animator.Update(1.0f / frameRate);
            }
            animator.recorderStopTime = frameCount * (1.0f / frameRate);
            animator.StopRecording();
            animator.StartPlayback();

            hasBeenBaked = true;

            // Return the Actor to his initial position.
            Actor.transform.localPosition = position;
            Actor.transform.localRotation = rotation;
            Actor.transform.localScale    = scale;

            for (int i = 0; i < revertCache.Count; ++i)
            {
                RevertInfo revertable = revertCache[i];
                if (revertable != null)
                {
                    if ((revertable.EditorRevert == RevertMode.Revert && !Application.isPlaying) ||
                        (revertable.RuntimeRevert == RevertMode.Revert && Application.isPlaying))
                    {
                        revertable.Revert();
                    }
                }
            }

            base.Initialize();
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
        }
        /// <summary>
        /// Bake the Mecanim preview data.
        /// </summary>
        public void Bake()
        {
            if (Actor == null || Application.isPlaying)
            {
                return;
            }
            Animator animator = Actor.GetComponent <Animator>();

            if (animator == null)
            {
                return;
            }

            AnimatorCullingMode cullingData = animator.cullingMode;

            animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

            List <RevertInfo> revertCache = new List <RevertInfo>();

            // Build the cache of revert info.
            MonoBehaviour[] mb = this.GetComponentsInChildren <MonoBehaviour>();
            for (int i = 0; i < mb.Length; i++)
            {
                IRevertable revertable = mb[i] as IRevertable;
                if (revertable != null)
                {
                    revertCache.AddRange(revertable.CacheState());
                }
            }

            Vector3    position = Actor.transform.localPosition;
            Quaternion rotation = Actor.transform.localRotation;
            Vector3    scale    = Actor.transform.localScale;

            Cutscene cutScene   = GetCutScene();
            float    frameRate  = 30;
            int      frameCount = (int)((cutScene.Duration * frameRate) + 2);

            animator.StopPlayback();
            animator.recorderStartTime = 0;
            animator.StartRecording(frameCount);

            base.SetRunningTime(0);

            for (int i = 0; i < frameCount - 1; i++)
            {
                List <TimelineTrack> tracks = GetTracks();
                for (int j = 0; j < tracks.Count; j++)
                {
                    tracks[j].UpdateTrack(i * (1.0f / frameRate), (1.0f / frameRate));
                }
                animator.Update(1.0f / frameRate);
            }
            animator.recorderStopTime = frameCount * (1.0f / frameRate);
            animator.StopRecording();
            animator.StartPlayback();

            hasBeenBaked = true;

            // Return the Actor to his initial position.
            Actor.transform.localPosition = position;
            Actor.transform.localRotation = rotation;
            Actor.transform.localScale    = scale;

            for (int i = 0; i < revertCache.Count; i++)
            {
                RevertInfo revertable = revertCache[i];
                if (revertable != null)
                {
                    if ((revertable.EditorRevert == RevertMode.Revert && !Application.isPlaying) ||
                        (revertable.RuntimeRevert == RevertMode.Revert && Application.isPlaying))
                    {
                        revertable.Revert();
                    }
                }
            }
            animator.cullingMode = cullingData;
            base.Initialize();
        }