Search Unity

Question IStartupSelector with async preload

Discussion in 'Localization Tools' started by Hertzole, Aug 18, 2022.

  1. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    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:

    Code (CSharp):
    1. [Serializable]
    2. public class SettingLocalizer : IStartupLocaleSelector, IPreloadRequired
    3. {
    4.     public Locale GetStartupLocale(ILocalesProvider availableLocales)
    5.     {
    6.         return SettingsManager.LoadLanguage();
    7.     }
    8.  
    9.     public AsyncOperationHandle PreloadOperation
    10.     {
    11.         get
    12.         {
    13.             // await SettingsManager.LoadSettingsAsync();
    14.         }
    15.     }
    16. }
    Any help would be appreciated!
     
  2. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
  3. Hertzole

    Hertzole

    Joined:
    Jul 27, 2013
    Posts:
    422
    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?
     
  4. karl_jones

    karl_jones

    Unity Technologies

    Joined:
    May 5, 2015
    Posts:
    8,293
    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
    Code (csharp):
    1. var mySelector = (SettingLocalizer)LocalizationSettings.StartupLocaleSelectors.Find(s => s is SettingLocalizer);
    2. mySelector.someValue = data;
     
    Hertzole likes this.