Addressables
Last updated
public AssetReference[] backgroundAddressableReferences;public void LoadBackgrounds()
{
List<AsyncOperationHandle<Sprite>> handles =
new List<AsyncOperationHandle<Sprite>>();
foreach (var reference in backgroundAddressableReferences)
{
// Check if the reference is valid before loading
if (reference != null)
{
AsyncOperationHandle<Sprite> handle =
reference.LoadAssetAsync<GameObject>();
handle.Completed += OnBackgroundLoaded;
handles.Add(handle);
}
}
}
private void OnBackgroundLoaded(AsyncOperationHandle<Sprite> handle)
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
GameObject Sprite = handle.Result;
// Use image here to assign to your in game images
}
else
{
Debug.LogError("Failed to load background: " + handle.OperationException);
}
}