81 lines
1.5 KiB
C#
81 lines
1.5 KiB
C#
using TMPro;
|
|
using UnityEngine;
|
|
|
|
namespace Michsky.UI.Heat
|
|
{
|
|
[AddComponentMenu("Heat UI/UI Manager/UI Manager Font Changer")]
|
|
public class UIManagerFontChanger : MonoBehaviour
|
|
{
|
|
[Header("Resources")]
|
|
public UIManager targetUIManager;
|
|
|
|
[Header("Fonts")]
|
|
public TMP_FontAsset lightFont;
|
|
|
|
public TMP_FontAsset regularFont;
|
|
|
|
public TMP_FontAsset mediumFont;
|
|
|
|
public TMP_FontAsset semiboldFont;
|
|
|
|
public TMP_FontAsset boldFont;
|
|
|
|
public TMP_FontAsset customFont;
|
|
|
|
[Header("Settings")]
|
|
[SerializeField]
|
|
private bool applyOnStart;
|
|
|
|
private void Start()
|
|
{
|
|
if (applyOnStart)
|
|
{
|
|
ApplyFonts();
|
|
}
|
|
}
|
|
|
|
public void ApplyFonts()
|
|
{
|
|
if (targetUIManager == null)
|
|
{
|
|
Debug.LogError("Cannot apply the changes due to missing 'Target UI Manager'.", this);
|
|
return;
|
|
}
|
|
if (lightFont != null)
|
|
{
|
|
targetUIManager.fontLight = lightFont;
|
|
}
|
|
if (regularFont != null)
|
|
{
|
|
targetUIManager.fontRegular = regularFont;
|
|
}
|
|
if (mediumFont != null)
|
|
{
|
|
targetUIManager.fontMedium = mediumFont;
|
|
}
|
|
if (semiboldFont != null)
|
|
{
|
|
targetUIManager.fontSemiBold = semiboldFont;
|
|
}
|
|
if (boldFont != null)
|
|
{
|
|
targetUIManager.fontBold = boldFont;
|
|
}
|
|
if (customFont != null)
|
|
{
|
|
targetUIManager.customFont = customFont;
|
|
}
|
|
if (!targetUIManager.enableDynamicUpdate)
|
|
{
|
|
targetUIManager.enableDynamicUpdate = true;
|
|
Invoke("DisableDynamicUpdate", 1f);
|
|
}
|
|
}
|
|
|
|
private void DisableDynamicUpdate()
|
|
{
|
|
targetUIManager.enableDynamicUpdate = false;
|
|
}
|
|
}
|
|
}
|