Created
January 28, 2025 00:06
-
-
Save baobao/f2aab1f76915b2ad7ecf9aa9275af780 to your computer and use it in GitHub Desktop.
https://shibuya24.info/entry/unity-playable-start で使用しているPlayable APIサンプル
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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