99 lines
3.1 KiB
C#
99 lines
3.1 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public class LanguageItem : MonoBehaviour
|
|
{
|
|
public TMP_Text Text;
|
|
|
|
public bool isSetText = false;
|
|
[ConditionalField("isSetText")] public string chin;
|
|
[ConditionalField("isSetText")] public string english;
|
|
[ConditionalField("isSetText")] public TMP_FontAsset ChinFontAsset;
|
|
[ConditionalField("isSetText")] public TMP_FontAsset EnglishFontAsset;
|
|
|
|
public bool isSetImage = false;
|
|
[ConditionalField("isSetImage")] public Image ChinImage;
|
|
[ConditionalField("isSetImage")] public Image EnglishImage;
|
|
|
|
public bool isSetGo = false;
|
|
[ConditionalField("isSetGo")] public GameObject ChinGo;
|
|
[ConditionalField("isSetGo")] public GameObject EnglishGo;
|
|
|
|
private LanguageManager.LanguageType currentType = LanguageManager.LanguageType.English;
|
|
|
|
private void Awake()
|
|
{
|
|
Text = GetComponentInParent<TMP_Text>();
|
|
}
|
|
|
|
private void Start()
|
|
{
|
|
LanguageManager.Instance.LanguageChange += LanguageChange;
|
|
LanguageChange(LanguageManager.Instance.type);
|
|
if (!LanguageManager.Instance.IsSimplified)
|
|
chin = LanguageManager.Instance.S2T(chin);
|
|
else
|
|
chin = LanguageManager.Instance.T2S(chin);
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
LanguageManager.Instance.LanguageChange -= LanguageChange;
|
|
}
|
|
|
|
private void LanguageChange(LanguageManager.LanguageType type)
|
|
{
|
|
if (currentType == type)
|
|
return;
|
|
currentType = type;
|
|
switch (type)
|
|
{
|
|
case LanguageManager.LanguageType.English:
|
|
if (isSetImage && ChinImage != null && EnglishImage != null)
|
|
{
|
|
ChinImage.gameObject.SetActive(false);
|
|
EnglishImage.gameObject.SetActive(true);
|
|
}
|
|
|
|
if (isSetText && Text != null)
|
|
{
|
|
Text.text = english;
|
|
Text.font = EnglishFontAsset;
|
|
}
|
|
|
|
if (isSetGo && ChinGo != null && EnglishGo != null)
|
|
{
|
|
ChinGo.gameObject.SetActive(false);
|
|
EnglishGo.gameObject.SetActive(true);
|
|
}
|
|
|
|
break;
|
|
case LanguageManager.LanguageType.Chinese:
|
|
if (isSetImage && ChinImage != null && EnglishImage != null)
|
|
{
|
|
ChinImage.gameObject.SetActive(true);
|
|
EnglishImage.gameObject.SetActive(false);
|
|
}
|
|
|
|
if (isSetText && Text != null)
|
|
{
|
|
Text.text = chin;
|
|
Text.font = ChinFontAsset;
|
|
}
|
|
|
|
if (isSetGo && ChinGo != null && EnglishGo != null)
|
|
{
|
|
ChinGo.gameObject.SetActive(true);
|
|
EnglishGo.gameObject.SetActive(false);
|
|
}
|
|
|
|
break;
|
|
default:
|
|
throw new ArgumentOutOfRangeException(nameof(type), type, null);
|
|
}
|
|
}
|
|
} |