包含此页的版本:
不含此页的版本:
此示例演示了如何创建PlayableGraph具有两种不同的可播放输出类型:一个AudioPlayableOutput和AnimationPlayableOutput.此示例还演示了如何播放AudioClip通过AudioClipPlayable连接到AudioPlayableOutput.
在使用DifferentOutputs脚本,则项目必须具有以下内容:
RequireComponent属性会添加这些组件(如果它们不存在)。要使用DifferentOutputsscript,请按照以下步骤作:
将脚本组件添加到游戏对象。为脚本文件命名DifferentOutputs.cs并使用以下代码:
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Audio;
using UnityEngine.Playables;
[RequireComponent(typeof(Animator))]
[RequireComponent(typeof(AudioSource))]
public class DifferentOutputs : MonoBehaviour
{
public AnimationClip animationClip;
public AudioClip audioClip;
PlayableGraph graph;
void Start()
{
// Create and name the graph.
graph = PlayableGraph.Create("DifferentOutputs");
// Create the outputs.
var animationOutput = AnimationPlayableOutput.Create(graph, "Animation", GetComponent<Animator>());
var audioOutput = AudioPlayableOutput.Create(graph, "Audio", GetComponent<AudioSource>());
// Create the playables.
var animationClipPlayable = AnimationClipPlayable.Create(graph, animationClip);
var audioClipPlayable = AudioClipPlayable.Create(graph, audioClip, true);
// Connect the playables to an output.
animationOutput.SetSourcePlayable(animationClipPlayable);
audioOutput.SetSourcePlayable(audioClipPlayable);
// Play the Graph.
graph.Play();
}
void OnDisable()
{
// Destroys all Playables and Outputs created by the graph.
graph.Destroy();
}
}
在 脚本(Script) 组件中,选择 PlayableGraph 将在运行时播放的 动画剪辑(Animation Clip) 和 音频剪辑(Audio Clip) 。
选择 运行(Play) 将编辑器切换到播放模式。
如果您已安装 PlayableGraph Visualizer 包,请选择MultiOutputSample以显示 PlayableGraph。
DifferentOutputs脚本。