114 lines
2.6 KiB
C#
114 lines
2.6 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
namespace Michsky.UI.Heat
|
|
{
|
|
public class SettingsDescriptionManager : MonoBehaviour
|
|
{
|
|
[Header("Default Content")]
|
|
[SerializeField]
|
|
private Sprite cover;
|
|
|
|
[SerializeField]
|
|
private string title = "Settings";
|
|
|
|
[SerializeField]
|
|
[TextArea]
|
|
private string description = "Description area.";
|
|
|
|
[Header("Localization")]
|
|
public string tableID = "UI";
|
|
|
|
[SerializeField]
|
|
private string titleKey;
|
|
|
|
[SerializeField]
|
|
private string descriptionKey;
|
|
|
|
[Header("Resources")]
|
|
[SerializeField]
|
|
private Image coverImage;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI titleObject;
|
|
|
|
[SerializeField]
|
|
private TextMeshProUGUI descriptionObject;
|
|
|
|
[Header("Settings")]
|
|
public bool useLocalization = true;
|
|
|
|
[HideInInspector]
|
|
public LocalizedObject localizedObject;
|
|
|
|
private void Awake()
|
|
{
|
|
if (useLocalization && !string.IsNullOrEmpty(titleKey) && !string.IsNullOrEmpty(descriptionKey))
|
|
{
|
|
CheckForLocalization();
|
|
}
|
|
}
|
|
|
|
private void OnEnable()
|
|
{
|
|
SetDefault();
|
|
}
|
|
|
|
private void CheckForLocalization()
|
|
{
|
|
localizedObject = base.gameObject.GetComponent<LocalizedObject>();
|
|
if (localizedObject == null)
|
|
{
|
|
localizedObject = base.gameObject.AddComponent<LocalizedObject>();
|
|
localizedObject.objectType = LocalizedObject.ObjectType.ComponentDriven;
|
|
localizedObject.updateMode = LocalizedObject.UpdateMode.OnDemand;
|
|
localizedObject.InitializeItem();
|
|
LocalizationSettings localizationSettings = LocalizationManager.instance.UIManagerAsset.localizationSettings;
|
|
foreach (LocalizationSettings.Table table in localizationSettings.tables)
|
|
{
|
|
if (tableID == table.tableID)
|
|
{
|
|
localizedObject.tableIndex = localizationSettings.tables.IndexOf(table);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
if (localizedObject.tableIndex == -1 || LocalizationManager.instance == null || !LocalizationManager.instance.UIManagerAsset.enableLocalization)
|
|
{
|
|
localizedObject = null;
|
|
useLocalization = false;
|
|
}
|
|
}
|
|
|
|
public void UpdateUI(string newTitle, string newDescription, Sprite newCover)
|
|
{
|
|
if (newCover != null)
|
|
{
|
|
coverImage.sprite = newCover;
|
|
}
|
|
else
|
|
{
|
|
coverImage.sprite = cover;
|
|
}
|
|
titleObject.text = newTitle;
|
|
descriptionObject.text = newDescription;
|
|
}
|
|
|
|
public void SetDefault()
|
|
{
|
|
if (localizedObject == null)
|
|
{
|
|
titleObject.text = title;
|
|
descriptionObject.text = description;
|
|
}
|
|
else
|
|
{
|
|
titleObject.text = localizedObject.GetKeyOutput(titleKey);
|
|
descriptionObject.text = localizedObject.GetKeyOutput(descriptionKey);
|
|
}
|
|
coverImage.sprite = cover;
|
|
}
|
|
}
|
|
}
|