Property InstanceProvider
InstanceProvider
The Instance Provider used by the Addressables System.
선언
public static IInstanceProvider InstanceProvider { get; }
프로퍼티 값
타입 | 설명 |
---|---|
IInstanceProvider | The IInstanceProvider object used to create instances of GameObjects. |
참고
Retrieves the interface used by the Addressables Asset System to create instances of Addressable GameObjects.
예
The example below instantiates a GameObject using ProvideInstance.
public AssetReferenceGameObject asset; // Identify the asset
AsyncOperationHandle<GameObject> instHandle;
AsyncOperationHandle<IList<IResourceLocation>> locHandle;
void UsingInstanceProviderSample()
{
locHandle = Addressables.LoadResourceLocationsAsync(asset, typeof(GameObject));
locHandle.Completed += OnLoadComplete;
}
void OnLoadComplete(AsyncOperationHandle<IList<IResourceLocation>> handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log($"Successfully loaded resource locations");
foreach (IResourceLocation location in handle.Result)
{
ResourceManager rm = Addressables.ResourceManager;
IInstanceProvider provider = Addressables.InstanceProvider;
instHandle = rm.ProvideInstance(provider, location, default(InstantiationParameters));
instHandle.Completed += OnProvideInstanceComplete;
}
}
}
void OnProvideInstanceComplete(AsyncOperationHandle<GameObject> handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
Debug.Log($"Successfully instantiated GameObject named '{handle.Result.name}'");
}
}
void ReleaseResources()
{
Addressables.Release(locHandle);
Addressables.Release(instHandle);
}
// When ready to release the asset, call ReleaseResources().
// For example during OnDestroy().
// void OnDestroy()
// {
// ReleaseResources();
// }