Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

This article introduces the loading of Addressables resources, which is also based on AssetBundle. Addressables are released after the Unity2018 version. You can directly find Addressables in Window-> Package Manager, which has reached version 1.7.5.
Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

After the installation is complete, the resources in the project will appear Addressable.
Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources
After the installation is complete, enter window-> Asset Management-> Addressable-> Groups
Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

  1. Resources can be grouped, the first place after entering is the default Group group
  2. Create-> Group-> Package Assets can create Group groups
  3. Profile: Set the address of your own resource packaging, and select the location you set, enter the Manage Profile to set up multiple packaging addresses (can be test service, development service, online service, VIP service, etc.) local / remote packaging The settings
    can generate many different settings: test server, official server, VIP server, etc.
    • Local Build Path-local package path
    • Local Load Path-local
    package path • Remote Build Path-remote package path
    • Remote Load Path-Remote load pathAsynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources
  4. Tool includes the tools you use, Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resourcesincluding resource loading analysis Profiles, testing services Hosting Services, Labels tags, etc.
  5. There are three options for play Mode Script. The first one is faster, which can be tested in the Unity editor, the second is simulated loading, Unity simulates a remote loading process, and the third Build loads ( requires), when the program is packaged, you must first select him to package the resourcesAsynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources
  6. Bulid is a packaged resource

Addressables resource packaging process
Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

For resources that need to be loaded asynchronously, check Addressable and drag it directly to your default Group group or Group group created by Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources
you to modify the location of Mark 1 in the name of your resource. You can modify the location of
Mark 2 in your resource to set the label of your resource.
Note: follow-up You can load resources by tag or name. After
adding all the resources, package the resources in the Build location. Resource packaging is basically finished. As for the details, you can open the API documentation.

Resource loading method After the
above resources are packaged, the resources are loaded asynchronously

InstantiateAsync ()
• Asynchronous instance instantiation
• The system will not wait
• When the call is completed, it will come back and then run • A large number of instance instantiations will not get stuck in the system
LoadAssetAsync ()
• Asynchronous loading
• Resources can also be local Can be on a remote server

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

public class Loading : MonoBehaviour
{
    //直接选择拖入目标
    public AssetReference box;

    /// <summary>
    /// 加载
    /// </summary>
    void LoadBox()
    {
        box.LoadAssetAsync<GameObject>().Completed += OnLoaded;
    }

    //加载完成的回调
    void OnLoaded(AsyncOperationHandle<GameObject> obj)
    {
        GameObject cube = obj.Result;
    }
}

Load by nameAsynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

using UnityEngine;
using UnityEngine.AddressableAssets;
using UnityEngine.ResourceManagement.AsyncOperations;

public class Loading : MonoBehaviour
{

    /// <summary>
    /// 加载
    /// </summary>
    void LoadBox()
    {
        Addressables.LoadAssetAsync<GameObject>("cube").Completed += OnLoaded;

                //异步加载实例化
        //Addressables.InstantiateAsync("cube");
    }

    //加载完成的回调
    void OnLoaded(AsyncOperationHandle<GameObject> obj)
    {
        GameObject cube = obj.Result;
    }
}

Load by label name (suitable for loading material maps, etc.)
Asynchronous loading of Unity3D resources (3)-Asynchronous loading of Addressables resources

  Addressables.LoadAssetsAsync<GameObject>(new List<object> { "key", "label" }, null, Addressables.MergeMode.Intersection).Completed += (AsyncOperationHandle<IList<GameObject>> obj) => {
            GameObject box = ((AsyncOperationHandle<IList<GameObject>>)obj).Result[0];
        };

Note: ⚠️When
a resource in a Resources folder is marked as Addressable, the system will automatically move it out of the Resources folder to the new folder of Resources_moved.
• The default associated location will point to the original old road route.
• The original loading code will change from Resources.LoadAsync <GameObject> (“map /
city.prefab”) to Addressables.LoadAssetAsync <GameObject> (“map / city.prefab”);

Conversion of the old version:
When Asset Bundles is set in the project, the first time you open the Addressables menu, you will be asked whether you want to transfer all to the Addressables group.

  • Addressables is based on the extension of the Asset Bundles system. You can think of Asset Bundles as manual management and Addressables as automatic management.
  • You can only use Addressables at all.
  • Although Addressables and Asset Bundles can be mixed, the official goal is not two
  • The coexistence, but instead Addressables can handle all related tasks as the goal.
  • public GameObject XXX changed to public AssetReference XXX; • Instantiate () changed to AssetRefName.InstantiateAsync ();
  • Load use LoadAssetAsync <GameObject> ();

Summary
legacy Assetbudle and Addressable compared to the latter easier to use, and do not address themselves to manage storage resources, resource update is also more convenient.
Addressables are not only loaded or instantiated, you can query where the object is. • The system will help you deal with rational correlation.
Build Script allows you to write your own packaging process.
Addressables is a high-level process based on the Asset Bundle architecture.
Addressable in the future

Addressable currently has some problems, such as not supporting script packaging, A project packaging, B project loading and use bugs, etc.

Guess you like

Origin blog.51cto.com/myselfdream/2488786