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

28 lines
819 B
C#

using System;
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
namespace HK.Keyboard
{
public class FontsChange : MonoBehaviour
{
List<TMP_FontAsset> fonts = new List<TMP_FontAsset>();
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); });
}
}
}
}