-
-
Save InitoryDad/6b4e24e889725f7fb81efcde3de58377 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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