赞
踩
用编译器和地址都可以实例化出预制体和下载,用浏览器打开程序就无法实例化,打包和下载代码如下
[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);
}
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("cube");
Debug.Log(go.name);
Instantiate(go).transform.position = Vector3.one;
text.text = go.name + "加载成功";
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。