90 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
		
		
			
		
	
	
			90 lines
		
	
	
		
			2.1 KiB
		
	
	
	
		
			C#
		
	
	
	
|  | using System; | |||
|  | using System.Collections; | |||
|  | using System.Collections.Generic; | |||
|  | using UnityEngine; | |||
|  | 
 | |||
|  | [CreateAssetMenu(menuName = "LanguageConfig")] | |||
|  | public class LanguageConfig : ConfigBase<LanguageConfig> | |||
|  | { | |||
|  |     public bool IsDebug = false; | |||
|  |     [SerializeField] LanguageType DebugLang = LanguageType.Chinese; | |||
|  |     [SerializeField] LanguageType DefaultLang = LanguageType.English; | |||
|  | 
 | |||
|  |     [SerializeField] List<LanguageItem> Items; | |||
|  | 
 | |||
|  |     public LanguageType LangType | |||
|  |     { | |||
|  |         get | |||
|  |         { | |||
|  |             if (IsDebug) | |||
|  |             { | |||
|  |                 return DebugLang; | |||
|  |             } | |||
|  | 
 | |||
|  |             LanguageType tLangType = DefaultLang; | |||
|  |             if (Application.systemLanguage == SystemLanguage.Chinese || Application.systemLanguage == SystemLanguage.ChineseSimplified || Application.systemLanguage == SystemLanguage.ChineseTraditional) | |||
|  |             { | |||
|  |                 tLangType = LanguageType.Chinese; | |||
|  |             } | |||
|  |             else if (Application.systemLanguage == SystemLanguage.Japanese) | |||
|  |             { | |||
|  |                 tLangType = LanguageType.Japanese; | |||
|  |             } | |||
|  | 
 | |||
|  |             return tLangType; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     public string GetText(string pKey) | |||
|  |     { | |||
|  |         LanguageItem tItem = Items.Find((pItem) => pItem.Key.Equals(pKey)); | |||
|  | 
 | |||
|  |         if (tItem != null) | |||
|  |         { | |||
|  |             return tItem.GetString(LangType); | |||
|  |         } | |||
|  | 
 | |||
|  |         return pKey; | |||
|  |     } | |||
|  | 
 | |||
|  |     [Serializable] | |||
|  |     class LanguageItem | |||
|  |     { | |||
|  |         public string Key; | |||
|  |         public LangString[] LangStrs; | |||
|  | 
 | |||
|  |         public string GetString(LanguageType pLangType) | |||
|  |         { | |||
|  |             for (int i = 0; i < LangStrs.Length; i++) | |||
|  |             { | |||
|  |                 if (LangStrs[i].LangType == pLangType) | |||
|  |                     return LangStrs[i].LString; | |||
|  |             } | |||
|  | 
 | |||
|  |             return Key; | |||
|  |         } | |||
|  |     } | |||
|  | 
 | |||
|  |     [Serializable] | |||
|  |     public class LangString | |||
|  |     { | |||
|  |         public LanguageType LangType; | |||
|  |         public string LString; | |||
|  |     } | |||
|  | 
 | |||
|  |     [Serializable] | |||
|  |     public class LangSprite | |||
|  |     { | |||
|  |         public LanguageType LangType; | |||
|  |         public Sprite LSprite; | |||
|  |     } | |||
|  | 
 | |||
|  |     public enum LanguageType | |||
|  |     { | |||
|  |         Chinese = 0, | |||
|  |         English, | |||
|  |         Japanese | |||
|  |     } | |||
|  | } | |||
|  | 
 |