Slate Forums › Support › Overwriting Captions › Reply To: Overwriting Captions
Hello,
Just to clarify what is going on, when you override the default GUI, like we do here, nothing from the default GUI (aka DirectorGUI) is executed or used by default, since we completely override it and as such, we need to tell our GUI exactly how to display the information.
Thus, the solution to that, is to also add a “Font” variable to our CustomGUIExample.cs script and change the script to use the supplied font:
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 36 37 38 39 40 41 42 43 44 45 46 47 48 |
using UnityEngine; using Slate; [ExecuteInEditMode] public class CustomGUIExample : MonoBehaviour { public Color subsColor = Color.white; public int size = 14; public Font font; public int yOffsetFromBottom = 5; private string subsText; private float colorAlpha; void OnEnable(){ DirectorGUI.OnSubtitlesGUI += OnSubtitlesGUI; } void OnDisable(){ DirectorGUI.OnSubtitlesGUI -= OnSubtitlesGUI; } void OnSubtitlesGUI(string text, Color color){ colorAlpha = color.a; if (colorAlpha < 0.1f){ subsText = null; return; } subsText = string.Format("<size={0}>{1}</size>", size, text); } void OnGUI(){ if (!string.IsNullOrEmpty(subsText)){ var style = new GUIStyle("label"); style.font = font; 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 - yOffsetFromBottom ); var clr = subsColor; clr.a = colorAlpha; GUI.color = clr; GUI.Label(rect, subsText, style); GUI.color = Color.white; } } } |
There will now be a “font” variable in the inspector of the above script.
Regarding the “(Clone)” naming issue, thanks for letting me know.
To fix this quickly, please open up PlayAudio.cs file and change line #96 to be like this:
DirectorGUI.UpdateSubtitles(string.Format("{0}{1}", parent is ActorAudioTrack? (actor.name.Replace("(Clone)", "") + ": ") : "", subtitlesText), lerpColor);
Let me know if the above work for you.
Thanks.
Join us on Discord: https://discord.gg/97q2Rjh