TimeLine
效果
配置
Playables
脚本播放动画
public class AnimationScript : MonoBehaviour
{
public AnimationClip clip01;
public AnimationClip clip02;
private PlayableGraph _graph;
private void OnGUI()
{
if (GUILayout.Button("Animation 01"))
AnimationPlayableUtilities.PlayClip(GetComponent<Animator>(), clip01, out _graph);
if (GUILayout.Button("Animation 02"))
AnimationPlayableUtilities.PlayClip(GetComponent<Animator>(), clip02, out _graph);
}
private void OnDisable()
{
_graph.Destroy();
}
}
混合动画音频
public class AnimationScript : MonoBehaviour
{
public AnimationClip clip01;
public AnimationClip clip02;
private PlayableGraph _graph;
private AnimationMixerPlayable _animationMixerPlayable;
public float weight;
private void Start()
{
_animationMixerPlayable = AnimationPlayableUtilities.PlayMixer(GetComponent<Animator>(), 2, out _graph);
AnimationClipPlayable clipPlayable01 = AnimationClipPlayable.Create(_graph, clip01);
AnimationClipPlayable clipPlayable02 = AnimationClipPlayable.Create(_graph, clip02);
_graph.Connect(clipPlayable01, 0, _animationMixerPlayable, 0);
_graph.Connect(clipPlayable02, 0, _animationMixerPlayable, 1);
}
private void Update()
{
weight = Mathf.Clamp01(weight);
_animationMixerPlayable.SetInputWeight(0, 1.0f - weight);
_animationMixerPlayable.SetInputWeight(1, weight);
}
private void OnGUI()
{
GUILayout.Label("混合动画权重");
weight = GUILayout.HorizontalSlider(weight, 0.0f, 1.0f);
}
private void OnDisable()
{
_graph.Destroy();
}
}
public class AudioScript : MonoBehaviour
{
public AudioClip clip01;
public AudioClip clip02;
private PlayableGraph _graph;
private AudioMixerPlayable _audioMixerPlayable;
public float weight;
private void Start()
{
_graph = PlayableGraph.Create();
_audioMixerPlayable = AudioMixerPlayable.Create(_graph, 2);
AudioClipPlayable clipPlayable01 = AudioClipPlayable.Create(_graph, clip01, true);
AudioClipPlayable clipPlayable02 = AudioClipPlayable.Create(_graph, clip02, true);
_graph.Connect(clipPlayable01, 0, _audioMixerPlayable, 0);
_graph.Connect(clipPlayable02, 0, _audioMixerPlayable, 1);
AudioPlayableOutput audioPlayableOutput = AudioPlayableOutput.Create(_graph, "Audio", GetComponent<AudioSource>());
audioPlayableOutput.SetSourcePlayable(_audioMixerPlayable);
_graph.Play();
}
private void Update()
{
weight = Mathf.Clamp01(weight);
_audioMixerPlayable.SetInputWeight(0, 1.0f - weight);
_audioMixerPlayable.SetInputWeight(1, weight);
}
private void OnGUI()
{
GUILayout.Label("混合音频权重");
weight = GUILayout.HorizontalSlider(weight, 0.0f, 1.0f);
}
private void OnDisable()
{
_graph.Destroy();
}
}