protected override bool BuildInternal() { FSequence sequence = Track.Sequence; FParticleTrack particleTrack = (FParticleTrack)Track; float currentTime = sequence.CurrentTime; if (currentTime >= 0) { sequence.Stop(); } _particles.Clear(); for (int frame = 0, numFrames = sequence.Length + 1; frame != numFrames; ++frame) { particleTrack.UpdateEvents(frame, frame * particleTrack.Sequence.InverseFrameRate); ParticleSystem.Particle[] particleBuffer = new ParticleSystem.Particle[particleTrack.ParticleSystem.main.maxParticles]; KeyValuePair <int, ParticleSystem.Particle[]> entry = new KeyValuePair <int, ParticleSystem.Particle[]>(particleTrack.ParticleSystem.GetParticles(particleBuffer), particleBuffer); _particles.Add(entry); } sequence.Stop(); if (currentTime >= 0) { sequence.SetCurrentTime(currentTime); } return(true); }
//protected override void OnUpdateEvent(float timeSinceTrigger) //{ // if (HasSequence()) // _sequence.Speed = Mathf.Sign(Sequence.Speed) * Mathf.Abs(_sequence.Speed); //} // protected override void OnUpdateEvent( float timeSinceTrigger ) // { //// if( !Application.isPlaying ) //// _sequence.SetCurrentTime( StartOffset * Sequence.InverseFrameRate + timeSinceTrigger ); // } // // protected override void OnUpdateEventEditor( float timeSinceTrigger ) // { //// _sequence.SetCurrentTime( StartOffset * Sequence.InverseFrameRate + timeSinceTrigger ); //// _sequence.SetCurrentFrameEditor( _startOffset + framesSinceTrigger ); //// _sequence.SetCurrentFrame( _startOffset + framesSinceTrigger ); // } protected override void OnStop() { if (HasSequence()) { _sequence.Stop(true); } }
protected override void OnStop() { base.OnStop(); if (!HasData()) { return; } _sequence.Stop(); _targetSnapshot.Restore(); }
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); }
// protected override void OnUpdateEvent( float timeSinceTrigger ) // { //// if( !Application.isPlaying ) //// _sequence.SetCurrentTime( StartOffset * Sequence.InverseFrameRate + timeSinceTrigger ); // } // // protected override void OnUpdateEventEditor( float timeSinceTrigger ) // { //// _sequence.SetCurrentTime( StartOffset * Sequence.InverseFrameRate + timeSinceTrigger ); //// _sequence.SetCurrentFrameEditor( _startOffset + framesSinceTrigger ); //// _sequence.SetCurrentFrame( _startOffset + framesSinceTrigger ); // } protected override void OnStop() { _sequence.Stop(true); }
protected override void OnTrigger(float timeSinceTrigger) { _sequence.Stop(); }
protected override void OnTrigger(int framesSinceTrigger, float timeSinceTrigger) { _sequence.Stop(); }