using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using RotaryHeart.Lib.SerializableDictionary; using Newtonsoft.Json; using System.Linq; namespace BITKit { public class UnityTranslator : MonoBehaviour, ITranslator { public string langs = "zh-cns"; public SerializableDictionaryBase dictionary = new(); public event Action OnChangeLanguage; public event Func OnCollageAllSourceText; public string Translate(string rawString) { if (dictionary.TryGetValue(langs, out var so)) { return so.Get(rawString, false); } return rawString; } public void Set(string value) { if (dictionary.ContainsKey(value)) { langs = value; BIT4Log.Log($"已设置语言为:{value}"); OnChangeLanguage?.Invoke(value); } } void Awake() { DI.Register(this); //GameObject.DontDestroyOnLoad(gameObject); } public string[] GetAllSourceText() { var value = OnCollageAllSourceText.GetInvocationList() .SelectMany(x => x.Method.Invoke(x.Target, null) as string[]) .ToArray(); return value; } public void LogAllSourceText() { BITAppForUnity.ThrowIfNotPlaying(); var json = JsonConvert.SerializeObject(GetAllSourceText(),Formatting.Indented); Debug.Log(json); } } }