Forums › 💬 Slate Sequencer › ⚙️ Support › Overwriting Captions › Reply To: Overwriting Captions
Hello,
To override the GUI, you need to subscribe to the various events that are available in the DirectorGUI class. Each event corresponds to a different GUI functionality, thus in your case, you would want to subscribe to the OnSubtitlesGUI
event.
Once you have subscribed to that event, the default subtitles GUI implementation will completely be bypassed and instead be forwarded for you to implement through the event raised.
Here is a rather very simple example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
using UnityEngine; using Slate; public class CustomGUIExample : MonoBehaviour { void OnEnable(){ DirectorGUI.OnSubtitlesGUI += OnSubtitlesGUI; } void OnDisable(){ DirectorGUI.OnSubtitlesGUI -= OnSubtitlesGUI; } private string subsText; private Color subsColor; void OnSubtitlesGUI(string text, Color color){ //store data to show OnGUI this.subsText = text; this.subsColor = color; } void OnGUI(){ if (!string.IsNullOrEmpty(subsText)){ var style = new GUIStyle("textfield"); var size = style.CalcSize(new GUIContent(subsText)); var rect = new Rect(0, 0, size.x, size.y); rect.center = new Vector2( Screen.width/2, Screen.height - size.y - 5 ); GUI.color = subsColor; GUI.Label(rect, subsText); GUI.color = Color.white; } } } |
You can attach this script in the “Director Camera Root” gameobject. In runtime (and runtime only since OnEnable and OnDisable are called in runtime), your implementation will be called, while in editor time the default implementation will be called.
But, if the only thing you want to change is the subtitles size, this might be an overkill. If that is the case, please just open up DirectorGUI.cs and change the SUBS_SIZE field from being private const
, to public
thus possible to change in inspector. I will keep this change in future version so that the subtitles size can be changed from inspector as well.
Let me know.
Thanks!