Skip to content

Commit 234e4f5

Browse files
committed
fix change font not working when awake
1 parent b65dad4 commit 234e4f5

File tree

4 files changed

+30
-14
lines changed

4 files changed

+30
-14
lines changed

Runtime/Component/LocalizeText.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ protected override void OnSetup()
2626

2727
s_manager.OnChangeFont -= OnChangeFont;
2828
s_manager.OnChangeFont += OnChangeFont;
29+
30+
if (s_manager.TryGetFont(out Font font))
31+
{
32+
OnChangeFont(font);
33+
}
2934
}
3035

3136
protected override void OnChangeLanguage(SystemLanguage language)

Runtime/ILocalizeManager.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,12 @@ public interface ILocalizeManager
99
event System.Action<Font> OnChangeFont;
1010
SystemLanguage currentLanguage { get; }
1111

12-
ILocalizeManager AddData(IEnumerable<ILocalizeData> datas);
13-
ILocalizeManager AddFontData(IEnumerable<ILocalizeFontData> datas);
12+
ILocalizeManager AddData(IEnumerable<ILocalizeData> data);
13+
ILocalizeManager AddFontData(IEnumerable<ILocalizeFontData> data);
1414
ILocalizeManager ChangeLanguage(SystemLanguage language);
1515

1616
string GetLocalizeText(string languageID, params string[] param);
1717
bool TryGetLocalizeText(string languageID, out string result, params string[] param);
18+
bool TryGetFont(out Font font);
1819
}
1920
}

Runtime/LocalizeManager.cs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,17 +35,9 @@ public ILocalizeManager ChangeLanguage(SystemLanguage language)
3535
{
3636
_currentLanguage = language;
3737
OnChangeLanguage?.Invoke(language);
38-
if (_fontDictionary.TryGetValue(language, out ILocalizeFontData fontData))
39-
{
40-
Font font = fontData.GetFont();
41-
if (font == null)
42-
{
43-
Debug.LogError($"LocalizeManager.{nameof(ChangeLanguage)}(language({language}) font == null");
44-
return this;
45-
}
4638

47-
OnChangeFont?.Invoke(font);
48-
}
39+
TryGetFont(out Font font);
40+
OnChangeFont?.Invoke(font);
4941

5042
return this;
5143
}
@@ -87,5 +79,22 @@ bool TryGetLocalizeText(bool printError, string languageID, out string result, p
8779

8880
return true;
8981
}
82+
83+
public bool TryGetFont(out Font font)
84+
{
85+
font = null;
86+
if (_fontDictionary.TryGetValue(_currentLanguage, out ILocalizeFontData fontData))
87+
{
88+
font = fontData.GetFont();
89+
if (font == null)
90+
{
91+
Debug.LogError($"LocalizeManager.{nameof(ChangeLanguage)}(language({_currentLanguage}) font == null");
92+
return false;
93+
}
94+
95+
}
96+
97+
return font != null;
98+
}
9099
}
91100
}

Runtime/LocalizeManagerComponent.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,12 @@ public event Action<Font> OnChangeFont
2121

2222
LocalizeManager _manager = new LocalizeManager();
2323

24-
public ILocalizeManager AddData(IEnumerable<ILocalizeData> datas) => _manager.AddData(datas);
25-
public ILocalizeManager AddFontData(IEnumerable<ILocalizeFontData> datas) => _manager.AddFontData(datas);
24+
public ILocalizeManager AddData(IEnumerable<ILocalizeData> data) => _manager.AddData(data);
25+
public ILocalizeManager AddFontData(IEnumerable<ILocalizeFontData> data) => _manager.AddFontData(data);
2626
public ILocalizeManager ChangeLanguage(SystemLanguage language) => _manager.ChangeLanguage(language);
2727

2828
public string GetLocalizeText(string languageID, params string[] param) => _manager.GetLocalizeText(languageID, param);
2929
public bool TryGetLocalizeText(string languageID, out string result, params string[] param) => _manager.TryGetLocalizeText(languageID, out result, param);
30+
public bool TryGetFont(out Font font) => _manager.TryGetFont(out font);
3031
}
3132
}

0 commit comments

Comments
 (0)