Exemple #1
0
        /// <summary>
        /// 放入加载队列开始加载assetbundle
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <param name="async">异步加载</param>
        /// <returns></returns>
        static void LoadAssetBundleInternal(string assetBundleName, bool async)
        {
            CacheData cache = CacheManager.TryGetCache(assetBundleName);

            if (cache.canUse)
            {
                return;               //可以使用
            }
            // bool isIn = downloadingBundles.Contains(assetBundleName);//正在队列中

            if (async && !downloadingBundles.Contains(assetBundleName)) //异步加载
            {
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                inBundleProgressOperations.Add(op);
                downloadingBundles.Add(assetBundleName);
            }
            else if (!async && cache.state != CacheData.CacheDataState.Loading) //如果是同步加载,
            {
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                op.StartSync(); //同步加载
                op.ReleaseToPool();
            }
            else if (!async)
            {
                Debug.LogWarningFormat("the assetbundle({0}) can't be sync loaded 因为它正在异步加载中!", assetBundleName);
            }
        }
Exemple #2
0
        static protected void LoadWebHttpInternal(CRequest req)
        {
            var op = OperationPools <HttpWebRequestOperation> .Get();

            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.Start();
        }
Exemple #3
0
        /// <summary>
        /// 加载资源
        /// </summary>
        /// <param name="CRequest">request</param>
        /// <param name="bool">async = true 异步加载</param>
        /// <returns></returns>
        static int LoadAsset(CRequest request, bool async = true, bool subAssets = false)
        {
            totalCount++; //count ++

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

            int opID = 0;

            LoadAssetBundle(request.assetBundleName, async);
#if UNITY_EDITOR
            if (SimulateAssetBundleInEditor)
            {
                AssetOperationSimulation assetOperS = OperationPools <AssetOperationSimulation> .Get();

                assetOperS.request   = request;
                assetOperS.subAssets = subAssets;
                assetOperS.StartSync();

                assetOperS.ReleaseToPool();
                DispatchReqAssetOperation(request, request.error != null, 0, false); //模拟器模式下只有同步所以需要调用回调
                CheckAllComplete();
            }
            else
#endif
            {
                var assetOper = OperationPools <AssetOperation> .Get();

                assetOper.request   = request;
                assetOper.subAssets = subAssets;
                if (async) //如果异步加载 设置id可以阻止回调
                {
                    AssetOperation.SetId(assetOper);
                    opID = assetOper.id;
                    completeOper.Add(opID);
                }

                if (!async) //同步加载
                {
                    assetOper.StartSync();
                    assetOper.ReleaseToPool();
                }
                // else if (inProgressOperations.Count >= maxLoading) //如果大于最大值
                // {
                //     waitOperations.Enqueue(assetOper); //放入等待列表
                // }
                else
                {
                    inProgressOperations.Add(assetOper);
                }
                // Debug.LogFormat("LoadAsset({0},{1},{2})", opID, request.assetBundleName,request.assetName);
            }
            return(opID);
        }
Exemple #4
0
        static int LoadSceneAsset(CRequest request, bool allowSceneActivation = true, LoadSceneMode loadSceneMode = LoadSceneMode.Additive)
        {
            totalCount++; //count ++
            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);
        }
Exemple #5
0
        /// <summary>
        /// 放入加载队列开始加载assetbundle
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <param name="async">异步加载</param>
        /// <returns></returns>
        static void LoadAssetBundleInternal(string assetBundleName, bool async)
        {
            CacheData cache = CacheManager.TryGetCache(assetBundleName);

            if (cache.canUse)
            {
                return;                                                 //可以使用
            }
            if (async && !downloadingBundles.Contains(assetBundleName)) //异步加载
            {
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                inBundleProgressOperations.Add(op);
                downloadingBundles.Add(assetBundleName);
#if HUGULA_CACHE_DEBUG
                Debug.LogFormat("LoadAssetBundleInternalAsync({0},async=true),isloading = false", assetBundleName);
#endif
            }
            else if (!async)// && cache.state != CacheData.CacheDataState.Loading) //如果是同步加载,
            {
                //cancel async loader
                if (cache.state == CacheData.CacheDataState.Loading) //异步加载中需要终止done
                {
                    foreach (var opAsync in inBundleProgressOperations)
                    {
                        if (string.Equals(opAsync.assetBundleName, assetBundleName))
                        {
                            opAsync.CancelAsyncDone();
#if UNITY_EDITOR
                            Debug.LogWarningFormat("CancelAsyncDone({0}", assetBundleName);
#endif
                            break;
                        }
                    }
                }
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                op.StartSync(); //同步加载
                op.ReleaseToPool();
            }
#if UNITY_EDITOR && HUGULA_CACHE_DEBUG
            else //if (!async)
            {
                Debug.LogWarningFormat("the assetbundle({0}) 正在异步加载中!", assetBundleName);
            }
#endif
        }
Exemple #6
0
        static protected void LoadAssetInternalSimulation(CRequest req)
        {
            ResourcesLoadOperation op = null;

            if (LoaderType.Typeof_ABScene.Equals(req.assetType))
            {
                op = OperationPools <LoadLevelOperationSimulation> .Get();
            }
            else
            {
                op = OperationPools <LoadAssetOperationSimulation> .Get();
            }

            op.SetRequest(req);
            inProgressOperations.Add(op);
            op.Start();
        }
Exemple #7
0
        /// <summary>
        /// 放入加载队列开始加载assetbundle
        /// </summary>
        /// <param name="assetBundleName"></param>
        /// <param name="async">异步加载</param>
        /// <returns></returns>
        static void LoadAssetBundleInternal(string assetBundleName, bool async)
        {
            CacheData cache = CacheManager.TryGetCache(assetBundleName);

            if (cache.canUse)
            {
                return;                                                 //可以使用
            }
            if (async && !downloadingBundles.Contains(assetBundleName)) //异步加载
            {
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                inBundleProgressOperations.Add(op);
                downloadingBundles.Add(assetBundleName);
            }
            else if (!async)// && cache.state != CacheData.CacheDataState.Loading) //如果是同步加载,
            {
                //cancel async loader
                if (cache.state == CacheData.CacheDataState.Loading) //异步加载中需要终止done
                {
                    foreach (var opAsync in inBundleProgressOperations)
                    {
                        if (string.Equals(opAsync.assetBundleName, assetBundleName))
                        {
                            opAsync.CancelAsyncDone();
                            break;
                        }
                    }
                }
                var op = OperationPools <BundleOperation> .Get();

                op.assetBundleName = assetBundleName;
                op.StartSync(); //同步加载
                op.ReleaseToPool();
            }
            // else if (!async)
            // {
            //     Debug.LogWarningFormat("the assetbundle({0}) can't be sync loaded 因为它正在异步加载中!", assetBundleName);
            // }
        }
Exemple #8
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);
        }
Exemple #9
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();
            }
        }
Exemple #10
0
 public new void ReleaseToPool()
 {
     OperationPools <AssetOperation> .Release(this);
 }
Exemple #11
0
 public void ReleaseToPool()
 {
     OperationPools <BundleOperation> .Release(this);
 }
Exemple #12
0
 public override void ReleaseToPool()
 {
     OperationPools <LoadLevelOperationSimulation> .Release(this);
 }
Exemple #13
0
 public override void ReleaseToPool()
 {
     OperationPools <HttpDnsResolve> .Release(this);
 }
Exemple #14
0
 public override void ReleaseToPool()
 {
     OperationPools <HttpWebRequestOperation> .Release(this);
 }
Exemple #15
0
 public override void ReleaseToPool()
 {
     OperationPools <LoadAssetOperation> .Release(this);
 }
Exemple #16
0
 public override void ReleaseToPool()
 {
     OperationPools <LoadAssetBundleInternalOperation> .Release(this);
 }