Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
稼働中のアニメーションコントローラーにAnimationClipPlayableを混ぜる
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
[RequireComponent(typeof(Animator))]
public class BlendAnimationController2Playable : MonoBehaviour
{
private PlayableGraph graph, animControlGraph;
private AnimationPlayableOutput output;
[SerializeField] AnimationClip clip = null;
void Awake()
{
// AnimationControllerのPlayableGraphは既に稼働しているので、新しく作る
graph = PlayableGraph.Create ();
// アニメーション再生の出力先を登録
var animator = GetComponent<Animator> ();
output = AnimationPlayableOutput.Create (graph, name, animator);
output.SetSourcePlayable (AnimationClipPlayable.Create (graph, clip));
// AnimationController側の操作用にキャッシュしとく
animControlGraph = animator.playableGraph;
}
void OnDestroy()
{
// PlayableGraphは必ず破棄する
graph.Destroy ();
}
public void SetWeight(float value)
{
// AnimationControllerがフルに動いてる時はPlayableGraphは停止させる
if (value == 0) {
graph.Stop ();
} else if( graph.IsPlaying() == false){
graph.Play ();
}
// Playable Graphがフルに動いてる時はAnimationControllerは停止させる
if (value == 1) {
animControlGraph.Stop ();
} else if (animControlGraph.IsPlaying () == false) {
animControlGraph.Play ();
}
// PlayableGraphのブレンド率
output.SetWeight (value);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.