Ejemplo n.º 1
0
        public override void Stop()
        {
            base.Stop();

            if (_snapshot != null)
            {
                _snapshot.Restore();
            }
        }
Ejemplo n.º 2
0
 protected override void OnStop()
 {
     base.OnStop();
     if (!HasData())
     {
         return;
     }
     _sequence.Stop();
     _targetSnapshot.Restore();
 }
Ejemplo n.º 3
0
 protected override void OnStop()
 {
     base.OnStop();
     if (_oldObj != null)
     {
         _oldObj.SetActive(true);
     }
     if (_newSnapshot != null)
     {
         _newSnapshot.Restore();
     }
 }
Ejemplo n.º 4
0
        public override void Stop()
        {
            base.Stop();

            if (HasCache && Cache.Track == this)
            {
                ((FAnimationTrackCache)Cache).StopPlayback();
                Owner.GetComponent <Animator>().enabled = false;
            }
            if (_snapshot != null)
            {
                _snapshot.Restore();
            }
        }
Ejemplo n.º 5
0
        protected override bool BuildInternal()
        {
            _tracksCached = GetAnimationTracks();
            _validFrameRanges.Clear();

            if (_tracksCached.Count == 0 || Animator == null || Animator.runtimeAnimatorController == null)
            {
                return(false);
            }

            // build preview
#if FLUX_DEBUG
            Debug.LogWarning("Creating Preview");
#endif

            TransformSnapshot transformSnapshot = new TransformSnapshot(Track.Owner);

            FSequence sequence = Track.Sequence;

            if (_tracksCached[0].Snapshot != null)
            {
                _tracksCached[0].Snapshot.Restore();
            }

            //			_snapshot = Application.isPlaying ? null : new GameObjectSnapshot( Track.Owner.gameObject );

            bool ownerIsActive = Track.Owner.gameObject.activeSelf;

            float speed = sequence.Speed;
            if (speed != 1)
            {
                sequence.Speed = 1f;
            }

            Animator.speed = 1f;

            int  currentFrame = sequence.CurrentFrame;
            bool isPlaying    = sequence.IsPlaying;

            if (!sequence.IsStopped)
            {
                sequence.Stop();
            }

            if (!sequence.IsInit)
            {
                sequence.Init();
            }

            if (!ownerIsActive)
            {
                HideFlags hideFlags = Track.Owner.gameObject.hideFlags;
                Track.Owner.gameObject.hideFlags |= HideFlags.DontSave;
                Track.Owner.gameObject.SetActive(true);
                Track.Owner.gameObject.hideFlags = hideFlags;
            }

            FrameRange currentFrameRange = new FrameRange();

            foreach (FAnimationTrack animTrack in _tracksCached)
            {
                animTrack.Cache = null;
                animTrack.Stop(); // we need to force stop them to clear the currentEvent index
            }

            // set culling to get around Unity bug of recording at the start
            AnimatorCullingMode animatorCullingMode = Animator.cullingMode;
            Animator.cullingMode = AnimatorCullingMode.AlwaysAnimate;

            Animator.enabled = true;

            for (int i = 0; i != Animator.layerCount; ++i)
            {
                Animator.SetLayerWeight(i, 0f);
            }

            Animator.StartRecording(-1);

            bool success = Animator.recorderMode == AnimatorRecorderMode.Record;

            if (success)
            {
                Animator.enabled = false;

                float delta = 1f / sequence.FrameRate;
                int   frame = 0;

                while (frame <= sequence.Length)
                {
                    bool wasEnabled = Animator.enabled;

                    foreach (FTrack track in _tracksCached)
                    {
                        track.UpdateEvents(frame, frame * delta);
                    }

                    if (wasEnabled)
                    {
                        currentFrameRange.End += 1;
                        if (Animator.enabled)
                        {
                            Animator.Update(delta);
                        }
                        else
                        {
                            Animator.enabled = true;
                            Animator.Update(delta);
                            Animator.enabled = false;
                            _validFrameRanges.Add(currentFrameRange);
                        }
                    }
                    else if (Animator.enabled)
                    {
                        Animator.Update(0);
                        currentFrameRange = new FrameRange(frame, frame);
                    }

                    ++frame;
                }

                foreach (FAnimationTrack animTrack in _tracksCached)
                {
                    animTrack.Cache = this;
                }

                Track = _tracksCached[0];

                Animator.StopRecording();
            }

            if (!ownerIsActive)
            {
                HideFlags hideFlags = Track.Owner.gameObject.hideFlags;
                Track.Owner.gameObject.hideFlags |= HideFlags.DontSave;
                Track.Owner.gameObject.SetActive(false);
                Track.Owner.gameObject.hideFlags = hideFlags;
            }

            if (speed != 1)
            {
                sequence.Speed = speed;
            }

            Animator.cullingMode = animatorCullingMode;

            sequence.Stop(true);

            if (currentFrame >= 0)
            {
                if (isPlaying)
                {
                    sequence.Play(currentFrame);
                }
                else
                {
                    sequence.SetCurrentFrame(currentFrame);
                }

                transformSnapshot.Restore();
            }

            return(success);
        }
Ejemplo n.º 6
0
 protected override void OnStop()
 {
     _snapshot.Restore();
 }