/// <summary> /// 加载资源对象 /// </summary> /// <param name="assetName">资源对象名称</param> /// <param name="assetType">资源对象类型</param> /// <param name="callback">结果回调</param> public void LoadAsset(string assetName, System.Type assetType, System.Action <UnityEngine.Object> callback) { // 如果已经提交相同请求 AssetObjectLoader loader = TryGetAssetObjectLoaderInternal(assetName); if (loader != null) { if (loader.IsDone()) { callback?.Invoke(loader.AssetObject); } else { loader.LoadCallback += callback; } } else { // 创建加载器 AssetObjectLoader newLoader = new AssetObjectLoader(_cacheBundle, assetName, assetType); // 新增下载需求 _assetObjectLoaders.Add(newLoader); newLoader.LoadCallback = callback; newLoader.Update(); //立刻轮询 } }
public override void LoadMainAsset(EAssetType assetType, OnAssetObjectLoad callback) { // Check error if (LoadState != EAssetFileLoadState.LoadAssetFileOK) { LogSystem.Log(ELogType.Error, $"Can not load asset object, {nameof(AssetBundleLoader)} is not ok : {LoadPath}"); callback?.Invoke(null, false); return; } // Check secne // 注意:场景文件在获取资源对象的时候直接返回成功 if (assetType == EAssetType.Scene) { callback?.Invoke(null, true); return; } // 如果加载器不存在 if (_mainAssetLoader == null) { string assetName = AssetSystem.GetCacheFileName(LoadPath); _mainAssetLoader = new AssetObjectLoader(_cacheBundle, assetName, assetType); _mainAssetLoader.LoadCallback = callback; _mainAssetLoader.Update(); //立刻轮询 } else { if (_mainAssetLoader.IsDone()) { callback?.Invoke(_mainAssetLoader.AssetObject, _mainAssetLoader.LoadState == EAssetObjectLoadState.LoadAssetObjectOK); } else { _mainAssetLoader.LoadCallback += callback; } } }