fix: LocalizedSubtitle
This commit is contained in:
@@ -1,57 +1,62 @@
|
||||
using UnityEngine;
|
||||
using OctoCore.Localization;
|
||||
using OctoFramework = OctoCore.OctoCore;
|
||||
using System;
|
||||
using Unheimlich.UI;
|
||||
using UnityEngine;
|
||||
using OctoFramework = OctoCore.OctoCore;
|
||||
using OctoCore.Localization;
|
||||
|
||||
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;
|
||||
[SerializeField] private OctoLocalizedTextData _data;
|
||||
|
||||
private OctoLocalizedText _localizedText; // A retirer
|
||||
private PerLetterFontShifter _shifter;
|
||||
private Action localize;
|
||||
|
||||
private void Awake()
|
||||
void Awake()
|
||||
{
|
||||
_localizedText = GetComponent<OctoLocalizedText>();
|
||||
_localizedText = GetComponent<OctoLocalizedText>(); // A retirer
|
||||
_shifter = GetComponent<PerLetterFontShifter>();
|
||||
|
||||
if (!OctoFramework.Instance)
|
||||
{
|
||||
Debug.LogWarning($"OctoCore.Instance not found");
|
||||
return;
|
||||
}
|
||||
|
||||
Localize();
|
||||
OctoFramework.Instance.Localization.SubscribeOnLanguageWrittenChange(localize = Localize);
|
||||
}
|
||||
|
||||
private void Start()
|
||||
void OnDestroy()
|
||||
{
|
||||
// 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();
|
||||
if (!OctoFramework.Instance) return;
|
||||
|
||||
// Re-hook on language change so the shifter stays in sync.
|
||||
if (OctoFramework.Instance)
|
||||
OctoFramework.Instance.Localization.SubscribeOnLanguageWrittenChange(Refresh);
|
||||
if (localize != null)
|
||||
{
|
||||
OctoFramework.Instance.Localization.UnsubscribeOnLanguageWrittenChange(localize);
|
||||
localize = null;
|
||||
}
|
||||
}
|
||||
|
||||
private void OnDestroy()
|
||||
private void Localize()
|
||||
{
|
||||
if (OctoFramework.Instance)
|
||||
OctoFramework.Instance.Localization.UnsubscribeOnLanguageWrittenChange(Refresh);
|
||||
}
|
||||
string localized = "Not localized";
|
||||
|
||||
/// <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();
|
||||
if (_data)
|
||||
{
|
||||
localized = OctoLocalization.GetLocalizedText(_data);
|
||||
}
|
||||
else // A retirer
|
||||
{ // A retirer
|
||||
_localizedText.Localize(); // A retirer
|
||||
localized = GetComponent<TMPro.TextMeshProUGUI>().text; // A retirer
|
||||
} // A retirer
|
||||
|
||||
// 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);
|
||||
_shifter.SetText(localized);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user