fix: 加强Translate和GetSourceText的null安全检查
This commit is contained in:
parent
86370f9417
commit
e3f5f18926
@ -679,7 +679,9 @@ public class LocalizationManager : MonoBehaviour
|
||||
if (string.IsNullOrEmpty(source) || language == (int)UILanguage.Chinese) return source;
|
||||
|
||||
string[] values;
|
||||
return table.TryGetValue(source, out values) ? values[language] : source;
|
||||
if (table.TryGetValue(source, out values) && values != null && language < values.Length && values[language] != null)
|
||||
return values[language];
|
||||
return source;
|
||||
}
|
||||
|
||||
private string GetSourceText(string value)
|
||||
@ -688,9 +690,10 @@ public class LocalizationManager : MonoBehaviour
|
||||
|
||||
foreach (KeyValuePair<string, string[]> pair in table)
|
||||
{
|
||||
if (pair.Value == null) continue;
|
||||
if (pair.Value == null || pair.Value.Length <= 1) continue;
|
||||
for (int i = 1; i < pair.Value.Length; i++)
|
||||
{
|
||||
if (object.ReferenceEquals(pair.Value[i], value)) return pair.Key;
|
||||
if (pair.Value[i] != null && pair.Value[i] == value) return pair.Key;
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user