wip : subtitles & flash hallu
This commit is contained in:
@@ -0,0 +1,57 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
using OctoFramework = OctoCore.OctoCore;
|
||||
using Unheimlich.UI;
|
||||
|
||||
namespace Unheimlich.Features.Dialogue
|
||||
{
|
||||
/// <summary>
|
||||
/// 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.
|
||||
/// </summary>
|
||||
[RequireComponent(typeof(OctoLocalizedText))]
|
||||
[RequireComponent(typeof(PerLetterFontShifter))]
|
||||
public class LocalizedSubtitle : MonoBehaviour
|
||||
{
|
||||
private OctoLocalizedText _localizedText;
|
||||
private PerLetterFontShifter _shifter;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
_localizedText = GetComponent<OctoLocalizedText>();
|
||||
_shifter = GetComponent<PerLetterFontShifter>();
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Pulls the current localized string and pushes it to the shifter.
|
||||
/// </summary>
|
||||
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<TMPro.TextMeshProUGUI>().text;
|
||||
|
||||
_shifter.SetText(resolved);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user