using UnityEngine;
using iHuman.UnitySz.Framework;
using TMPro;

#if UNITY_EDITOR
using UnityEditor;
#endif
[ExecuteAlways]
public class LabaController : MonoBehaviour
{
    public int Type = 1;

    public string KeyWord = "";    

    public bool IsLong = false;

    public TMP_FontAsset fontAsset;

    public GameObject laba;

    private void Awake()
    {
       
    }
    void Start()
    {
        UpdateLaba();
    }

    void DoAdapt()
    {
        UpdateLaba();
    }
    
    public void UpdateLaba()
    {
        var img_yuyin_bg1 = gameObject.Seek("img_yuyin_bg1");
        var img_yuyin_bg2 = gameObject.Seek("img_yuyin_bg2");
        var text_1 = img_yuyin_bg1.Seek("text").GetComponent<TextMeshPro>();
        var text_2 = img_yuyin_bg2.Seek("text").GetComponent<TextMeshPro>();
        img_yuyin_bg1.SetActive(Type == 1);
        img_yuyin_bg2.SetActive(Type == 2);
        if(KeyWord == null || KeyWord == "")
        {
            KeyWord = text_1.text == "" ? text_2.text: text_1.text;
        }
        text_1.text = KeyWord;
        text_2.text = KeyWord;
        if(fontAsset!=null)
        {
            text_1.font = fontAsset;
            text_2.font = fontAsset;
        }
        laba = Type == 1 ? img_yuyin_bg1 :img_yuyin_bg2;
    }
}
