Property InternalIdTransformFunc
InternalIdTransformFunc
Functor to transform internal ids before being used by the providers.
Declaration
public Func<IResourceLocation, string> InternalIdTransformFunc { get; set; }
Property Value
Type | Description |
---|---|
Func<IResourceLocation, string> | A function taking an IResourceLocation and returning a transformed string location. |
Remarks
Used to assign a function to the ResourceManager that replaces location identifiers used at runtime. This is useful when you want to load assets from a different location than the one specified in the content catalog, for example downloading a remote AssetBundle from a different URL.
Assigning this value through the Addressables object will set the value on the ResourceManager.
The example below instantiates a GameObject from a local AssetBundle. The location identifier of the bundle is replaced with a file URI, and so the bundle is loaded via UnityWebRequest.
public AssetReferenceGameObject asset; // Identify the asset
AsyncOperationHandle<GameObject> opHandle;
void UsingInternalIdTransformFuncSample()
{
Addressables.InternalIdTransformFunc = MyCustomTransform;
opHandle = Addressables.InstantiateAsync(asset);
opHandle.Completed += OnInstantiateComplete;
}
//Implement a method to transform the internal ids of locations
static string MyCustomTransform(IResourceLocation location)
{
if (location.ResourceType == typeof(IAssetBundleResource)
&& !location.InternalId.StartsWith("http"))
{
Debug.Log($"Replace local identifier with remote URL : {location.InternalId}");
return "file:///" + location.InternalId;
}
return location.InternalId;
}
void OnInstantiateComplete(AsyncOperationHandle<GameObject> handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log($"Successfully instantiated GameObject named '{handle.Result.name}'");
}
}
void ReleaseResources()
{
opHandle.Release();
}
// When ready to release the asset, call ReleaseResources().
// For example during OnDestroy().
//void OnDestroy()
//{
// ReleaseResources();
//}
///