Version: 2023.2
public static AssetBundle LoadFromFile (string path);
public static AssetBundle LoadFromFile (string path, uint crc);
public static AssetBundle LoadFromFile (string path, uint crc, ulong offset);

参数

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

返回

AssetBundle 已加载的 AssetBundle 对象,如果失败则为 null。

描述

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

The function supports bundles of any compression type. In case of LZMA compression, the file content will be fully decompressed into memory and loaded from there. See AssetBundles compression for more details.

LoadFromFileAsync 相比,该版本是同步的,将等待 AssetBundle 对象创建完毕才返回。

这是加载 AssetBundle 的最快方法。

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

public class LoadFromFileExample : MonoBehaviour { void Start() { var myLoadedAssetBundle = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "myassetBundle")); if (myLoadedAssetBundle == null) { Debug.Log("Failed to load AssetBundle!"); return; }

var prefab = myLoadedAssetBundle.LoadAsset<GameObject>("MyObject"); Instantiate(prefab);

myLoadedAssetBundle.Unload(false); } }

另请参阅:AssetBundleLoadFromFileAsync