/// <summary> /// 设置参数 /// </summary> /// <param name="_fileParameter">文件参数</param> public void SetParameter(IAssetBundleFileParameter _fileParameter) { fileParameter = _fileParameter; mLoadState = enLoadState.Wait; isDone = false; progress = 0; mIsExecuteQueue = false; }
/// <summary> /// 获得资源文件 /// </summary> /// <param name="_assetId">资源Id</param> /// <returns>资源文件参数</returns> IAssetBundleFileParameter OnGetAssetBundleFile(int _assetId) { IAssetBundleFileParameter path = default(IAssetBundleFileParameter); if (mAssetBundlePathParameterMaping.ContainsKey(_assetId)) { path = mAssetBundlePathParameterMaping[_assetId]; } return(path); }
/// <summary> /// 获得资源文件 /// </summary> /// <param name="_fileId">文件Id</param> /// <param name="_folderId">文件夹Id</param> /// <returns>资源文件参数</returns> public IAssetBundleFileParameter GetAssetBundleFile(int _fileId, int _folderId) { IAssetBundleFileParameter path = default(IAssetBundleFileParameter); if (mXLSToManifestMaping.ContainsKey(_folderId) && mXLSToManifestMaping[_folderId].ContainsKey(_fileId) && mAssetBundlePathParameterMaping.ContainsKey(mXLSToManifestMaping[_folderId][_fileId])) { path = mAssetBundlePathParameterMaping[mXLSToManifestMaping[_folderId][_fileId]]; } return(path); }
/// <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="_fileId">文件Id</param> /// <param name="_folderId">文件夹Id</param> /// <returns>资源</returns> public string GetTextAssetDirect(int _fileId, int _folderId) { string result = string.Empty; IAssetBundleFileParameter file = StrayFogGamePools.assetBundleManager.GetAssetBundleFile(_fileId, _folderId); XLS_Config_View_AssetDiskMaping config = StrayFogGamePools.assetBundleManager.GetAssetDiskMaping(_fileId, _folderId); if (file != null) { TextAsset ta = GetAssetDirect <TextAsset>(config.fileName, file.assetBundlePath); if (ta != null) { result = ta.text; } } return(result); }
/// <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)); } }
/// <summary> /// 设置参数 /// </summary> /// <param name="_fileParameter">文件参数</param> public void SetParameter(IAssetBundleFileParameter _fileParameter) { mFileParameter = _fileParameter; }
/// <summary> /// 收集磁盘映射 /// </summary> void OnCollectAssetDiskMaping() { #if UNITY_EDITOR string editorABPN = typeof(IAssetBundleFileParameter).Name; string editorManifestN = typeof(AssetBundleManifest).Name; string editorXLSN = typeof(XLS_Config_View_AssetDiskMaping).Name; System.Diagnostics.Stopwatch watch = new System.Diagnostics.Stopwatch(); watch.Start(); #endif if (mAssetBundleManifest != null) { string[] names = mAssetBundleManifest.GetAllAssetBundles(); if (names != null && names.Length > 0) { foreach (string n in names) { IAssetBundleFileParameter abmp = new AssetBundleFileParameter(n); if (!mAssetBundlePathParameterMaping.ContainsKey(abmp.assetBundleId)) { mAssetBundlePathParameterMaping.Add(abmp.assetBundleId, abmp); } } } #if UNITY_EDITOR watch.Stop(); Debug.LogFormat("Collection {0} from 【Manifest =>{1}】,Time:{2}", editorABPN, mAssetBundlePathParameterMaping.Count, watch.Elapsed); watch.Reset(); #endif } #if UNITY_EDITOR int beforeCollectXlsConfigABMPC = mAssetBundlePathParameterMaping.Count; watch.Start(); #endif IAssetBundleFileParameter tempAbp = null; mXLS_Config_View_AssetDiskMaping.Clear(); StrayFogConfigHelper.AddLoadViewFromXLS(StrayFogSQLiteEntityHelper_OnEventHandlerLoadViewFromXLS <XLS_Config_View_AssetDiskMaping>); List <XLS_Config_View_AssetDiskMaping> mapings = StrayFogConfigHelper.Select <XLS_Config_View_AssetDiskMaping>(); if (mapings.Count > 0) { foreach (XLS_Config_View_AssetDiskMaping v in mapings) { if (!mXLS_Config_View_AssetDiskMaping.ContainsKey(v.folderId)) { mXLS_Config_View_AssetDiskMaping.Add(v.folderId, new Dictionary <int, XLS_Config_View_AssetDiskMaping>()); } if (!mXLS_Config_View_AssetDiskMaping[v.folderId].ContainsKey(v.fileId)) { mXLS_Config_View_AssetDiskMaping[v.folderId].Add(v.fileId, v); } if (!mXLSToManifestMaping.ContainsKey(v.folderId)) { mXLSToManifestMaping.Add(v.folderId, new Dictionary <int, int>()); } if (!mXLSToManifestMaping[v.folderId].ContainsKey(v.fileId)) { mXLSToManifestMaping[v.folderId].Add(v.fileId, 0); } if (StrayFogGamePools.setting.isUseAssetBundle) { tempAbp = new AssetBundleFileParameter(v.outAssetPath); } else { tempAbp = new AssetBundleFileParameter(v.inAssetPath); } if (!mAssetBundlePathParameterMaping.ContainsKey(tempAbp.assetBundleId)) { mAssetBundlePathParameterMaping.Add(tempAbp.assetBundleId, tempAbp); } #if UNITY_EDITOR if (mXLSToManifestMaping[v.folderId][v.fileId] != 0 && mXLSToManifestMaping[v.folderId][v.fileId] != tempAbp.assetBundleId) { Debug.LogErrorFormat("Asset 【{0}】【{1}_{2}】has the two assetId 【{3}_{4}】【{5}_{6}】", v.inAssetPath, v.folderId, v.fileId, mAssetBundlePathParameterMaping[mXLSToManifestMaping[v.folderId][v.fileId]].assetBundleId, mAssetBundlePathParameterMaping[mXLSToManifestMaping[v.folderId][v.fileId]].assetBundlePath, tempAbp.assetBundleId, tempAbp.assetBundlePath ); } #endif mXLSToManifestMaping[v.folderId][v.fileId] = tempAbp.assetBundleId; } } StrayFogConfigHelper.RemoveLoadViewFromXLS(StrayFogSQLiteEntityHelper_OnEventHandlerLoadViewFromXLS <XLS_Config_View_AssetDiskMaping>); #if UNITY_EDITOR watch.Stop(); Debug.LogFormat("Collection {0} from 【{1}=> {2}】,Time: {3}", editorABPN, editorXLSN, mapings.Count, watch.Elapsed); Debug.LogFormat("Collection {0} between {1} and {2} different【{3}】,Time:{4}", editorABPN, editorManifestN, editorXLSN, mAssetBundlePathParameterMaping.Count - beforeCollectXlsConfigABMPC, watch.Elapsed); watch.Reset(); #endif }