Exemplo n.º 1
0
        /// <summary>
        /// Cache the initial state of the curve clip manipulated values.
        /// </summary>
        /// <returns>The Info necessary to revert this event.</returns>
        public RevertInfo[] CacheState()
        {
#if PROFILE_FILE
            Profiler.BeginSample("CinemaActorClipCurve.CacheState");
#endif // PROFILE_FILE
            List <RevertInfo> reverts = new List <RevertInfo>();
            if (Actor != null)
            {
                var list   = CurveData;
                var length = list.Count;
                for (var i = 0; i < length; i++)
                {
                    var memberData = list[i];

                    var component = GetActorComponent(memberData.Type);

                    if (component != null)
                    {
                        RevertInfo info = new RevertInfo(this, component,
                                                         memberData.PropertyName, memberData.getCurrentValue(component));

                        reverts.Add(info);
                    }
                }
            }
#if PROFILE_FILE
            Profiler.EndSample();
#endif // PROFILE_FILE
            return(reverts.ToArray());
        }
Exemplo n.º 2
0
 /// <summary>
 /// Cache the Actor Transform.
 /// </summary>
 /// <returns>The revert info for the Actor's transform.</returns>
 public RevertInfo[] CacheState()
 {
     RevertInfo[] reverts = new RevertInfo[3];
     if (Actor == null)
     {
         return(new RevertInfo[0]);
     }
     reverts[0] = new RevertInfo(this, Actor.transform, "localPosition", Actor.transform.localPosition);
     reverts[1] = new RevertInfo(this, Actor.transform, "localRotation", Actor.transform.localRotation);
     reverts[2] = new RevertInfo(this, Actor.transform, "localScale", Actor.transform.localScale);
     return(reverts);
 }
Exemplo n.º 3
0
 /// <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();
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// Cache the initial state of the curve clip manipulated values.
        /// </summary>
        /// <returns>The Info necessary to revert this event.</returns>
        public RevertInfo[] CacheState()
        {
            List <RevertInfo> reverts = new List <RevertInfo>();

            if (Actor != null)
            {
                foreach (MemberClipCurveData memberData in CurveData)
                {
                    Component component = Actor.GetComponent(memberData.Type);
                    if (component != null)
                    {
                        RevertInfo info = new RevertInfo(this, component,
                                                         memberData.PropertyName, memberData.getCurrentValue(component));

                        reverts.Add(info);
                    }
                }
            }
            return(reverts.ToArray());
        }
        /// <summary>
        /// Cache the initial state of the curve clip manipulated values.
        /// </summary>
        /// <returns>The Info necessary to revert this event.</returns>
        public RevertInfo[] CacheState()
        {
            List <RevertInfo> reverts = new List <RevertInfo>();

            if (Actor != null)
            {
                for (int i = 0; i < CurveData.Count; i++)
                {
                    Component component = Actor.GetComponent(CurveData[i].Type);
                    if (component != null)
                    {
                        RevertInfo info = new RevertInfo(this, component,
                                                         CurveData[i].PropertyName, CurveData[i].getCurrentValue(component));

                        reverts.Add(info);
                    }
                }
            }
            return(reverts.ToArray());
        }
Exemplo n.º 6
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
        }
Exemplo n.º 7
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
        }
Exemplo n.º 8
0
        /// <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();
        }
Exemplo n.º 9
0
        /// <summary>
        /// Cache the initial state of the curve clip manipulated values.
        /// </summary>
        /// <returns>The Info necessary to revert this event.</returns>
        public List <RevertInfo> CacheState()
        {
            List <RevertInfo> reverts = new List <RevertInfo>();

            GameObject actor = GetActor();

            if (actor != null)
            {
                for (int i = 0; i < CurveData.Count; i++)
                {
                    RevertInfo info = null;
                    switch (CurveData[i]._CurveDataType)
                    {
                    case CurveDataType.Transform:
                        Transform trans = actor.GetComponent <Transform>();
                        if (!trans)
                        {
                            continue;
                        }
                        switch (CurveData[i]._CurveDataPropertyName)
                        {
                        case CurveDataPropertyName.Position:
                            info = new RevertInfo(this, trans, trans.localPosition, RevertType.Transform, RevertValueType.LocalPosition);
                            break;

                        case CurveDataPropertyName.Rotation:
                            info = new RevertInfo(this, trans, trans.localEulerAngles, RevertType.Transform, RevertValueType.LocalEulerAngles);
                            break;

                        case CurveDataPropertyName.Scale:
                            info = new RevertInfo(this, trans, trans.localScale, RevertType.Transform, RevertValueType.Scale);
                            break;
                        }
                        break;

                    case CurveDataType.Camera:
                        Camera cam = actor.GetComponent <Camera>();
                        if (!cam)
                        {
                            continue;
                        }
                        switch (CurveData[i]._CurveDataPropertyName)
                        {
                        case CurveDataPropertyName.Fov:
                            info = new RevertInfo(this, cam, cam.fieldOfView, RevertType.Camera, RevertValueType.Fov);
                            break;

                        case CurveDataPropertyName.Near:
                            info = new RevertInfo(this, cam, cam.nearClipPlane, RevertType.Camera, RevertValueType.Near);
                            break;

                        case CurveDataPropertyName.Far:
                            info = new RevertInfo(this, cam, cam.farClipPlane, RevertType.Camera, RevertValueType.Far);
                            break;
                        }
                        break;
                    }
                    if (info != null)
                    {
                        reverts.Add(info);
                    }
                }
            }

            return(reverts);
        }