advantage
Addressable resource system: easy to manage resources, hot update, reduce package size, etc.
Prepare
- Download the Addressables package from the Package Manager;
- After selecting the resource, check Addressable in the inspector window;
- Note: C# code cannot be set to address a resource
- After the resources in the Resources folder are set as addressable resources, they will be moved out of the folder to avoid resource duplication.
load
using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;
public class Addressables : MonoBehaviour
{
//1.资源标识类
public AssetReference assetReference;//通用资源标识类 加载任意类型资源
//2.资源异步加载
void Start()
{
//加载预制体
assetReference.LoadAssetAsync<GameObject>().Completed += (handle) =>
{
if (handle.Status == AsyncOperationStatus.Succeeded)
{
Instantiate(handle.Result, Vector3.zero, Quaternion.identity);
}
};
}
}