private IEnumerator CreateAssetBundle_Offset(string name, string path, ulong offset, Request request, EndLoadBundle endLoad, System.Object ud, bool assetBundle)//, bool cb_whatever) { if (Config.Detail_Debug_Log()) { Debug.LogWarning("begin create asset ---------->" + name); } AssetBundleCreateRequest result = AssetBundle.LoadFromFileAsync(path, 0, offset); yield return(result); if (Config.Detail_Debug_Log()) { Debug.LogWarning("end create asset ----------->" + name); } if (!result.isDone || result.assetBundle == null) { if (Config.Debug_Log()) { Debugger.LogError("Failed to create asset bundle: " + path + "^" + ResUpdate.ConvertPathToName(path)); } cache.Remove(name); ProcessRequest(request, (System.Object)endLoad, ud); yield break; } if (!assetBundle) { request.asset = result.assetBundle.mainAsset; if (Config.Detail_Debug_Log()) { if (result.assetBundle.mainAsset != null) { Debug.LogWarning("create asset bundle type->" + result.assetBundle.mainAsset); } } } else { request.asset = result.assetBundle; } if (request.asset == null) { UnityEngine.Object[] arr = result.assetBundle.LoadAllAssets(); if (arr != null && arr.Length > 0) { request.asset = arr[0]; if (arr.Length > 1) { for (int i = 1, count = arr.Length; i < count; i++) { Resources.UnloadAsset(arr[i]); } } } } if (request.asset == null) { if (Config.Debug_Log()) { Debugger.LogError("Failed to load asset:%s, asset is null", ResUpdate.ConvertPathToName(path)); } } request.referenceNum++; ProcessRequest(request, (System.Object)endLoad, ud); if (!assetBundle) { CoroutineHelper.CreateCoroutineHelper(AsynUnloadAssetBundle(result.assetBundle)); } }
private IEnumerator CreateAssetBundle_RelationFile(string originName, string destName, Request request, EndLoadBundle endLoad, System.Object ud) { request.raf = new RelationAssetFile(destName); request.raf.Load(); while (!request.raf.Over()) { yield return(null); } if (request.raf.GetMainAsset() == null) { if (Config.Debug_Log()) { Debugger.LogError("Failed to load asset:%s, asset is null", originName); } } request.referenceNum++; ProcessRequest(request, (System.Object)endLoad, ud); }
private void CreateAssetBundle(string originName, string destName, string path, Example.VersionFile.Type fileType, Request request, EndLoadBundle endLoad, System.Object ud, bool assetBundle)//, bool cb_whatever) { if (fileType == Example.VersionFile.Type.DEFAULT) { CoroutineHelper.CreateCoroutineHelper(CreateAssetBundle_Offset(originName, path, 0, request, endLoad, ud, assetBundle)); } else if (fileType == Example.VersionFile.Type.COMBINE_FILE) { CombineFile cf = CombineFileManager.GetInstance().GetCombineFile(destName); int offset; int size; bool encrypt; cf.GetFileDetail(originName, out offset, out size, out encrypt); if (encrypt) { Debugger.LogError("asset bundle resource in combine file should not encrypt"); return; } CoroutineHelper.CreateCoroutineHelper(CreateAssetBundle_Offset(originName, path, (ulong)offset, request, endLoad, ud, assetBundle)); } }
public void LoadBundle(string originName, string destName, string path, Example.VersionFile.Type fileType, EndLoadBundle endLoad, System.Object endLoadParam, bool assetBundle = false)//, bool cb_whatever = false) { if (path == null || path == "") { return; } Request request; if (!cache.TryGetValue(originName, out request)) { request = new Request(); cache.Add(originName, request); if (fileType == Example.VersionFile.Type.RELATION_FILE) { CoroutineHelper.CreateCoroutineHelper(CreateAssetBundle_RelationFile(originName, destName, request, endLoad, endLoadParam)); } else { CreateAssetBundle(originName, destName, path, fileType, request, endLoad, endLoadParam, assetBundle); } } else { if (request.referenceNum < 0) { if (Config.Debug_Log()) { Debugger.LogError("referencenum is invalid->" + request.referenceNum); } request.referenceNum = 0; } request.referenceNum++; if (fileType == Example.VersionFile.Type.RELATION_FILE) { if (request.raf.GetMainAsset() == null) { PushOP(request, endLoad, endLoadParam); } else { if (endLoad != null) { endLoad(request.raf.GetMainAsset(), endLoadParam); } } } else { if (request.asset == null) { PushOP(request, (System.Object)endLoad, endLoadParam); } else { if (endLoad != null) { endLoad(request.asset, endLoadParam); } } } } }