Skip to content

Instantly share code, notes, and snippets.

@tsubaki
Created March 13, 2017 14:29
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tsubaki/92415cd3368734315f0a900c30e334d4 to your computer and use it in GitHub Desktop.
Save tsubaki/92415cd3368734315f0a900c30e334d4 to your computer and use it in GitHub Desktop.
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