/// <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; } List <RevertInfo> revertCache = new List <RevertInfo>(); // Build the cache of revert info. foreach (MonoBehaviour mb in this.GetComponentsInChildren <MonoBehaviour>()) { 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++) { foreach (TimelineTrack track in GetTracks()) { 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; foreach (RevertInfo revertable in revertCache) { if (revertable != null) { if ((revertable.EditorRevert == RevertMode.Revert && !Application.isPlaying) || (revertable.RuntimeRevert == RevertMode.Revert && Application.isPlaying)) { revertable.Revert(); } } } base.Initialize(); }
public IRevertable Revert(EditorSceneBase scene) { return(new DoubleRevertable(second.Revert(scene), first.Revert(scene))); }