Addressable System - Loading Resources

advantage

Addressable resource system: easy to manage resources, hot update, reduce package size, etc.

Prepare

  1. Download the Addressables package from the Package Manager;
  2. After selecting the resource, check Addressable in the inspector window;
  3. Note: C# code cannot be set to address a resource
  4. 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);
             }
         };
    }
}

Guess you like

Origin blog.csdn.net/weixin_43796392/article/details/122874968