Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created July 30, 2017 04:08
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tsubaki/91d4cfebd199fdbc8700bbae1c2edf4e to your computer and use it in GitHub Desktop.
Save tsubaki/91d4cfebd199fdbc8700bbae1c2edf4e to your computer and use it in GitHub Desktop.
PlayableOutputのターゲットを切り替えるサンプル
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Animations;
public class ChangeTargetAnimator : MonoBehaviour
{
PlayableGraph graph;
AnimationPlayableOutput output;
AnimationClipPlayable clipPlayable;
[SerializeField] Animator[] animators;
[SerializeField] AnimationClip clip;
void Awake()
{
graph = PlayableGraph.Create ();
}
void Start()
{
clipPlayable = AnimationClipPlayable.Create (graph, clip);
output = AnimationPlayableOutput.Create (graph, "animation", null);
output.SetSourcePlayable (clipPlayable);
graph.Play ();
}
void OnGUI()
{
foreach( var anim in animators){
if (GUILayout.Button (anim.name)) {
output.SetTarget (anim);
clipPlayable.SetTime (0);
}
}
}
void OnDestroy()
{
graph.Destroy ();
}
}
@tsubaki
Copy link
Author

tsubaki commented Jul 30, 2017

animation 105

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