Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.