Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Last active May 5, 2018 03:36
Show Gist options
  • Save tsubaki/d9e867be84b6f71176a4cf451028e86b to your computer and use it in GitHub Desktop.
Save tsubaki/d9e867be84b6f71176a4cf451028e86b to your computer and use it in GitHub Desktop.
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Timeline;
using UnityEngine.Playables;
#if UNITY_EDITOR
using UnityEditor.Experimental.Animations;
// A behaviour that is attached to a playable
public class GORecorderPlayable : PlayableBehaviour
{
public AnimationClip clip;
public GameObject gameObject;
public bool isRecord;
private GameObjectRecorder m_Recorder;
public override void OnGraphStart(Playable playable)
{
if (isRecord == false || clip == null || gameObject == null)
return;
m_Recorder = new GameObjectRecorder(gameObject);
m_Recorder.BindComponentsOfType<Transform>(gameObject, true);
}
public override void OnGraphStop(Playable playable)
{
if (m_Recorder == null || isRecord == false || clip == null || gameObject == null)
return;
m_Recorder.SaveToClip(clip);
m_Recorder.ResetRecording();
}
public override void PrepareFrame(Playable playable, FrameData info) {
if (m_Recorder == null || isRecord == false || clip == null || gameObject == null)
return;
m_Recorder.TakeSnapshot(info.deltaTime);
}
}
#endif
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
#if UNITY_EDITOR
[System.Serializable]
public class GORecorderAsset : PlayableAsset
{
public ExposedReference<GameObject> obj;
public AnimationClip clip;
public bool isRecord = false;
public override Playable CreatePlayable(PlayableGraph graph, GameObject go) {
var playable = ScriptPlayable<GORecorderPlayable>.Create(graph);
var gorecorder = playable.GetBehaviour();
gorecorder.gameObject = obj.Resolve(graph.GetResolver());
gorecorder.clip = clip;
gorecorder.isRecord = gorecorder.gameObject != null && clip != null && isRecord;
return playable;
}
}
#endif
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment