Files
Hasebe/Library/PackageCache/com.unity.addressables@42676f2a154e/Tests/Editor/DocExampleCode/AsynchronousLoading.cs
T
2026-09-21 12:15:57 +03:00

49 lines
1.3 KiB
C#

namespace AddressableAssets.DocExampleCode
{
#region doc_asyncload
using System.Collections;
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
internal class AsynchronousLoading : MonoBehaviour
{
private string address = "tree";
private AsyncOperationHandle loadHandle;
// always minimum of 1 frame
IEnumerator LoadAssetCoroutine()
{
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
yield return loadHandle;
}
// minimum of 1 frame for new asset loads
// callback called in current frame for already loaded assets
void LoadAssetCallback()
{
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
loadHandle.Completed += h =>
{
// Loaded here
};
}
// minimum of 1 frame for new asset loads
// await completes in current frame for already loaded assets
async void LoadAssetWait()
{
loadHandle = Addressables.LoadAssetAsync<GameObject>(address);
await loadHandle.Task;
}
private void OnDestroy()
{
loadHandle.Release();
}
}
#endregion
}