用编译器和地址都可以实例化出预制体和下载,用浏览器打开程序就无法实例化,打包和下载代码如下
[MenuItem("AssetBundle/Package (Default)")]
static void PutBundleAssetesAll()
{
//将这些资源包放在一个名为ABs的目录下
// string assetBundleDirectory = "E:/UnityProject/ceshi/aboundceTest/assetbundle";
string assetBundleDirectory = "Assets/StreamingAssets/assetbundle";
//如果目录不存在,就创建一个目录
if (!Directory.Exists(assetBundleDirectory))
{
Directory.CreateDirectory(assetBundleDirectory);
}
BuildPipeline.BuildAssetBundles(assetBundleDirectory, BuildAssetBundleOptions.None, BuildTarget.StandaloneWindows64);
}
//string url = "http://192.168.11.114:8089/StreamingAssets/assetbundle/cube.unity3d";
//string url = "http://localhost:8089/StreamingAssets/assetbundle/cube.unity3d";
IEnumerator LoadABB(string url)
{
UnityWebRequest request = UnityWebRequestAssetBundle.GetAssetBundle(url);
yield return request.SendWebRequest();
if (request.isNetworkError)
{
text.text = request.error;
}
else
{
AssetBundle ab = DownloadHandlerAssetBundle.GetContent(request);
GameObject go = ab.LoadAsset<GameObject>("cube");
Debug.Log(go.name);
Instantiate(go).transform.position = Vector3.one;
text.text = go.name + "加载成功";
}
}
大哥,请问你解决了吗?我也想咨询这个问题 我的qq是1261037456