private float GetAsyncAssetProgress(string assetPath) { AssetNode assetNode = assetNodeDic[assetPath]; if (assetNode.IsLoaded()) { return(1.0f); } if (!assetNode.IsLoading()) { return(0.0f); } string bundlePath = assetDetailConfig.GetBundleByPath(assetPath); float progress = GetAsycBundleProgress(bundlePath); int progressCount = 1; string[] dependBundlePaths = bundleDetailConfig.GetDependencies(bundlePath); if (dependBundlePaths != null && dependBundlePaths.Length > 0) { progressCount += dependBundlePaths.Length; foreach (var dbp in dependBundlePaths) { progress += GetAsycBundleProgress(dbp); } } if (assetOperationDic.TryGetValue(assetPath, out var loadAsyncOperation)) { progress += loadAsyncOperation.Progress; } progressCount += 1; return(progress / progressCount); }
protected override void OnAsyncRequestUpdate(AsyncRequest request) { var result = request.result; string[] assetPaths = request.paths; for (int i = 0; i < assetPaths.Length; i++) { if (result.IsDoneAt(i)) { continue; } string assetPath = assetPaths[i]; AssetNode assetNode = assetNodeDic[assetPath]; if (assetNode.IsLoaded()) { if (request.isInstance) { request.SetUObject(i, assetNode.CreateInstance()); } else { request.SetUObject(i, assetNode.GetAsset()); } assetNode.ReleaseRef(); continue; } else { string bundlePath = assetDetailConfig.GetBundleByPath(assetPath); BundleNode bundleNode = bundleNodeDic[bundlePath]; if (bundleNode.IsDone && !assetOperationDic.ContainsKey(assetPath)) { BundleAssetAsyncOperation assetOperation = assetOperationPool.Get(); assetOperation.DoInitilize(assetPath); assetOperation.OnOperationComplete = OnAssetFromBundleCreated; assetOperationDic.Add(assetPath, assetOperation); operationLDic.Add(assetPath, assetOperation); } request.SetProgress(i, GetAsyncAssetProgress(assetPath)); } } if (result.IsDone()) { if (request.isInstance) { request.state = RequestState.InstanceFinished; } else { request.state = RequestState.LoadFinished; } } }
protected override void OnAsyncRequestUpdate(AsyncRequest request) { var result = request.result; string[] assetPaths = request.paths; for (int i = 0; i < assetPaths.Length; i++) { if (result.IsDoneAt(i)) { continue; } string assetPath = assetPaths[i]; AssetNode assetNode = assetNodeDic[assetPath]; if (assetNode.IsLoaded()) { if (request.isInstance) { request.SetUObject(i, assetNode.CreateInstance()); } else { request.SetUObject(i, assetNode.GetAsset()); } assetNode.ReleaseRef(); continue; } else { if (!operationLDic.TryGetValue(assetPath, out var assetOperation)) { assetOperation = assetOperationPool.Get(); assetOperation.DoInitilize(assetPath); assetOperation.OnOperationComplete = OnAssetLoadCompleted; operationLDic.Add(assetPath, assetOperation); } request.SetProgress(i, assetOperation.Progress); } } if (result.IsDone()) { if (request.isInstance) { request.state = RequestState.InstanceFinished; } else { request.state = RequestState.LoadFinished; } } }