首页 新闻 会员 周边 捐助

Unity Webgl打ab包放到IIS上

0
悬赏园豆:50 [待解决问题]

用编译器和地址都可以实例化出预制体和下载,用浏览器打开程序就无法实例化,打包和下载代码如下
[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 + "加载成功";
    }
}


想不开的教书人的主页 想不开的教书人 | 初学一级 | 园豆:152
提问于:2019-06-03 10:57
< >
分享
所有回答(1)
0

大哥,请问你解决了吗?我也想咨询这个问题 我的qq是1261037456

徐颖杰 | 园豆:204 (菜鸟二级) | 2020-11-30 18:31
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册