Version: 2020.3
public static Animations.AnimationScriptPlayable Create (Playables.PlayableGraph graph, T jobData, int inputCount);

参数

graph 将拥有 AnimationScriptPlayable 的 PlayableGraph 对象。
job 在处理可播放项时执行的 IAnimationJob
inputCount 可播放项上的输入数。

返回

AnimationScriptPlayable 链接到 PlayableGraph 的新 AnimationScriptPlayable

描述

PlayableGraph 中创建 AnimationScriptPlayable

此可播放项包含一个实现 IAnimationJob 的作业。此接口定义了在处理 PlayableGraph 时将调用的两个方法。

以下是一个如何使用简单 IAnimationJob 创建 AnimationScriptPlayable 的示例:

using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;

public struct AnimationJob : IAnimationJob { public int userData;

public void ProcessRootMotion(AnimationStream stream) { // This method is called during the root motion process pass. }

public void ProcessAnimation(AnimationStream stream) { // This method is called during the animation process pass. Debug.Log(string.Format("Value of the userData: {0}", userData)); } }

[RequireComponent(typeof(Animator))] public class AnimationScriptExample : MonoBehaviour { PlayableGraph m_Graph; AnimationScriptPlayable m_AnimationScriptPlayable;

void OnEnable() { m_Graph = PlayableGraph.Create("AnimationScriptExample"); var output = AnimationPlayableOutput.Create(m_Graph, "ouput", GetComponent<Animator>());

var animationJob = new AnimationJob(); m_AnimationScriptPlayable = AnimationScriptPlayable.Create(m_Graph, animationJob);

output.SetSourcePlayable(m_AnimationScriptPlayable); m_Graph.Play(); }

void Update() { var animationJob = m_AnimationScriptPlayable.GetJobData<AnimationJob>(); ++animationJob.userData; m_AnimationScriptPlayable.SetJobData(animationJob); }

void OnDisable() { m_Graph.Destroy(); } }

另请参阅:IAnimationJobAnimatorJobExtensions