包含此页的版本:
不含此页的版本:
此示例演示了PlayableGraph一个可播放输出链接到一个可播放节点。可播放节点播放单个动画剪辑(clip).在可播放节点可以使用动画剪辑之前,必须将剪辑包装在AnimationClipPlayable.
要使用PlayAnimationClip脚本,则项目必须具有以下内容:
RequireComponent属性 添加此组件(如果不存在)。要使用PlayAnimationClipscript,请按照以下步骤作:
将脚本组件添加到游戏对象。为脚本文件命名PlayAnimationClip.cs并使用以下代码:
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
[RequireComponent(typeof(Animator))]
public class PlayAnimationClip : MonoBehaviour
{
public AnimationClip clip;
PlayableGraph graph;
void Start()
{
graph = PlayableGraph.Create("PlayAnimationClip");
graph.SetTimeUpdateMode(DirectorUpdateMode.GameTime);
var output = AnimationPlayableOutput.Create(graph, "Animation", GetComponent<Animator>());
// Wrap the clip in a playable.
var clipPlayable = AnimationClipPlayable.Create(graph, clip);
// Connect the Playable to an output.
output.SetSourcePlayable(clipPlayable);
// Plays the Graph.
graph.Play();
}
void OnDisable()
{
// Destroys all Playables and PlayableOutputs created by the graph.
graph.Destroy();
}
}
在 Script 组件中,选择动画剪辑 (clip),PlayableGraph 将在运行时播放。
选择 运行(Play) 将编辑器切换到播放模式。
如果您已安装 PlayableGraph Visualizer 包,请选择PlayAnimationClip以显示 PlayableGraph:
PlayAnimationClip脚本