/// <summary> ///只在编辑器下可用 /// </summary> /// <param name="bridgeLoader"></param> /// <param name="url"></param> /// <param name="isloadScene"> 如果加载的是场景 则这里必须填true ,否则false</param> /// <returns></returns> private void LoadAssetByPriority_Editor(string url, BridgeLoader bridgeLoader, bool isloadSceneAsset) { LoadAssetPathEnum curLoadAssetPathEnum = ApplicationConfig.GetDefaultEditorLoadAssetPath(); string fileName = System.IO.Path.GetFileNameWithoutExtension(url); if (curLoadAssetPathEnum == LoadAssetPathEnum.ResourcesPath) { bridgeLoader.m_ConnectLoader = ResourcesLoader.LoadResourcesAsset(url, LoadAssetModel.Sync, null, isloadSceneAsset); if (bridgeLoader.m_ConnectLoader.ResultObj != null) { return; } else { Debug.LogError("加载资源失败 url" + url); } } Debug.LogError("LoadAssetByPriority_Editor Fail, 无法识别的模式 " + curLoadAssetPathEnum); }
/// <summary> /// 根据配置的路径加载优先级 选择合适的加载器加载资源 (可能存在加载不到资源的情况,目前只处理LoadAssetPathEnum.PersistentDataPath和PersistentDataPath.ResourcesPath) /// </summary> /// <param name="bridgeLoader"></param> /// <param name="url"></param> /// <param name="isloadScene"> 如果加载的是场景 则这里必须填true ,否则false</param> /// <returns></returns> private IEnumerator LoadAssetByPriorityAsync(string url, BridgeLoader bridgeLoader, bool isloadSceneAsset) { LoadAssetPathEnum curLoadAssetPathEnum = ApplicationConfig.Instance.GetFirstPriortyAssetPathEnum(); //加载的优先级 string fileName = System.IO.Path.GetFileNameWithoutExtension(url); do { if (curLoadAssetPathEnum == LoadAssetPathEnum.PersistentDataPath) { AssetBundleExitState assetBundleExitState; string newUrl = HotUpdate.AssetBundleMgr.Instance.CheckIfAssetBundleAsset(url.ToLower(), out assetBundleExitState); if (assetBundleExitState != AssetBundleExitState.None) { Debug.Log("[AssetBundler ]加载外部资源,且以AssetBundle 加载"); bridgeLoader.m_ConnectLoader = NewAssetBundleLoader3.LoadAssetBundleAsset(newUrl, fileName, LoadAssetModel.Async, assetBundleExitState, isloadSceneAsset); //整体打包的资源 } else { if (isloadSceneAsset == false) { Debug.Log("[byteLoader ]优先加载外部资源,但是不是AssetBundle 资源,则以Byte[] 尝试 加载"); string path = url; if (url.StartsWith(ConstDefine.S_AssetBundleTopPath) == false) { path = ConstDefine.S_AssetBundleTopPath + url; } bridgeLoader.m_ConnectLoader = ByteLoader.LoadAsset(path, LoadAssetModel.Async, null); } else { //***场景资源不通过这种方式 } } } else if (curLoadAssetPathEnum == LoadAssetPathEnum.ResourcesPath) { Debug.Log("[RecourcsLoader ] 加载Resources 资源 " + url); bridgeLoader.m_ConnectLoader = ResourcesLoader.LoadResourcesAsset(url, LoadAssetModel.Async, null, isloadSceneAsset); } while (bridgeLoader.m_ConnectLoader.IsCompleted == false) { yield return(null); } if (curLoadAssetPathEnum == LoadAssetPathEnum.PersistentDataPath && (bridgeLoader.m_ConnectLoader.GetType() == typeof(NewAssetBundleLoader3))) { NewAssetBundleLoader3 assetBundleLoader = bridgeLoader.m_ConnectLoader as NewAssetBundleLoader3; if (assetBundleLoader.AssetLoaderResultInfor.GetAssetByUrl(assetBundleLoader.m_ResourcesUrl, fileName) != null) { yield break; } } else { if (bridgeLoader.m_ConnectLoader.ResultObj != null) { yield break; } } // bridgeLoader.m_ConnectLoader.ReduceReference(bridgeLoader.m_ConnectLoader, false); //卸载这个加载器 ApplicationConfig.Instance.GetNextLoadAssetPath(ref curLoadAssetPathEnum); continue; //如果加载得到则返回否则继续尝试其他的加载方式 } while (curLoadAssetPathEnum != LoadAssetPathEnum.None); Debug.LogError("如果加载成功不会执行到这里" + url); bridgeLoader.m_ConnectLoader = null; //如果加载成功不会执行到这里 }