异步加载
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class LaodAB : MonoBehaviour {
// Use this for initialization
void Start () {
StartCoroutine("LoadWed");
//LoadFile();
}
void LoadFile()
{//本地
AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "my2"));
GameObject go = ab.LoadAsset<GameObject>("Cube");
GameObject g = Instantiate(go);
//g.transform.SetParent(GameObject.Find("Canvas").transform, false);
}
IEnumerator LoadWed()
{
string uri = "file:///" + Application.dataPath + "/StreamingAssets/my2";
UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
//AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath, "my2"));
GameObject go = ab.LoadAsset<GameObject>("Cube");
GameObject g = Instantiate(go);
}
void Update () {
}
}