InitializeAsync()
Loads the available locales and selects the startup locale, running once.
阅读时间1 分钟最后更新于 1 个月前
Definition
- Type: Method
- Namespace: Unity.Localization
- Assembly: UnityEngine.LocalizationRuntimeModule
public static Awaitable InitializeAsync()
Returns
Type | Description |
|---|---|
| Awaitable | An awaitable that completes when initialization has finished, or immediately when it has already run. |
Remarks
Discovers locales that the asset providers expose through ILocaleDiscovery and adds them to the registered LocalizationSettings.AvailableLocales, then selects the startup locale by evaluating the LocalizationSettings.StartupSelectors in order (skipping disabled locales) and falling back to LocalizationSettings.ProjectLocale. Initialization runs only once; the first synchronous or asynchronous resolve through the LocalizationSettings.Database triggers it automatically, so calling this explicitly is only needed when you want to await completion. When it finishes it raises LocalizationSettings.InitializationCompleted.
Waits for localization to be ready before resolving a string.
Examples
using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ public class InitializeAsyncExample : MonoBehaviour { async void Start() { await LocalizationSettings.InitializeAsync(); string title = await LocalizationSettings.ResourceDatabase.GetLocalizedStringAsync("UI Text", "title"); Debug.Log(title); } }}