T FindTrack<T>(PlayableGraph graph) where T : TrackAsset
{
var director = (graph.GetResolver() as PlayableDirector);
foreach (var binding in director.playableAsset.outputs)
{
if (binding.sourceObject is T track)
{
return track;
}
}
return null;
}
[TrackColor(1f, 0f, 0f)]
public class XxxxTrack : TrackAsset
{
public override Playable CreateTrackMixer(PlayableGraph graph, GameObject go, int inputCount)
{
var scriptPlayable = ScriptPlayable<XxxxMixer>.Create(graph, inputCount);
var mixer = scriptPlayable.GetBehaviour();
foreach (var clip in GetClips())
{
var asset = clip.asset as XxxxxPlayableAsset;
mixer.yy = asset.zz;
}
return scriptPlayable;
}
}
https://github.com/UnityTechnologies/ATerribleKingdom
PlayableAsset CreateTimeline(AnimationClip[] clips)
{
var tl = ScriptableObject.CreateInstance<TimelineAsset>();
var track = tl.CreateTrack<AnimationTrack>("Animation");
float total = 0f;
for (int i = 0; i < clips.Length; i++)
{
var clip = clips[i];
float start = total;
float duration = clip.length;
var clip = track.CreateClip<AnimationPlayableAsset>();
(clip.asset as AnimationPlayableAsset).clip = clip;
clip.start = start;
clip.duration = duration;
total += duration;
}
return tl;
}
var tl = ScriptableObject.CreateInstance<TimelineAsset>();
AssetDatabase.CreateAsset(tl, "test.playable"));
AssetDatabase.SaveAssets();
// need SaveAssets before CreateTrack, or AddObjectToAsset manually
var track = tl.CreateTrack<AnimationTrack>();
EditorUtility.SetDirty(tl);
ProjectWindowUtil.ShowCreatedAsset(tl);
TimelineEditor.Refresh(RefreshReason.ContentsAddedOrRemoved);
https://forum.unity.com/threads/set-timelineclip-pre-post-extrapolationmode-from-script.475679/
playable.GetGraph().GetRootPlayable(0).SetSpeed(Xf);
public class Xxxx : PlayableBehaviour
{
public override void OnBehaviourPause(Playable playable, FrameData info)
{
info.output.PushNotification(playable, new XxxxNotification();
}
}
private class NotificationReceiver : MonoBehaviour, INotificationReceiver
{
void INotificationReceiver.OnNotify(Playable origin, INotification notification, object context)
{
if (notification is XxxxNotification)
{
...
}
}
}
https://blog.unity.com/ja/technology/how-to-create-custom-timeline-markers https://tsubakit1.hateblo.jp/entry/2018/12/10/233146
public class XxxxTrack : TrackAsset
{
protected override Playable CreatePlayable(PlayableGraph graph, GameObject gameObject, TimelineClip clip)
{
if (clip.asset is XxxxPlayableAsset asset)
{
clip.displayName = "Xxxx";
}
return base.CreatePlayable(graph, gameObject, clip);
}
}
[CustomTimelineEditor(typeof(XxxxClip))]
public class XxxxClipEditor : ClipEditor
{
public override void OnClipChanged(TimelineClip clip)
{
var asset = clip.asset as XxxxPlayableAsset;
clip.displayName = asset.xxxx;
base.OnClipChanged(clip);
}
}