using UnityEngine; using OctoCore.Localization; using OctoFramework = OctoCore.OctoCore; using Unheimlich.UI; namespace Unheimlich.Features.Dialogue { /// /// Bridges OctoLocalizedText and PerLetterFontShifter. /// OctoLocalizedText writes to the source TMP, which is disabled by the shifter — /// this component intercepts Localize() and forwards the result to SetText() instead. /// [RequireComponent(typeof(OctoLocalizedText))] [RequireComponent(typeof(PerLetterFontShifter))] public class LocalizedSubtitle : MonoBehaviour { private OctoLocalizedText _localizedText; private PerLetterFontShifter _shifter; private void Awake() { _localizedText = GetComponent(); _shifter = GetComponent(); } private void Start() { // OctoLocalizedText.Awake() has already run and called Localize() into the dead TMP. // Pull the resolved text back out and push it into the shifter. Refresh(); // Re-hook on language change so the shifter stays in sync. if (OctoFramework.Instance) OctoFramework.Instance.Localization.SubscribeOnLanguageWrittenChange(Refresh); } private void OnDestroy() { if (OctoFramework.Instance) OctoFramework.Instance.Localization.UnsubscribeOnLanguageWrittenChange(Refresh); } /// /// Pulls the current localized string and pushes it to the shifter. /// private void Refresh() { // Force OctoLocalizedText to re-resolve the string into the source TMP. _localizedText.Localize(); // Read it back from the source TMP (it's disabled but the .text field is still set). string resolved = GetComponent().text; _shifter.SetText(resolved); } } }