コード例 #1
0
        bool LoadAssetBundleInternal(string _dir, string _packageName, List <UAssetBundleCreateRequest> _requests, Func <string, AssetBundleCreateRequest> _getCreateRequest)
        {
            //> 检查并加载这个模块的关系依赖文件
            string moduleName     = UAssetBundleManifestManager.ParseModuleName(_packageName);
            string fullModuleName = GetAssetBundlePath(_dir, moduleName, moduleName);
            string fullPackgeName = GetAssetBundlePath(_dir, moduleName, _packageName);

            if (false == ManifestManager.Contains(fullModuleName))
            {
                //> 加载依赖关系文件
                string content = LoadPathText(fullModuleName);
                ManifestManager.AddManifest(fullModuleName, content);
            }

            //> 如果他已经在完成列表中,那么将他的引用++
            if (PackageManager.ApplyPackage(fullPackgeName) != null)
            {
                //> 已经加载完成了
                return(true);
            }

            UAssetBundleCreateRequest outRequest;

            if (PackageManager.TryGetRequest(fullModuleName, out outRequest))
            {
                //> 已经处于加载状态了
                _requests.Add(outRequest);
                return(true);
            }

            string path = fullPackgeName + "." + Manager.PackageExtension;
            AssetBundleCreateRequest createRequest = _getCreateRequest(path);

            if (createRequest == null || createRequest.isDone && createRequest.assetBundle == null)
            {
                //> 执行加载操作失败了
                PackageManager.RemPackage(fullPackgeName, 1, true);
                return(true);
            }
            else
            {
                var request = new UAssetBundleCreateRequestUnity(createRequest, fullPackgeName, (NAME, VALUE) =>
                {
                    PackageManager.CompleteRequest(fullPackgeName, VALUE);
                });
                //> 成功执行了加载
                PackageManager.AddRequest(fullPackgeName, request);
                _requests.Add(request);
                return(false);
            }
        }