private void RebuildGraph(Animator animator) { DestroyGraph(); m_Graph = PlayableGraph.Create("PreviewGraph"); m_Graph.SetTimeUpdateMode(DirectorUpdateMode.Manual); m_ClipPlayable = AnimationClipPlayable.Create(m_Graph, state.activeAnimationClip); m_ClipPlayable.SetOverrideLoopTime(true); m_ClipPlayable.SetLoopTime(false); m_ClipPlayable.SetApplyFootIK(false); m_CandidateClipPlayable = AnimationClipPlayable.Create(m_Graph, m_CandidateClip); m_CandidateClipPlayable.SetApplyFootIK(false); IAnimationWindowPreview[] previewComponents = FetchPostProcessComponents(); bool requiresDefaultPose = previewComponents != null && previewComponents.Length > 0; int nInputs = requiresDefaultPose ? 3 : 2; // Create a layer mixer if necessary, we'll connect playable nodes to it after having populated AnimationStream. AnimationLayerMixerPlayable mixer = AnimationLayerMixerPlayable.Create(m_Graph, nInputs); m_GraphRoot = (Playable)mixer; // Populate custom playable preview graph. if (previewComponents != null) { foreach (var component in previewComponents) { m_GraphRoot = component.BuildPreviewGraph(m_Graph, m_GraphRoot); } } // Finish hooking up mixer. int inputIndex = 0; if (requiresDefaultPose) { AnimationMode.RevertPropertyModificationsForGameObject(state.activeRootGameObject); EditorCurveBinding[] streamBindings = AnimationUtility.GetAnimationStreamBindings(state.activeRootGameObject); m_DefaultPose = new AnimationClip() { name = "DefaultPose" }; AnimationWindowUtility.CreateDefaultCurves(state, m_DefaultPose, streamBindings); m_DefaultPosePlayable = AnimationClipPlayable.Create(m_Graph, m_DefaultPose); m_DefaultPosePlayable.SetApplyFootIK(false); mixer.ConnectInput(inputIndex++, m_DefaultPosePlayable, 0, 1.0f); } mixer.ConnectInput(inputIndex++, m_ClipPlayable, 0, 1.0f); mixer.ConnectInput(inputIndex++, m_CandidateClipPlayable, 0, 1.0f); if (animator.applyRootMotion) { var motionX = AnimationMotionXToDeltaPlayable.Create(m_Graph); motionX.SetAbsoluteMotion(true); motionX.SetInputWeight(0, 1.0f); m_Graph.Connect(m_GraphRoot, 0, motionX, 0); m_GraphRoot = (Playable)motionX; } var output = AnimationPlayableOutput.Create(m_Graph, "ouput", animator); output.SetSourcePlayable(m_GraphRoot); output.SetWeight(0.0f); }