Beispiel #1
0
 protected override void OnTrigger(float timeSinceTrigger)
 {
     if (Sequence.IsPlaying && Application.isPlaying)
     {
         _sequence.Play(_startOffset * _sequence.InverseFrameRate + timeSinceTrigger);
     }
 }
 protected override void OnTrigger(int framesSinceTrigger, float timeSinceTrigger)
 {
     if (Sequence.IsPlaying && Application.isPlaying)
     {
         _sequence.Play(_startOffset + framesSinceTrigger);
     }
 }
Beispiel #3
0
        protected override void OnUpdateEvent(float timeSinceTrigger)
        {
            base.OnUpdateEvent(timeSinceTrigger);

            if (!HasData())
            {
                return;
            }

            if (CheckHit(_zone) && Sequence.IsPlaying)
            {
                _sequence.Play(_sequence.InverseFrameRate + timeSinceTrigger);
            }
        }
        protected override bool BuildInternal()
        {
            _tracksCached = GetAnimationTracks();

            _validFrameRanges.Clear();

            if (_tracksCached.Count == 0)
            {
                return(false);
            }

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

            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;

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

            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();
            }

            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
            }

//			RuntimeAnimatorController controller = Animator.runtimeAnimatorController;
//			Animator.runtimeAnimatorController = null;
//			Animator.runtimeAnimatorController = controller;

            // 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 (FAnimationTrack animTrack in _tracksCached)
                    {
                        animTrack.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();

                sequence.Stop(true);

                if (_snapshot != null)
                {
                    _snapshot.Restore();
                }
            }

            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;

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

            return(success);
        }