Version: 2023.2

AssetBundle.LoadFromFileAsync

切换到手册
public static AssetBundleCreateRequest LoadFromFileAsync (string path);
public static AssetBundleCreateRequest LoadFromFileAsync (string path, uint crc);
public static AssetBundleCreateRequest LoadFromFileAsync (string path, uint crc, ulong offset);

参数

path 文件在磁盘上的路径。
crc 未压缩内容的 CRC-32 校验和(可选)。如果该参数不为零,则加载前将内容与校验和进行比较,如果不匹配则给出错误。
offset 字节偏移(可选)。该值指定读取 AssetBundle 的起始位置。

返回

AssetBundleCreateRequest Asynchronous load request for an AssetBundle. Use assetBundle property to get an AssetBundle once it is loaded.

描述

从磁盘上的文件异步加载 AssetBundle。

The function supports bundles of any compression type. In case of LZMA compression, the data will be decompressed to the memory. See AssetBundles compression for more details.

这是加载 AssetBundle 的最快方法。

using UnityEngine;
using System.Collections;
using System.IO;

public class LoadFromFileAsyncExample : MonoBehaviour { IEnumerator Start() { var bundleLoadRequest = AssetBundle.LoadFromFileAsync(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); yield return bundleLoadRequest;

var myLoadedAssetBundle = bundleLoadRequest.assetBundle; if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); yield break; }

var assetLoadRequest = myLoadedAssetBundle.LoadAssetAsync<GameObject>("MyObject"); yield return assetLoadRequest;

GameObject prefab = assetLoadRequest.asset as GameObject; Instantiate(prefab);

myLoadedAssetBundle.Unload(false); } }
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961