FM/Assets/Scripts/Base/Keyboard/FontsChange.cs

29 lines
869 B
C#
Raw Normal View History

2025-06-04 22:49:37 +08:00
using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
2025-07-14 19:29:10 +08:00
using UnityEngine.Serialization;
2025-06-04 22:49:37 +08:00
using UnityEngine.UI;
namespace HK.Keyboard
{
public class FontsChange : MonoBehaviour
{
[SerializeField] List<TMP_FontAsset> fonts = new List<TMP_FontAsset>();
2025-06-04 22:49:37 +08:00
public GameObject item;
public Keyboard keyboard;
private void Awake()
{
keyboard = GetComponentInParent<Keyboard>();
foreach (var tmpAsset in fonts)
{
var o = GameObject.Instantiate(item, item.transform.parent);
o.SetActive(true);
o.name = tmpAsset.name;
o.GetComponentInChildren<TMP_Text>().font = tmpAsset;
o.GetComponent<Button>().onClick.AddListener(() => { keyboard.SetFont(tmpAsset); });
}
}
}
}