以上是使用UnityWebRequest加载资源
//以下是加载内存资源
需注意的是加载图片时需要 新建image 千万不要忘记把图片设置成 Sprite(2D and UI) 格式
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using System.IO;
using System.Xml.Serialization;
using UnityEngine.UI;
public class Control : MonoBehaviour
{
string dir = “AssetBundles/aaaa”;
public Image imagea;
// Start is called before the first frame update
void Start()
{
StartCoroutine("LoadFromMemoryAsync");
Debug.Log(1);
//GameObject a = GameObject.Instantiate(UnityEditor.AssetDatabase.LoadAssetAtPath<GameObject>("Assets/Cube.prefab"));
}
IEnumerator LoadFromMemoryAsync()
{
AssetBundleCreateRequest request = AssetBundle.LoadFromMemoryAsync(File.ReadAllBytes(dir));
Debug.Log(1);
yield return request;
AssetBundle ab = request.assetBundle;
//使用里面的资源
Sprite allenprefab = ab.LoadAsset<Sprite>("denglun");
imagea.sprite = allenprefab;
}
通过Manifest文件得到某个包的依赖