Hello
I have a custom startup selector that should read the value from a file that could be somewhere and I’d prefer to read it asynchronously. I read here that I could use IPreloadRequired but how do I even use that? I have an async read file method that I want to use for my preload operation.
Some pseudo-code of what I’d like to do:
[Serializable]
public class SettingLocalizer : IStartupLocaleSelector, IPreloadRequired
{
public Locale GetStartupLocale(ILocalesProvider availableLocales)
{
return SettingsManager.LoadLanguage();
}
public AsyncOperationHandle PreloadOperation
{
get
{
// await SettingsManager.LoadSettingsAsync();
}
}
}
Any help would be appreciated!
Ah, we don’t support IPreloadRequired in the StartupSelectors. Its mainly used by databases. What you could do is put your async work into an Addressables initialization object:
https://docs.unity3d.com/Packages/com.unity.addressables@1.20/manual/InitializeAsync.html#initialization-objects
Do your initializing and then set the results in the SettingLocalizer which will be called once all the initialization has been completed.
Ah, I’ll look into that! Is it 100% safe that my initialization object will be called before the startup selector so I know it exists?
Yes, it’s fine. The LocalizationSettings will be available however they won’t be initialized so don’t try and access the Locales. You will be fine to access your startup selector through.
E.G
var mySelector = (SettingLocalizer)LocalizationSettings.StartupLocaleSelectors.Find(s => s is SettingLocalizer);
mySelector.someValue = data;
1 Like