示例#1
0
        /// <summary>
        /// real load assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected AssetBundleDownloadOperation LoadAssetBundleInternal(CRequest req)
        {
            AssetBundleDownloadOperation abDownloadOp = null;

            if (!downloadingBundles.TryGetValue(req.key, out abDownloadOp))
            {
                req.url = GetAssetBundleDownloadingURL(req.vUrl); // set full url

                if (req.url.StartsWith(Common.HTTP_STRING))       //load assetbunlde
                {
                    abDownloadOp = AssetBundleDownloadFromWebOperation.Get();
                }
                else
                {
                    abDownloadOp = AssetBundleDownloadFromDiskOperation.Get();
                }
                abDownloadOp.SetRequest(req);
                downloadingBundles.Add(req.key, abDownloadOp);

                CacheData cached = null;
                CacheManager.CreateOrGetCache(req.keyHashCode, out cached);//cache data
                inProgressBundleOperations.Add(abDownloadOp);
                abDownloadOp.BeginDownload();

#if HUGULA_LOADER_DEBUG
                HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.2 LoadAssetBundleInternal Request(key={0},isShared={1},assetname={2},dependencies.count={4})keyHashCode{3}, frameCount{5}</color>", req.key, req.isShared, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif
            }
            else if (req.isShared)
            {
                req.ReleaseToPool();
            }

            return(abDownloadOp);
        }
示例#2
0
        //========================================
        //--------------- assetbundle asset logic--------------------
        //========================================

        /// <summary>
        /// Insert AssetBundleLoadAssetOperation to inProgressOperations list
        /// </summary>
        /// <param name="operation"></param>
        static void InsertAssetBundleLoadAssetOperation(AssetBundleDownloadOperation operation)
        {
            ResourcesLoadOperation rp = operation.next;

            while (rp != null)
            {
                inProgressOperations.Add(rp);
                rp = rp.next;
            }
        }
示例#3
0
        /// <summary>
        /// real load assetbundle
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        static protected AssetBundleDownloadOperation LoadAssetBundleInternal(CRequest req)
        {
            AssetBundleDownloadOperation abDownloadOp = null;

            if (!downloadingBundles.TryGetValue(req.key, out abDownloadOp))
            {
#if HUGULA_PROFILER_DEBUG
                Profiler.BeginSample(string.Format("LoadAssetBundleInternal ({0},{1},{2})", req.assetName, req.key, req.isShared));
#endif
                if (!UriGroup.CheckRequestCurrentIndexCrc(req)) //crc
                {
                    abDownloadOp       = new AssetBundleDownloadErrorOperation();
                    abDownloadOp.error = string.Format("assetbundle({0}) crc check wrong ", req.key);
                }
                else if (req.url.StartsWith(Common.HTTP_STRING))  //load assetbunlde
                {
                    abDownloadOp = AssetBundleDownloadFromWebOperation.Get();
                }
                else
                {
                    abDownloadOp = AssetBundleDownloadFromDiskOperation.Get();
                }
                abDownloadOp.SetRequest(req);
                downloadingBundles.Add(req.key, abDownloadOp);
                CacheData cached = null;
                CacheManager.CreateOrGetCache(req.keyHashCode, out cached);//cache data
                //load now
                if (bundleMax - inProgressBundleOperations.Count > 0)
                {
                    inProgressBundleOperations.Add(abDownloadOp);
                    abDownloadOp.BeginDownload();
                }
                else
                {
                    bundleQueue.Enqueue(abDownloadOp);
                }
#if HUGULA_LOADER_DEBUG
                HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.2 LoadAssetBundleInternal Request(key={0},isShared={1},assetname={2},dependencies.count={4})keyHashCode{3}, frameCount{5}</color>", req.key, req.isShared, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif

#if HUGULA_PROFILER_DEBUG
                Profiler.EndSample();
#endif
            }
            else if (req.isShared)
            {
                req.ReleaseToPool();
            }

            return(abDownloadOp);
        }
示例#4
0
        /// <summary>
        /// finish assetbundle
        /// </summary>
        /// <param name="operation"></param>
        static void ProcessFinishedBundleOperation(AssetBundleDownloadOperation operation)
        {
#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("ResourcesLoader.ProcessFinishedBundleOperation CRequest({0},shared={1})", operation.cRequest.assetName, operation.cRequest.isShared));
#endif
            var  req     = operation.cRequest;
            bool isError = operation.assetBundle == null;
            var  ab      = operation.assetBundle;
            AssetBundleDownloadOperation download = operation;
            if (!isError)
            {
                CacheManager.AddSourceCacheDataFromWWW(ab, req);
            }
            else
            {
#if UNITY_EDITOR
                Debug.LogWarning(operation.error);
#endif
                CacheManager.AddErrorSourceCacheDataFromReq(req);
            }
#if HUGULA_LOADER_DEBUG
            HugulaDebug.FilterLogFormat(req.key, "<color=#10f010>1.9  ProcessFinishedBundleOperation AssetBundle Loaded Request(url={0},assetname={1},dependencies.count={3},keyHashCode{2}),isError={4} frameCount{5}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, isError, Time.frameCount);
#endif

            //begin load asset
            InsertAssetBundleLoadAssetOperation(download);

            downloadingBundles.Remove(req.key);
            download.ReleaseToPool();

            if (isError)
            {
                CallOnAssetBundleErr(req);
            }
            else
            {
                CallOnAssetBundleComplete(req, ab);
            }

            if (req.isShared)
            {
                req.ReleaseToPool();
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif
        }
示例#5
0
        /// <summary>
        /// load assetbundle
        /// </summary>
        /// <param name="req"></param>
        static protected void LoadAssetBundle(CRequest req)
        {
#if UNITY_EDITOR
            if (ManifestManager.SimulateAssetBundleInEditor)
            {
                //load asset
                ResourcesLoadOperation operation1;
                var tp1 = req.assetType;

                if (req.assetOperation != null)
                {
                    operation1 = req.assetOperation;
                }
                else if (CacheManager.Typeof_ABScene.Equals(tp1))
                {
                    operation1 = new AssetBundleLoadLevelSimulationOperation();
                    operation1.SetRequest(req);
                }
                else
                {
                    operation1 = new AssetBundleLoadAssetOperationSimulation();
                    operation1.SetRequest(req);
                }

                bool isLoading1 = false;

                if (operation1 is AssetBundleLoadAssetOperation)
                {
                    isLoading1 = AddAssetBundleLoadAssetOperationToCallBackList((AssetBundleLoadAssetOperation)operation1);
                }

                if (!isLoading1)
                {
                    inProgressOperations.Add(operation1);
                    loadingTasks.Add(req);
                }
                return;
            }
#endif
            //remove delay unload assetbundle
            ABDelayUnloadManager.CheckRemove(req.keyHashCode);

            //check load asset from cache
            if (LoadAssetFromCache(req))
            {
                DispatchReqAssetOperation(req, false);
                return;
            }

            totalCount++;//count ++
#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadAssetBundle ({0},{1},{2}) LoadDependencies and LoadAssetBundleInternal", req.assetName, req.key, req.isShared));
#endif
            AssetBundleDownloadOperation abDownloadOperation = null;

            if (downloadingBundles.TryGetValue(req.key, out abDownloadOperation)) //check is loading
            {
            }
            else if (CheckAssetBundleCanLoad(req)) //need load
            {
                //load dependencies and refrenece count
                if (ManifestManager.fileManifest != null)
                {
                    req.dependencies = LoadDependencies(req); //load dependencies assetbundle
                }
                //load assetbundle
                abDownloadOperation = LoadAssetBundleInternal(req);
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif

#if HUGULA_PROFILER_DEBUG
            Profiler.BeginSample(string.Format("LoadAssetBundle  ({0},{1},{2}) to inProgressOperations", req.assetName, req.key, req.isShared));
#endif
            //load asset
            ResourcesLoadOperation operation;
            var tp = req.assetType;

            if (req.assetOperation != null)
            {
                operation = req.assetOperation;
            }
            else if (CacheManager.Typeof_ABScene.Equals(tp))
            {
                operation = new AssetBundleLoadLevelOperation();
                operation.SetRequest(req);
            }
            else
            {
                operation = AssetBundleLoadAssetOperationFull.Get();
                operation.SetRequest(req);
            }

            bool isLoading = false;
            //the same asset be one Operation
            if (operation is AssetBundleLoadAssetOperation)
            {
                isLoading = AddAssetBundleLoadAssetOperationToCallBackList((AssetBundleLoadAssetOperation)operation);
            }

            if (!isLoading)
            {
                if (abDownloadOperation != null)
                {
                    abDownloadOperation.AddNext(operation);//wait for assetbunle complete
                }
                else
                {
                    inProgressOperations.Add(operation);// the assetbundle is done
                }
                loadingTasks.Add(req);
            }
#if HUGULA_PROFILER_DEBUG
            Profiler.EndSample();
#endif
#if HUGULA_LOADER_DEBUG
            HugulaDebug.FilterLogFormat(req.key, "<color=#15A0A1>2.0 LoadAssetBundle Asset Request(url={0},assetname={1},dependencies.count={3})keyHashCode{2}, frameCount{4}</color>", req.url, req.assetName, req.keyHashCode, req.dependencies == null ? 0 : req.dependencies.Length, Time.frameCount);
#endif
        }