Skip to content

Instantly share code, notes, and snippets.

@baobao
Created January 28, 2025 00:06
Show Gist options
  • Save baobao/f2aab1f76915b2ad7ecf9aa9275af780 to your computer and use it in GitHub Desktop.
Save baobao/f2aab1f76915b2ad7ecf9aa9275af780 to your computer and use it in GitHub Desktop.
https://shibuya24.info/entry/unity-playable-start で使用しているPlayable APIサンプル
using UnityEngine;
using UnityEngine.Animations;
using UnityEngine.Playables;
public class SimplePlayable : MonoBehaviour
{
[SerializeField] private AnimationClip _clip;
[SerializeField] private Animator _animator;
private PlayableGraph _graph;
void Awake()
{
// 1.PlayableGraphの作成
_graph = PlayableGraph.Create("TestGraph");
// 2.Playable(インプット)の作成
var playable = AnimationClipPlayable.Create(_graph, _clip);
// 3.PlayableOutput(アウトプット)の作成
var output = AnimationPlayableOutput.Create(_graph, "AnimationOutput", _animator);
// 4.PlayableOutputにPlayableを接続
output.SetSourcePlayable(playable);
// 5.PlayableGraphを通して再生
_graph.Play();
}
void OnDestroy()
{
// 6.使い終わったらPlayableGraphを破棄
_graph.Destroy();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment