Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.Playables;
using UnityEngine.Timeline;
// The instance of the clip for a playing timeline
[System.Serializable]
public class SubtitlePlayable : ScriptPlayable
{
public UnityEngine.UI.Text ui;
public string message;
//public override void OnGraphStart() { }
//public override void OnGraphStop() { }
//public override void PrepareFrame(FrameData info) { }
public override void OnPlayStateChanged(FrameData info, PlayState newState) {
if (ui == null)
return;
ui.enabled = handle.playState == PlayState.Playing;
if (newState == PlayState.Playing) {
ui.text = message;
}
}
}
// The representation of the Timeline Clip
[System.Serializable]
public class SubtitlePlayableAsset : PlayableAsset
{
public ExposedReference<UnityEngine.UI.Text> ui;
public string message;
// Create the runtime version of the clip, by creating a copy of the template
public override PlayableHandle CreatePlayable(PlayableGraph graph, GameObject go)
{
var handle = graph.CreateScriptPlayable<SubtitlePlayable> ();
handle.GetObject<SubtitlePlayable>().ui = ui.Resolve(graph.resolver);
handle.GetObject<SubtitlePlayable> ().message = message;
return handle;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment