Class LocalizedAsset<TObject>
Provides a way to reference an Asset
Implements
Inherited Members
Namespace: UnityEngine .Localization
Assembly: Unity.Localization.dll
Syntax
[Serializable]
public class LocalizedAsset<TObject> : LocalizedAssetBase, ISerializationCallbackReceiver where TObject : Object
Type Parameters
Name | Description |
---|---|
TObject | The type that should be supported. This can be any type that inherits from UnityEngine.Object. |
Examples
This example shows how a Localized
public class LocalizedPrefabExample : MonoBehaviour
{
[Serializable]
public class LocalizedPrefab : LocalizedAsset<GameObject> {}
public LocalizedPrefab localizedPrefab;
GameObject currentInstance;
void OnEnable()
{
localizedPrefab.AssetChanged += UpdatePrefab;
}
void OnDisable()
{
localizedPrefab.AssetChanged -= UpdatePrefab;
}
void UpdatePrefab(GameObject value)
{
if (currentInstance != null)
Destroy(currentInstance);
currentInstance = Instantiate(value);
}
}
This example shows how a Localized
[CreateAssetMenu]
public class MyScriptableObject : ScriptableObject
{
public string someStringValue;
}
[Serializable]
public class LocalizedMyScriptableObject : LocalizedAsset<MyScriptableObject> { }
public class Example : MonoBehaviour
{
public LocalizedMyScriptableObject localizedScriptableObject;
void OnEnable()
{
localizedScriptableObject.AssetChanged += OnAssetChanged;
}
void OnDisable()
{
localizedScriptableObject.AssetChanged -= OnAssetChanged;
}
void OnAssetChanged(MyScriptableObject value)
{
Debug.Log(value.someStringValue);
}
}
This example shows how to bind to a UI Toolkit property. Note that this requires Unity 2023.2 and above.
using UnityEngine;
using UnityEngine.Localization;
using UnityEngine.UIElements;
public class LocalizedTextureUIDocumentExample : MonoBehaviour
{
void Start()
{
var document = GetComponent<UIDocument>();
var label = new Label();
label.text = "Some localized image";
document.rootVisualElement.Add(label);
// Add binding to the background style property of the label.
var localizedTexture = new LocalizedTexture { TableReference = "My asset table", TableEntryReference = "My Texture" };
label.SetBinding("style.backgroundImage", localizedTexture);
}
}
Constructors
Name | Description |
---|---|
Localized |
Initializes and returns an empty instance of a Localized |
Properties
Name | Description |
---|---|
Current |
The current loading operation for the asset when using Asset |
Current |
The current loading operation for the asset when using Asset |
Has |
Returns true if Asset |
Wait |
Determines if WaitForCompletion should be used to force loading to be completed immediately. See Synchronous Workflow for further details. Please note that WaitForCompletion is not supported on WebGL. |
Methods
Name | Description |
---|---|
Clear |
|
Force |
|
Load |
Provides a localized asset from a Asset |
Load |
Returns the localized asset as a UnityEngine.Object. |
Load |
Provides a localized asset from a Asset |
Load |
Overrides the asset's default type. This loads a type from Asset |
Register |
|
Reset() | Called when values are changed due to a change made via serialization, such as via the inspector. |
Events
Name | Description |
---|---|
Asset |
Provides a callback that will be invoked when the asset is available or has changed. |