コード例 #1
0
ファイル: AssetPromise_AB.cs プロジェクト: menduz/explorer
        protected IEnumerator LoadAssetBundleWithDeps(string baseUrl, string hash, Action OnSuccess, Action OnFail)
        {
            if (!DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                CoroutineStarter.Start(DependencyMapLoadHelper.GetDepMap(baseUrl, hash));
            }

            yield return(DependencyMapLoadHelper.WaitUntilDepMapIsResolved(hash));

            if (DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                using (var it = DependencyMapLoadHelper.dependenciesMap[hash].GetEnumerator())
                {
                    while (it.MoveNext())
                    {
                        var dep     = it.Current;
                        var promise = new AssetPromise_AB(baseUrl, dep);
                        AssetPromiseKeeper_AB.i.Keep(promise);
                        dependencyPromises.Add(promise);
                        yield return(promise);
                    }
                }
            }

            yield return(WaitForConcurrentRequestsSlot());

            RegisterConcurrentRequest();
            yield return(LoadAssetBundle(baseUrl + hash, OnSuccess, OnFail));

            UnregisterConcurrentRequest();
        }
コード例 #2
0
        protected IEnumerator LoadAssetBundleWithDeps(string baseUrl, string hash, Action OnSuccess, Action OnFail)
        {
            string finalUrl = baseUrl + hash;

            if (failedRequestUrls.Contains(finalUrl))
            {
                OnFail?.Invoke();
                yield break;
            }

            yield return(WaitForConcurrentRequestsSlot());

            RegisterConcurrentRequest();
#if UNITY_EDITOR
            assetBundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(finalUrl, Hash128.Compute(hash));
#else
            //NOTE(Brian): Disable in build because using the asset bundle caching uses IDB.
            assetBundleRequest = UnityWebRequestAssetBundle.GetAssetBundle(finalUrl);
#endif
            asyncOp = assetBundleRequest.SendWebRequest();

            if (!DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                CoroutineStarter.Start(DependencyMapLoadHelper.GetDepMap(baseUrl, hash));
            }

            yield return(DependencyMapLoadHelper.WaitUntilDepMapIsResolved(hash));

            if (DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                using (var it = DependencyMapLoadHelper.dependenciesMap[hash].GetEnumerator())
                {
                    while (it.MoveNext())
                    {
                        var dep     = it.Current;
                        var promise = new AssetPromise_AB(baseUrl, dep, containerTransform);
                        AssetPromiseKeeper_AB.i.Keep(promise);
                        dependencyPromises.Add(promise);
                    }
                }
            }

            while (!asyncOp.isDone)
            {
                yield return(null);
            }

            //NOTE(Brian): For some reason, another coroutine iteration can be triggered after Cleanup().
            //             So assetBundleRequest can be null here.
            if (assetBundleRequest == null)
            {
                OnFail?.Invoke();
                yield break;
            }

            if (!assetBundleRequest.WebRequestSucceded())
            {
                if (VERBOSE)
                {
                    Debug.Log($"Request failed? {assetBundleRequest.error} ... {finalUrl}");
                }
                failedRequestUrls.Add(finalUrl);
                assetBundleRequest.Abort();
                assetBundleRequest = null;
                OnFail?.Invoke();
                yield break;
            }

            UnregisterConcurrentRequest();

            foreach (var promise in dependencyPromises)
            {
                yield return(promise);
            }

            AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(assetBundleRequest);

            if (assetBundle == null || asset == null)
            {
                assetBundleRequest.Abort();
                assetBundleRequest = null;
                OnFail?.Invoke();

                failedRequestUrls.Add(finalUrl);
                yield break;
            }

            asset.ownerAssetBundle     = assetBundle;
            asset.assetBundleAssetName = assetBundle.name;

            assetBundlesLoader.MarkAssetBundleForLoad(asset, assetBundle, containerTransform, OnSuccess, OnFail);
        }
コード例 #3
0
        protected IEnumerator LoadAssetBundleWithDeps(string baseUrl, string hash, Action OnSuccess, Action OnFail)
        {
            string finalUrl = baseUrl + hash;

            if (failedRequestUrls.Contains(finalUrl))
            {
                OnFail?.Invoke();
                yield break;
            }

            yield return(WaitForConcurrentRequestsSlot());

            RegisterConcurrentRequest();
#if (UNITY_EDITOR || UNITY_STANDALONE)
            asyncOp = Environment.i.platform.webRequest.GetAssetBundle(url: finalUrl, hash: Hash128.Compute(hash), disposeOnCompleted: false);
#else
            //NOTE(Brian): Disable in build because using the asset bundle caching uses IDB.
            asyncOp = Environment.i.platform.webRequest.GetAssetBundle(url: finalUrl, disposeOnCompleted: false);
#endif

            if (!DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                CoroutineStarter.Start(DependencyMapLoadHelper.GetDepMap(baseUrl, hash));
            }

            yield return(DependencyMapLoadHelper.WaitUntilDepMapIsResolved(hash));

            if (DependencyMapLoadHelper.dependenciesMap.ContainsKey(hash))
            {
                using (var it = DependencyMapLoadHelper.dependenciesMap[hash].GetEnumerator())
                {
                    while (it.MoveNext())
                    {
                        var dep     = it.Current;
                        var promise = new AssetPromise_AB(baseUrl, dep, containerTransform);
                        AssetPromiseKeeper_AB.i.Keep(promise);
                        dependencyPromises.Add(promise);
                    }
                }
            }

            yield return(asyncOp);

            if (asyncOp.isDisposed)
            {
                OnFail?.Invoke();
                yield break;
            }

            if (!asyncOp.isSucceded)
            {
                if (VERBOSE)
                {
                    Debug.Log($"Request failed? {asyncOp.webRequest.error} ... {finalUrl}");
                }
                failedRequestUrls.Add(finalUrl);
                OnFail?.Invoke();
                asyncOp.Dispose();
                yield break;
            }

            UnregisterConcurrentRequest();

            foreach (var promise in dependencyPromises)
            {
                yield return(promise);
            }

            AssetBundle assetBundle = DownloadHandlerAssetBundle.GetContent(asyncOp.webRequest);
            asyncOp.Dispose();

            if (assetBundle == null || asset == null)
            {
                OnFail?.Invoke();

                failedRequestUrls.Add(finalUrl);
                yield break;
            }

            asset.ownerAssetBundle     = assetBundle;
            asset.assetBundleAssetName = assetBundle.name;

            assetBundlesLoader.MarkAssetBundleForLoad(asset, assetBundle, containerTransform, OnSuccess, OnFail);
        }