在Android上下载Asset Bundle时出现例外情况

时间:2016-12-10 13:49:03

标签: c# android unity3d

我为Android构建游戏时遇到以下异常

  

WWW下载有一个错误:java.lang.IllegalArgumentException:uri ==   空

现在我不知道为什么会这样,因为它在编辑器中工作正常。以下是相关代码:

assetLoader.BundleURL = "ftp://user:pass@81.161.248.122/Unity-Uri/AssetBundles/seasonalcontent/christmas";
            assetLoader.version = 1;
            assetLoader.StartDownload();

和实际的下载代码:

IEnumerator DownloadAndCache()
    {
        // Wait for the Caching system to be ready
        while (!Caching.ready)
            yield return null;

        // Load the AssetBundle file from Cache if it exists with the same version or download and store it in the cache
        using (WWW www = WWW.LoadFromCacheOrDownload(BundleURL, version))
        {
            yield return www;
            if (www.error != null)
                throw new Exception("WWW download had an error:" + www.error);
            AssetBundle bundle = www.assetBundle;
            SeasonManager.assets = bundle.LoadAllAssets();
            Debug.Log("Stop");
            OnContentLoaded();
        } // memory is freed from the web stream (www.Dispose() gets called implicitly)
    }

编辑:我从文档中得到了这个:ftp://协议支持仅限于匿名下载。 android上不支持ftp吗?

编辑2:正如评论中的建议我尝试了这一点,导致登录失败错误:

 IEnumerator makeRequest()
    {
        string authorization = authenticate("username", "pass");
        string url = "ftp://ipgoeshere";


        UnityWebRequest www = UnityWebRequest.Get(url);
        www.SetRequestHeader("AUTHORIZATION", authorization);

        yield return www.Send();
        if (www.isError)
        {
            Debug.Log(www.error);
        }
        else
        {
            AssetBundle bundle = ((DownloadHandlerAssetBundle)www.downloadHandler).assetBundle;
            SeasonManager.assets = bundle.LoadAllAssets();
        }
    }
string authenticate(string username, string password)
    {
        string auth = username + ":" + password;
        auth = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(auth));
        auth = "Basic " + auth;
        return auth;
    }

澄清我确保用户名密码和服务器地址是正确的。出于显而易见的原因,我只是将它们从代码中删除了。

0 个答案:

没有答案