Esempio n. 1
0
        internal AssetBundleAsyncLoader CreateLoader(string abFileName)
        {
            AssetBundleAsyncLoader loader = null;
            string bundleName             = abFileName;

            if (_loaderCache.ContainsKey(bundleName))
            {
                loader = _loaderCache[bundleName];
            }
            else
            {
                AssetBundleInfo abInfo = VersionManager.Instance.GetAssetBundleInfo(bundleName);
                if (string.IsNullOrEmpty(abInfo.AssetBundleName))
                {
                    DebugUtil.LogError("### abInfo Error: ###" + abFileName);
                }

                loader = new AssetBundleAsyncLoader
                {
                    assetBundleInfo = abInfo
                };
                _loaderCache.Add(bundleName, loader);
            }

            return(loader);
        }
        // 加载所有依赖包
        void LoadDepends()
        {
            if (depLoaders == null && assetBundleInfo.DependenciesBundleNames != null && assetBundleInfo.DependenciesBundleNames.Length > 0)
            {
                depLoaders = new List <AssetBundleAsyncLoader>();
                for (int i = 0; i < assetBundleInfo.DependenciesBundleNames.Length; i++)
                {
                    if (ResourcesManager.Instance.AssetBundleCache.GetAssetBundle(assetBundleInfo.DependenciesBundleNames[i]) == null)
                    {
                        depLoaders.Add(ResourcesManager.Instance.CreateLoader(assetBundleInfo.DependenciesBundleNames[i]));
                    }
                }
            }

            _currentLoadingDepCount = 0;
            if (depLoaders != null)
            {
                for (int i = 0; i < depLoaders.Count; i++)
                {
                    AssetBundleAsyncLoader depLoader = depLoaders[i];
                    if (!depLoader.IsComplete)
                    {
                        _currentLoadingDepCount++;
                        depLoader.onComplete += OnDepComplete;
                        depLoader.Start();
                    }
                }
            }

            this.CheckDepComplete();
        }
Esempio n. 3
0
 internal void Enqueue(AssetBundleAsyncLoader loader)
 {
     if (_requestRemain < 0)
     {
         _requestRemain = 0;
     }
     _requestQueue.Add(loader);
 }
Esempio n. 4
0
 void LoadBundleAsync(AssetBundleAsyncLoader loader)
 {
     if (!loader.IsComplete)
     {
         loader.LoadBundle();
         _requestRemain--;
     }
 }
Esempio n. 5
0
 void CheckQueue()
 {
     while (_requestRemain > 0 && _requestQueue.Count > 0)
     {
         AssetBundleAsyncLoader loader = _requestQueue[0];
         _requestQueue.RemoveAt(0);
         LoadBundleAsync(loader);
     }
 }
Esempio n. 6
0
        internal void LoadComplete(AssetBundleAsyncLoader loader)
        {
            _requestRemain++;
            AssetBundleCache.AddAssetBundle(loader.AssetBundle, loader.assetBundleInfo);
            _currentLoadQueue.Remove(loader);

            if (_currentLoadQueue.Count == 0 && _nonCompleteLoaderSet.Count == 0)
            {
                _isCurrentLoading = false;
                //Application.backgroundLoadingPriority = ThreadPriority.Low;
            }
        }
Esempio n. 7
0
        public AssetBundleAsyncLoader LoadAssetBundleAsync(string path, AssetBundleAsyncLoader.LoaderCompleteHandler handler = null)
        {
            string normalizepath          = FilePathTools.NormalizePath(path.ToLower());
            AssetBundleAsyncLoader loader = this.CreateLoader(normalizepath);

            loader.onComplete += handler;
            if (!_isCurrentLoading)
            {
                _isCurrentLoading = true;
                //Application.backgroundLoadingPriority = ThreadPriority.High;
            }
            _nonCompleteLoaderSet.Add(loader);
            return(loader);
        }
Esempio n. 8
0
 internal void LoadError(AssetBundleAsyncLoader loader)
 {
     DebugUtil.LogError("### Cant load AB : " + loader.assetBundleInfo.AssetBundleName + " ###");
     LoadComplete(loader);
 }
 void OnDepComplete(AssetBundleAsyncLoader aba)
 {
     _currentLoadingDepCount--;
     this.CheckDepComplete();
 }