gdl_123 2 месяцев назад
Родитель
Сommit
0077b2692a

+ 1 - 0
Assets/Src/Core/Config/LocalizedTextureCfgMgr.cs

@@ -128,6 +128,7 @@ public class LocalizedTextureCfgMgr : Singleton<LocalizedTextureCfgMgr>
             curLanguageKey = language;
             ReadConfig();
             ConfigMgr.CurLangKey = language;
+            EventMgr.DispatchEvent(new CoreEvent<int>(ECoreEventType.EID_LANGUAGE_CHANGE, 1));
         }
     }
 

+ 1 - 1
Assets/Src/Core/Event/ECoreEventType.cs

@@ -31,7 +31,7 @@ public sealed class ECoreEventType
     public const int EID_UI_SHOW = 34;
     public const int EID_GameServer_ConnectSuccess = 35;
     public const int EID_LOAD_LUA_OK = 36;
-
+    public const int EID_LANGUAGE_CHANGE = 37;
 
     public const int EID_FIGHTER_ENTERCOMBAT = 99;
     public const int EID_FIGHTER_HURT = 100;    

+ 12 - 2
Assets/Src/ExtendComponents/UILocalizeScript.cs

@@ -1,4 +1,5 @@
-using System.Collections;
+using System;
+using System.Collections;
 using TMPro;
 using UnityEngine;
 using UnityEngine.UI;
@@ -20,6 +21,12 @@ public class UILocalizeScript : MonoBehaviour
         mText = GetComponent<Text>();
         mTextMeshProUGUI = GetComponent<TextMeshProUGUI>();
         Inner_SetContent(m_key);
+        EventMgr.AddEventListener<int>(ECoreEventType.EID_LANGUAGE_CHANGE, OnLanguageChange);
+    }
+
+    private void OnLanguageChange(CoreEvent<int> e)
+    {
+        Refresh();
     }
 
     void OnEnable()
@@ -44,7 +51,10 @@ public class UILocalizeScript : MonoBehaviour
         Refresh();
     }
 
-
+    private void OnDestroy()
+    {
+        EventMgr.RemoveEventListener<int>(ECoreEventType.EID_LANGUAGE_CHANGE, OnLanguageChange);
+    }
     public void OnChangeLang()
     {
         if (!string.IsNullOrEmpty(m_key))

+ 7 - 0
Assets/Src/ExtendComponents/UILocalizeTexture.cs

@@ -21,6 +21,12 @@ public class UILocalizeTexture : MonoBehaviour
         oldname = "";
         loadSeq = 0;
         mImage = GetComponent<Image>();
+        EventMgr.AddEventListener<int>(ECoreEventType.EID_LANGUAGE_CHANGE,OnLanguageChange);
+    }
+
+    private void OnLanguageChange(CoreEvent<int> e)
+    {
+        Refresh();
     }
 
     // Start is called before the first frame update
@@ -39,6 +45,7 @@ public class UILocalizeTexture : MonoBehaviour
     private void OnDestroy()
     {
         Dispose();
+        EventMgr.RemoveEventListener<int>(ECoreEventType.EID_LANGUAGE_CHANGE, OnLanguageChange);
     }
 
     public void Refresh()