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

51 lines
1.3 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 PerLetterFontShifter _shifter;
private Action _localize;
void Awake()
{
_shifter = GetComponent<PerLetterFontShifter>();
}
void Start()
{
if (!OctoFramework.Instance)
{
Debug.LogWarning("[LocalizedSubtitle] 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;
}
}
void Localize()
{
string localized = _data ? OctoLocalization.GetLocalizedText(_data) : string.Empty;
_shifter.SetText(localized);
}
}
}