Playable

struct in UnityEngine.Playables


Implements interfaces:IPlayable

Switch to Manual

Description

Playable 是可自定义的运行时对象,此类对象可连接在一起并包含在 PlayableGraph 中以创建复杂的行为。

Playable 可用于创建复杂且灵活的数据评估树。Playable 是可连接在一起的节点,连接后,每一个 Playable 都可以设置其子项的“权重”或“影响”。

The playables of the same graph are contained in a PlayableGraph. A PlayableGraph can have several outputs, also called "players", which implement IPlayableOutput. The PlayableOutput takes the result of their source playable and apply it to an object in the Scene. For instance, the AnimationPlayableOutput is linked to a playable node in the graph (the "source playable") and to an Animator in the Scene. When the graph is played, the animation pose resulting of the graph evaluation is applied by the Animator. There are as many PlayableOutputs as there are different playable types: AnimationPlayableOutput, AudioPlayableOutput, TexturePlayableOutput, ScriptPlayableOutput, etc...

ScriptPlayable<T> 是一种特殊的可播放项。其主要角色为一个“自定义”可播放项。它是一个模板化结构,其中 T 必须由 PlayableBehaviour 派生。借助这些自定义 PlayableBehaviour,您可以在特定时间在图评估中写入行为(请参阅 PlayableBehaviour.PrepareFrame 以及 PlayableBehaviour.ProcessFrame)。ScriptPlayable 的一个典型例子是控制 Timeline 图的 TimelinePlayable。ScriptPlayable 会创建负责轨道和剪辑的可播放项并将其链接在一起。

播放 PlayableGraph 时,会遍历每个 PlayableOutput。遍历期间,它将在每个 Playable 上调用 PrepareFrame 方法。这允许 Playable“为下一评估做好准备”。在 PrepareFrame 阶段期间,每个 Playable 都可修改其子项(通过添加新的输入或是移除部分输入)。这样,Playable 可在运行时在 Playable 树中“生成”新的子树枝。这意味着 Playable 树不是静态结构。它们可以随时间进行调整和改变。

一旦准备完毕,PlayableOutput 会负责处理结果,这也是将其称为“玩家”的原因。如果使用 AnimationPlayableOutputAnimator 会负责处理图;如果使用 ScriptPlayableOutput,将在每个 ScriptPlayable 上调用 PlayableBehaviour.ProcessFrame

注意:您可以在实现 IPlayable 的任何结构上使用 PlayableExtensions 方法。

注意:在手册中,详细介绍了 Playables API

Static Variables

Null返回无效的 Playable。