Exemplo n.º 1
0
        static protected bool LoadAssetBundleInternal(CRequest req)
        {
            if (!downloadingBundles.Contains(req.key) && CacheManager.GetCache(req.keyHashCode) == null)
            {
                if (bundleMax - downloadingBundles.Count > 0)
                {
                    var op = OperationPools <LoadAssetBundleInternalOperation> .Get();

                    op.SetRequest(req);
                    inProgressOperations.Add(op);
                    op.Start();
                    downloadingBundles.Add(req.key);

                    return(true);
                }
                else
                {
                    inProgressBundleOperations.Add(req);  //wait bundle
                }
            }
            return(false);
        }
Exemplo n.º 2
0
        /// <summary>
        /// finish asset or http request
        /// </summary>
        /// <param name="operation"></param>
        internal static void ProcessFinishedOperation(ResourcesLoadOperation operation)
        {
            HttpLoadOperation httpLoad;
            var req = operation.cRequest;

            operation.Done();

            if (operation is LoadAssetBundleInternalOperation)
            {
#if DEBUG
                Profiler.BeginSample("ProcessFinishedOperation AssetbundleDone " + req.assetName);
#endif
                CallOnAssetBundleComplete(req, ((LoadAssetBundleInternalOperation)operation).assetBundle);
                downloadingBundles.Remove(req.key);
                if (req.isShared)
                {
                    req.ReleaseToPool();
                }
                operation.ReleaseToPool();
                LoadingBundleQueue();
#if DEBUG
                Profiler.EndSample();
#endif
            }
            else if ((httpLoad = operation as HttpLoadOperation) != null)
            {
                bool isError = !string.IsNullOrEmpty(httpLoad.error);
                if (isError && CUtils.IsResolveHostError(httpLoad.error) && !CUtils.IsHttps(req.url))   // http dns
                {
                    // req.error = httpLoad.error;
                    Debug.LogFormat("dns resolve error url={0} ", req.url);
                    // httpLoad.error = string.Format ("dns resolve error url={0} ", req.url);
                    var httpDnsOp = OperationPools <HttpDnsResolve> .Get(); // HttpDnsResolve.Get();

                    httpDnsOp.SetRequest(req);
                    httpDnsOp.SetOriginalOperation(httpLoad);
                    inProgressOperations.Add(httpDnsOp);
                    httpDnsOp.Start();
                }
                else
                {
#if DEBUG
                    Profiler.BeginSample("ProcessFinishedOperation HttpDone " + req.url);
#endif
                    operation.ReleaseToPool();
                    try {
                        if (isError)
                        {
                            req.DispatchEnd();
                        }
                        else
                        {
                            req.DispatchComplete();
                        }
                    } catch (System.Exception e) {
                        Debug.LogError(e);
                    }

                    if (req.group != null)
                    {
                        req.group.Complete(req, isError);
                    }

                    req.ReleaseToPool();
#if DEBUG
                    Profiler.EndSample();
#endif
                }
            }
            else
            {
#if DEBUG
                Profiler.BeginSample("ProcessFinishedOperation AssetDone " + req.assetName);
#endif
                loadingTasks.Remove(req);
                operation.ReleaseToPool();

                DispatchReqAssetOperation(req, req.error != null);
#if DEBUG
                Profiler.EndSample();
#endif
                CheckAllComplete();
            }
        }
Exemplo n.º 3
0
        static int LoadSceneAsset(CRequest request, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            totalCount++; //count ++

            if (m_MarkGroup)
            {
                m_Groupes.Add(request);
                m_TotalGroupCount++;
            }

            LoadAssetBundle(request.assetBundleName);
            int opID = 0;

#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                var assetOper = OperationPools <AssetOperationSimulation> .Get();

                assetOper.request              = request;
                assetOper.loadSceneMode        = loadSceneMode;
                assetOper.allowSceneActivation = allowSceneActivation;
                assetOper.Update();
                AssetOperation.SetId(assetOper);
                opID = assetOper.id;
                completeOper.Add(opID);

                if (inProgressOperations.Count >= maxLoading) //如果大于最大值
                {
                    waitOperations.Enqueue(assetOper);        //放入等待列表
                }
                else
                {
                    inProgressOperations.Add(assetOper);
                }
            }
            else
#endif
            {
                AssetOperation assetOper = OperationPools <AssetOperation> .Get();

                assetOper.request              = request;
                assetOper.loadSceneMode        = loadSceneMode;
                assetOper.allowSceneActivation = allowSceneActivation;
                AssetOperation.SetId(assetOper);
                opID = assetOper.id;
                completeOper.Add(opID);

                if (inProgressOperations.Count >= maxLoading) //如果大于最大值
                {
                    waitOperations.Enqueue(assetOper);        //放入等待列表
                }
                else
                {
                    inProgressOperations.Add(assetOper);
                }
            }

            // Debug.LogFormat("LoadSceneAsset({0},{1})", opID, request.assetBundleName);

            return(opID);
        }