Created
June 2, 2020 22:03
-
-
Save karljj1/4b10868766a33435c2fe34606874a274 to your computer and use it in GitHub Desktop.
A workaround for 1247232
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System; | |
using System.Linq; | |
using UnityEngine; | |
using UnityEngine.Localization.Settings; | |
using UnityEngine.Localization.SmartFormat; | |
using UnityEngine.Localization.SmartFormat.Core.Extensions; | |
public class FixListFormatter : MonoBehaviour | |
{ | |
void Start() | |
{ | |
var formatters = LocalizationSettings.StringDatabase.SmartFormatter.FormatterExtensions; | |
for (int i = 0; i < formatters.Count; ++i) | |
{ | |
// If the name is null then create a new instance so we can get the default names and then copy it across | |
if (formatters[i].Names == null) | |
{ | |
// We only support 2 types of constructor. A default and one that takes a SmartFormatter. | |
var type = formatters[i].GetType(); | |
var hasDefaultConstructor = type.GetConstructors().Any(c => c.GetParameters().Length == 0); | |
var hasSmartFormatterConstructor = type.GetConstructors().Any(c => c.GetParameters().Length == 1 && c.GetParameters()[0].ParameterType == typeof(SmartFormatter)); | |
if (hasSmartFormatterConstructor || hasDefaultConstructor) | |
{ | |
var instance = hasDefaultConstructor ? Activator.CreateInstance(type) : Activator.CreateInstance(type, LocalizationSettings.StringDatabase.SmartFormatter); | |
formatters[i].Names = (instance as IFormatter).Names; | |
Debug.Log("Fixed null Names for" + type.Name); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment