using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEngine.Networking;
public class LoadDb : MonoBehaviour {
// Use this for initialization
void Start () {
//LoadFile();
StartCoroutine(LoadWeb());
}
private void LoadFile()
{
//加载本地文件
AssetBundle ab = AssetBundle.LoadFromFile(Path.Combine(Application.streamingAssetsPath,"main"));//mainpanel被打包之后的名字
GameObject go = ab.LoadAsset<GameObject>("MainPanel");//预设体的名字 (在被打打包之前对象的名字)
GameObject g = Instantiate(go);
g.name = "MainPanel";
g.transform.SetParent(GameObject.Find("Canvas").transform,false);
}
IEnumerator LoadWeb() {
//加载网络文件
string uri = "file:///" + Application.dataPath + "/StreamingAssets/main";
UnityWebRequest request = UnityWebRequest.GetAssetBundle(uri);
yield return request.Send();
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
GameObject go = ab.LoadAsset<GameObject>("MainPanel");//预设体的名字 (在被打打包之前对象的名字)
GameObject g = Instantiate(go);
g.name = "MainPanel";
g.transform.SetParent(GameObject.Find("Canvas").transform, false);
}
void Update () {
}
}
AssetBundle(AB)解析
最新推荐文章于 2023-06-08 20:15:21 发布