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); } }