Files
Ipseity-Demo/Assets/_Content/Scripts/Features/Dialogue/Runtime/LocalizedSubtitle.cs
T

62 lines
2.0 KiB
C#

using System;
using Unheimlich.UI;
using UnityEngine;
using OctoFramework = OctoCore.OctoCore;
using OctoCore.Localization;
namespace Unheimlich.Features.Dialogue
{
[RequireComponent(typeof(PerLetterFontShifter))]
public class LocalizedSubtitle : MonoBehaviour
{
[SerializeField] private OctoLocalizedTextData _data;
private OctoLocalizedText _localizedText; // A retirer
private PerLetterFontShifter _shifter;
private Action localize;
void Awake()
{
_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);
}
void OnDestroy()
{
if (!OctoFramework.Instance) return;
if (localize != null)
{
OctoFramework.Instance.Localization.UnsubscribeOnLanguageWrittenChange(localize);
localize = null;
}
}
private void Localize()
{
string localized = "Not localized";
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).
_shifter.SetText(localized);
}
}
}