void D_OnLoadAssetBundleComplete(AssetBundleMonoBehaviour _mono) { bool isLoadAllDependencies = true; if (mDependencies != null && mDependencies.Length > 0) { float temP = 0; foreach (AssetBundleMonoBehaviour d in mDependencies) { temP += d.progress; isLoadAllDependencies &= d.isDone; } progress = temP / (mDependencies.Length + 1); foreach (IAssetBundleRequestInMemory q in mQueueRequest) { q.progressEvent?.Invoke(progress, q.input); } } if (isLoadAllDependencies && mLoadState == enLoadState.Dependencies) { if (fileParameter.isUseAssetBundle) { mLoadState = enLoadState.AssetBundle; AssetBundleCreateRequest requestAssetBundle = AssetBundle.LoadFromFileAsync(fileParameter.assetBundlePath); requestAssetBundle.completed += RequestAssetBundle_completed; } else { mLoadState = enLoadState.Ready; OnExecuteQueueRequest(); } } }
/// <summary> /// 创建组件 /// </summary> /// <param name="_fileParameter">文件参数</param> /// <returns>组件</returns> AssetBundleMonoBehaviour OnCreateMono(IAssetBundleFileParameter _fileParameter) { if (!mAssetBundleMonoBehaviourMaping.ContainsKey(_fileParameter.assetBundleId)) { GameObject go = new GameObject(_fileParameter.assetBundleName); go.hideFlags = gameObject.hideFlags; go.transform.SetParent(gameObject.transform); AssetBundleMonoBehaviour mono = go.AddDynamicComponent <AssetBundleMonoBehaviour>(); mono.OnRequestLoadDependencies += Mono_OnRequestLoadDependencies; mono.SetParameter(_fileParameter); mAssetBundleMonoBehaviourMaping.Add(_fileParameter.assetBundleId, mono); } return(mAssetBundleMonoBehaviourMaping[_fileParameter.assetBundleId]); }
/// <summary> /// 请求加载依赖项 /// </summary> /// <param name="_request">请求资源</param> /// <returns>依赖资源</returns> AssetBundleMonoBehaviour[] Mono_OnRequestLoadDependencies(AssetBundleMonoBehaviour _request) { AssetBundleMonoBehaviour[] result = null; if (_request.fileParameter.isUseAssetBundle) { string[] deps = mAssetBundleManifest.GetDirectDependencies(_request.fileParameter.assetBundleName); if (deps != null && deps.Length > 0) { result = new AssetBundleMonoBehaviour[deps.Length]; for (int i = 0; i < deps.Length; i++) { IAssetBundleFileParameter file = OnGetAssetBundleFile(deps[i].UniqueHashCode()); result[i] = OnCreateMono(file); result[i].BeginLoad(); } } } return(result); }
/// <summary> /// 加载资源到内存 /// </summary> /// <param name="_fileId">文件Id</param> /// <param name="_folderId">文件夹Id</param> /// <param name="_outputEvent">输出</param> /// <param name="_progressEvent">进度</param> /// <param name="_extraParemeter">额外参数</param> void OnLoadAssetInMemory(int _fileId, int _folderId, Action <IAssetBundleOutput> _outputEvent, Action <float, IAssetBundleInput> _progressEvent, params object[] _extraParemeter) { XLS_Config_View_AssetDiskMaping config = GetAssetDiskMaping(_fileId, _folderId); if (config != null) { IAssetBundleFileParameter file = GetAssetBundleFile(_fileId, _folderId); AssetBundleMonoBehaviour mono = OnCreateMono(file); IAssetBundleInput input = new AssetBundleInput(config, _extraParemeter); IAssetBundleRequestInMemory request = new AssetBundleRequestInMemory(input, _outputEvent, _progressEvent); mono.Request(request); mono.BeginLoad(); } else { throw new UnityException(string.Format("Can't find XLS_Config_View_AssetDiskMaping for 【folderId:{0}】【fileId:{1}】", _folderId, _fileId)); } }