StationObscurum/Assets/Packages/Heat - Complete Modern UI/Scripts/Credits/CreditsMentionItem.cs
2024-02-01 22:45:59 -05:00

66 lines
2.0 KiB
C#

using UnityEngine;
using UnityEngine.UI;
using TMPro;
namespace Michsky.UI.Heat
{
public class CreditsMentionItem : MonoBehaviour
{
[Header("Resources")]
[SerializeField] private Image iconImage;
[SerializeField] private TextMeshProUGUI descriptionText;
public VerticalLayoutGroup listLayout;
// Helpers
[HideInInspector] public CreditsPreset preset;
[HideInInspector] public LocalizedObject localizedObject;
void OnEnable()
{
if (localizedObject != null && !string.IsNullOrEmpty(localizedObject.localizationKey))
{
SetDescription(localizedObject.GetKeyOutput(localizedObject.localizationKey));
}
}
public void UpdateLayout(int paddingValue, int spacingValue)
{
listLayout.padding.top = paddingValue / 2;
listLayout.padding.bottom = paddingValue / 2;
listLayout.spacing = spacingValue;
}
public void SetIcon(Sprite icon)
{
if (icon == null)
{
iconImage.gameObject.SetActive(false);
return;
}
iconImage.sprite = icon;
}
public void SetDescription(string text)
{
if (string.IsNullOrEmpty(text))
{
descriptionText.gameObject.SetActive(false);
return;
}
descriptionText.text = text;
}
public void CheckForLocalization(string key)
{
localizedObject = descriptionText.GetComponent<LocalizedObject>();
if (localizedObject == null || (LocalizationManager.instance != null && !LocalizationManager.instance.UIManagerAsset.enableLocalization)) { localizedObject = null; }
else if (!string.IsNullOrEmpty(key))
{
localizedObject.localizationKey = key;
SetDescription(localizedObject.GetKeyOutput(localizedObject.localizationKey));
}
}
}
}