无法在.GetDownloadUrlAsync()方法内部启动协程?

时间:2019-08-02 15:31:41

标签: c# unity3d asynchronous

所以我知道我可能无法使用单独的线程启动协程(如果这就是你所说的话),但是我想为什么这不可能,并且有办法解决吗?下面是代码。 (简而言之,代码)

与尝试使用协程下载资产捆绑包相比,我基本上是使用.GetDownloadUrlAsync()方法从firebase获得直接链接。

    {
        string assetBundleName = "assetbundle";
        string assetBundleEndpoint = _storageUrl + "/" + targetInfo.Name + "/" + assetBundleName;

        StorageReference _Ref = _storage.GetReferenceFromUrl(assetBundleEndpoint);

        _Ref.GetDownloadUrlAsync().ContinueWith((Task<Uri> task) =>
        {
            if (!task.IsFaulted && !task.IsCanceled)
            {
                StartCoroutine(HandleDownloadAssets(task.Result.AbsoluteUri, assetBundleName));
            }
        });
    }

    IEnumerator HandleDownloadAssets(string assetBundleEndpoint, string assetBundleName)
    {
        UnityWebRequest www = UnityWebRequestAssetBundle.GetAssetBundle(assetBundleEndpoint);
        yield return www.SendWebRequest();

        if (www.isNetworkError || www.isHttpError)
        {
            Debug.Log(www.error);
        }
        else
        {
            AssetBundle bundle = DownloadHandlerAssetBundle.GetContent(www);
            var prefab = bundle.LoadAsset<GameObject>(assetBundleName);
            Instantiate(prefab, _imageTrackable.transform);
        }
    }```

0 个答案:

没有答案