public override void ResampleAnimation()
        {
            if (state.disabled)
            {
                return;
            }

            if (previewing == false)
            {
                return;
            }
            if (canPreview == false)
            {
                return;
            }

            if (state.activeAnimationClip != null)
            {
                AnimationMode.BeginSampling();

                Undo.FlushUndoRecordObjects();

                AnimationMode.SampleAnimationClip(state.activeRootGameObject, state.activeAnimationClip, time.time);
                if (m_CandidateClip != null)
                {
                    AnimationMode.SampleCandidateClip(state.activeRootGameObject, m_CandidateClip, 0f);
                }

                AnimationMode.EndSampling();

                SceneView.RepaintAll();
                InspectorWindow.RepaintAllInspectors();

                // Particle editor needs to be manually repainted to refresh the animated properties
                var particleSystemWindow = ParticleSystemWindow.GetInstance();
                if (particleSystemWindow)
                {
                    particleSystemWindow.Repaint();
                }
            }
        }
 public override void ResampleAnimation()
 {
     if (!this.state.disabled)
     {
         if (this.previewing)
         {
             if (this.canPreview)
             {
                 bool flag = false;
                 AnimationMode.BeginSampling();
                 AnimationWindowSelectionItem[] array = this.state.selection.ToArray();
                 for (int i = 0; i < array.Length; i++)
                 {
                     AnimationWindowSelectionItem animationWindowSelectionItem = array[i];
                     if (animationWindowSelectionItem.animationClip != null)
                     {
                         Undo.FlushUndoRecordObjects();
                         AnimationMode.SampleAnimationClip(animationWindowSelectionItem.rootGameObject, animationWindowSelectionItem.animationClip, this.time.time - animationWindowSelectionItem.timeOffset);
                         if (this.m_CandidateClip != null)
                         {
                             AnimationMode.SampleCandidateClip(animationWindowSelectionItem.rootGameObject, this.m_CandidateClip, 0f);
                         }
                         flag = true;
                     }
                 }
                 AnimationMode.EndSampling();
                 if (flag)
                 {
                     SceneView.RepaintAll();
                     InspectorWindow.RepaintAllInspectors();
                     ParticleSystemWindow instance = ParticleSystemWindow.GetInstance();
                     if (instance)
                     {
                         instance.Repaint();
                     }
                 }
             }
         }
     }
 }
Esempio n. 3
0
        private void ResampleAnimation(ResampleFlags flags)
        {
            if (state.disabled)
            {
                return;
            }

            if (previewing == false)
            {
                return;
            }
            if (canPreview == false)
            {
                return;
            }

            s_ResampleAnimationMarker.Begin();
            if (state.activeAnimationClip != null)
            {
                var  animationPlayer  = state.activeAnimationPlayer;
                bool usePlayableGraph = animationPlayer is Animator;

                if (usePlayableGraph)
                {
                    var isValidGraph = m_Graph.IsValid();
                    if (isValidGraph)
                    {
                        var playableOutput = (AnimationPlayableOutput)m_Graph.GetOutput(0);
                        isValidGraph = playableOutput.GetTarget() == (Animator)animationPlayer;
                    }

                    if (HasFlag(flags, ResampleFlags.RebuildGraph) || !isValidGraph)
                    {
                        RebuildGraph((Animator)animationPlayer);
                    }
                }

                AnimationMode.BeginSampling();

                if (HasFlag(flags, ResampleFlags.FlushUndos))
                {
                    Undo.FlushUndoRecordObjects();
                }

                if (usePlayableGraph)
                {
                    if (m_UsesPostProcessComponents)
                    {
                        IAnimationWindowPreview[] previewComponents = FetchPostProcessComponents();
                        if (previewComponents != null)
                        {
                            foreach (var component in previewComponents)
                            {
                                component.UpdatePreviewGraph(m_Graph);
                            }
                        }
                    }

                    if (!m_CandidateClip.empty)
                    {
                        AnimationMode.AddCandidates(state.activeRootGameObject, m_CandidateClip);
                    }

                    m_ClipPlayable.SetSampleRate(playing ? -1 : state.activeAnimationClip.frameRate);

                    AnimationMode.SamplePlayableGraph(m_Graph, 0, time.time);

                    // This will cover euler/quaternion matching in basic playable graphs only (animation clip + candidate clip).
                    AnimationUtility.SampleEulerHint(state.activeRootGameObject, state.activeAnimationClip, time.time, WrapMode.Clamp);
                    if (!m_CandidateClip.empty)
                    {
                        AnimationUtility.SampleEulerHint(state.activeRootGameObject, m_CandidateClip, time.time, WrapMode.Clamp);
                    }
                }
                else
                {
                    AnimationMode.SampleAnimationClip(state.activeRootGameObject, state.activeAnimationClip, time.time);
                    if (!m_CandidateClip.empty)
                    {
                        AnimationMode.SampleCandidateClip(state.activeRootGameObject, m_CandidateClip, 0f);
                    }
                }

                AnimationMode.EndSampling();

                if (HasFlag(flags, ResampleFlags.RefreshViews))
                {
                    SceneView.RepaintAll();
                    InspectorWindow.RepaintAllInspectors();

                    // Particle editor needs to be manually repainted to refresh the animated properties
                    var particleSystemWindow = ParticleSystemWindow.GetInstance();
                    if (particleSystemWindow)
                    {
                        particleSystemWindow.Repaint();
                    }
                }
            }
            s_ResampleAnimationMarker.End();
        }