Version: 2023.2

AssetBundle.LoadFromMemory

切换到手册
public static AssetBundle LoadFromMemory (byte[] binary);
public static AssetBundle LoadFromMemory (byte[] binary, uint crc);

参数

binary 包含 AssetBundle 数据的字节数组。
crc 未压缩内容的 CRC-32 校验和(可选)。如果该参数不为零,则加载前将内容与校验和进行比较,如果不匹配则给出错误。

返回

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

描述

Synchronously load an AssetBundle from a memory region.

Use this method to load an AssetBundle from an array of bytes. This is useful when you have downloaded the data with encryption and need to load the AssetBundle from the decrypted bytes.

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

using UnityEngine;
using UnityEngine.Networking;
using System.Collections;

public class ExampleClass : MonoBehaviour { byte[] MyDecrypt(byte[] binary) { // ...Perform some decryption process here to transform the input... return binary; }

IEnumerator Start() { var uwr = UnityWebRequest.Get("https://myserver/myBundle.unity3d"); yield return uwr.SendWebRequest(); byte[] decryptedBytes = MyDecrypt(uwr.downloadHandler.data); AssetBundle.LoadFromMemory(decryptedBytes); } }