Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 29, 2017 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/2887c4c22a0fbba52aeade032b007dd8 to your computer and use it in GitHub Desktop.
Save tsubaki/2887c4c22a0fbba52aeade032b007dd8 to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
[RequireComponent(typeof(Animator))]
public class SimpleAnimation : MonoBehaviour {
PlayableGraph graph;
[SerializeField] string clipName = "RobotBoyRun";
void Awake()
{
graph = PlayableGraph.Create ();
}
void Start()
{
// アニメーションをResourcesから取得し
// AnimationClipPlayableを構築
var clip = Resources.Load<AnimationClip> (clipName);
var clipPlayable = AnimationClipPlayable.Create (graph, clip);
// outputを生成して、出力先を自身のAnimatorに設定
var output = AnimationPlayableOutput.Create (graph, "output", GetComponent<Animator>());
// playableをoutputに流し込む
output.SetSourcePlayable (clipPlayable);
graph.Play ();
}
void OnDestroy()
{
graph.Destroy ();
}
}
@tsubaki
Copy link
Author

tsubaki commented Jul 29, 2017

animation 96

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment