Class LocalizeTextureEvent
Component that can be used to Localize a Texture asset. Provides an update event OnUpdateAsset that can be used to automatically update the Texture whenever the SelectedLocale or AssetReference changes.
Inheritance
LocalizeTextureEvent
Inherited Members
Namespace: UnityEngine.Localization.Components
Syntax
public class LocalizeTextureEvent : LocalizedAssetEvent<Texture, LocalizedTexture, UnityEventTexture>
Remarks
This component can also be added through the Localize menu item in the Raw Image context menu. Adding it this way will also automatically configure the Update Asset events to update the Texture.
Examples
The example shows how to switch between different Localized Textures.
#if PACKAGE_UGUI
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.Localization.Components;
using UnityEngine.UI;
public class LocalizedTextureChanger : MonoBehaviour
{
public LocalizeTextureEvent localizeTextureEvent;
public LocalizedTexture[] textures;
public RawImage image;
int currentTexture = 0;
private void Start()
{
ChangeTexture(textures[currentTexture]);
}
private void OnGUI()
{
GUILayout.BeginHorizontal();
if (GUILayout.Button("Previous"))
{
if (currentTexture == 0)
currentTexture = textures.Length - 1;
else
currentTexture--;
ChangeTexture(textures[currentTexture]);
}
// Show the current texture that is visible
GUILayout.Label(image.texture?.name);
if (GUILayout.Button("Next"))
{
if (currentTexture == textures.Length - 1)
currentTexture = 0;
else
currentTexture++;
ChangeTexture(textures[currentTexture]);
}
GUILayout.EndHorizontal();
}
void ChangeTexture(LocalizedTexture texture)
{
// When we assign a new AssetReference the system will automatically load the new Sprite asset then call the AssetChanged event.
localizeTextureEvent.AssetReference = texture;
}
}
#endif