LanguageDropdown
A dropdown that lets the player pick a language.
読み終わるまでの所要時間 10 分最終更新 1ヶ月前
Definition
- Type: Class
- Namespace: Unity.Localization.UI
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: PopupField<Locale>
- Implements: IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle, IBindable, IMixedValueSupport, INotifyValueChanged<Locale>
[UxmlElement]public class LanguageDropdown : PopupField<Locale>, IEventHandler, IResolvedStyle, ITransform, ITransitionAnimations, IExperimentalFeatures, IVisualElementScheduler, ICustomStyle, IBindable, IMixedValueSupport, INotifyValueChanged<Locale>
Remarks
The control fills itself from LocalizationSettings.AvailableLocales and writes the chosen locale to LocalizationSettings.SelectedLocale, so it needs no setup code. It follows a change made anywhere else, and it refreshes when localization finishes initializing, which is when locales discovered from data files appear. Only the locales whose Locale.Enabled is true are offered.
Additional Resources: LanguageRadioButtonGroup, LocalizationSettings.SelectedLocale, LocalizationSettings.AvailableLocales
Adds a language dropdown to a panel from code.
Examples
using Unity.Localization.UI;using UnityEngine;using UnityEngine.UIElements;namespace Unity.Localization.Samples{ [RequireComponent(typeof(UIDocument))] public class LanguageDropdownExample : MonoBehaviour { void OnEnable() { var dropdown = new LanguageDropdown("Language"); GetComponent<UIDocument>().rootVisualElement.Add(dropdown); } }}
Constructors
Constructor | Description |
|---|---|
| LanguageDropdown() | Creates a language dropdown with no label. |
| LanguageDropdown(System.String) | Creates a language dropdown with a label in front of it. |