ドキュメント

Unity Engine

Unity Engine

IStartupLocalePrepare

Optional hook a startup selector implements to load what it needs before the locale is chosen.
読み終わるまでの所要時間 1 分最終更新 1ヶ月前

Definition

  • Type: Interface
  • Namespace: Unity.Localization
  • Assembly: UnityEngine.LocalizationRuntimeModule
public interface IStartupLocalePrepare

Remarks

Implement this interface alongside IStartupLocaleSelector when the locale comes from somewhere that has to be awaited, such as a cloud save or a platform API. LocalizationSettings.InitializeAsync awaits IStartupLocalePrepare.PrepareAsync on every selector that implements it, after the asset providers have discovered their locales and before any selector is asked to choose. Store the result and return it from IStartupLocaleSelector.GetStartupLocale, which stays synchronous. The three hooks run in the order IStartupLocalePrepare.PrepareAsync, then IStartupLocaleSelector.GetStartupLocale, then IStartupLocaleInitialize.PostInitialize.
A selector that awaits a value before choosing a locale.

Examples

using System;using System.Threading;using Unity.Localization;using UnityEngine;namespace Unity.Localization.Samples{ [Serializable] public class AsyncLocaleSelectorExample : IStartupLocaleSelector, IStartupLocalePrepare { string m_Code; public async Awaitable PrepareAsync(LocalizationSettings settings, CancellationToken cancellationToken = default) { m_Code = await FetchPreferredLanguageAsync(cancellationToken); } public Locale GetStartupLocale(LocalizationSettings settings) => string.IsNullOrEmpty(m_Code) ? null : settings.GetLocale(m_Code); // Stands in for a platform API or a cloud save that has to be awaited. static async Awaitable<string> FetchPreferredLanguageAsync(CancellationToken cancellationToken) { await Awaitable.NextFrameAsync(cancellationToken); return "fr"; } }}

Methods

Method

Description

PrepareAsyncLoads whatever the selector needs before it is asked for a locale.