Created
July 29, 2017 13:57
-
-
Save tsubaki/2887c4c22a0fbba52aeade032b007dd8 to your computer and use it in GitHub Desktop.
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 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 (); | |
} | |
} |
Author
tsubaki
commented
Jul 29, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment