LocalizeStringEvent
Component that resolves a localized string and forwards it through a UnityEvent whenever the value or the selected locale changes.
Read time 7 minutesLast updated 10 days ago
Definition
- Type: Class
- Namespace: Unity.Localization.Components
- Assembly: UnityEngine.LocalizationRuntimeModule
- Inherits from: MonoBehaviour
[AddComponentMenu("Localization/Localize String Event")]public class LocalizeStringEvent : MonoBehaviour
Remarks
Add this component to a GameObject, assign its LocalizeStringEvent.StringReference in the Inspector, then connect LocalizeStringEvent.OnUpdateString to a text field so the field updates automatically. While the component is active it subscribes to LocalizedString.StringChanged, so it re-resolves and re-invokes the event when LocalizationSettings.SelectedLocale changes. Use it for per-object localization without writing subscription code by hand.
Forward the resolved string to a UI text field.
Examples
using Unity.Localization.Components;using UnityEngine;namespace Unity.Localization.Samples{ public class LocalizeStringEventBindingExample : MonoBehaviour { public LocalizeStringEvent localize; public TextMesh label; void OnEnable() => localize.OnUpdateString.AddListener(OnUpdate); void OnDisable() => localize.OnUpdateString.RemoveListener(OnUpdate); void OnUpdate(string value) => label.text = value; }}
Properties
Property | Description |
|---|---|
| OnUpdateString | The event invoked with the localized string each time it resolves. |
| StringReference | The localized string reference to resolve. |
Inheritance
Operators
Operator | Description |
|---|---|
| operator == | Compares two object references to see if they refer to the same object. |
| bool | Determines whether the object exists. |
| operator != | Compares if two objects refer to a different object. |