I would like to change the LocalizedString used in the LocalizeStringEvent during run time. And I would like to do this via Unity Events in the inspector.
The setup is the following:
A text mesh pro component.
A Localize String Event component
A custom component for changing the StringReference of the LocalizeStringEvent component with a function:
code
public class LocalizationExtensions : MonoBehaviour
{
[Required]
[SerializeField] private LocalizeStringEvent _localizeStringEvent;
public void SetStringReference(LocalizedString localizedString)
{
_localizeStringEvent.SetStringReference(localizedString);
}
}
SetStringReference is an extension method, which also refreshes the string.
The issue is that I cannot call the SetStringReference method via Unity Events in the inspector because LocalizedString is not a Unity object. It is a shame that 2 Unity systems do not work together nicely. If I didn’t want to create a script purely for this case then what are my options?
Yes, this certainly works. However it is error prone and tedious to use. Would be much simpler to choose a StringReference from a list rather than having to look up the exact key value.
You could do this but it wont work in a UnityEvent as they only support primitives and Object references…
You could make a version of LocalizedString that would work as an object reference.
[CreateAssetMenu]
public class LocalizedStringAsset : ScriptableObject
{
public LocalizedString localizedString;
}
public void SetString(LocalizedStringAsset asset)
{
localizedStringEvent.StringReference = asset.localizedString;
}
You can now create an asset for each string you want to reference.