ProjectDDD/Assets/_DDD/_Scripts/GameUi/TabUi.cs
2025-07-24 17:41:20 +09:00

54 lines
1.7 KiB
C#

using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
namespace DDD
{
public class TabUi : MonoBehaviour
{
[SerializeField]
private TabUiConfigSo _tabUiConfigSo;
[SerializeField]
private List<GameObject> _tabContents = new();
private Toggle _toggle;
private TextMeshProUGUI _text;
private LocalizeStringEvent _localizeStringEvent;
private const string TabContent = "TabContent";
private const string Text = "Text";
public void Initialize()
{
Debug.Assert(_tabUiConfigSo != null, "_tabUiConfigSo != null");
_toggle = GetComponent<Toggle>();
_text = transform.Find(Text).GetComponent<TextMeshProUGUI>();
_localizeStringEvent = _text.transform.GetComponent<LocalizeStringEvent>();
_toggle.onValueChanged.AddListener(TabContentsSetActive);
_text.text = null;
LocalizedString localizedString = LocalizationManager.Instance.GetLocalizedString(_tabUiConfigSo.DisplayNameKey);
_localizeStringEvent.SetTable(localizedString.TableReference);
_localizeStringEvent.SetEntry(localizedString.TableEntryReference);
_localizeStringEvent.OnUpdateString.RemoveAllListeners();
_localizeStringEvent.OnUpdateString.AddListener(value => _text.text = value);
}
public bool IsOn => _toggle.isOn;
public void TabContentsSetActive(bool isOn)
{
foreach (var tabContent in _tabContents)
{
tabContent.SetActive(isOn);
}
}
}
}