/// <summary> /// 加载资源的桥连接器 会根据配置路径加载优先级加载资源 /// </summary> /// <param name="url"></param> /// <param name="onCompleteAct"></param> /// <param name="isloadSceneAsset"> 如果加载的是场景资源 则这里必须为true 否则为false</param> /// <returns></returns> private static BridgeLoader LoadAssetAsync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadSceneAsset) { if (string.IsNullOrEmpty(url)) { Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(BridgeLoader))); return(null); } bool isLoaderExit = false; BridgeLoader bridgeLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <BridgeLoader>(url, ref isLoaderExit); bridgeLoader.m_OnCompleteAct.Add(onCompleteAct); bridgeLoader.m_IsLoadSceneAsset = isloadSceneAsset; bridgeLoader.LoadassetModel = LoadAssetModel.Async; //这里获得的加载器不需要特殊处理 if (isLoaderExit) { if (bridgeLoader.IsCompleted) { bridgeLoader.OnCompleteLoad(bridgeLoader.IsError, bridgeLoader.Description, bridgeLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件 } return(bridgeLoader); //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调 } EventCenter.Instance.StartCoroutine(bridgeLoader.LoadAssetByPriorityAsync(url, bridgeLoader, isloadSceneAsset)); EventCenter.Instance.StartCoroutine(bridgeLoader.LoadAssetAsync(url, bridgeLoader)); return(bridgeLoader); }
/// <summary> /// 同步加载资源 /// </summary> /// <param name="url"></param> /// <param name="onCompleteAct"></param> /// <param name="isloadSceneAsset"></param> /// <returns></returns> private static BridgeLoader LoadAssetSync(string url, System.Action <BaseAbstracResourceLoader> onCompleteAct, bool isloadSceneAsset) { if (string.IsNullOrEmpty(url)) { Debug.LogError(string.Format("Url Can't Be Null , TypeLoader={0}", typeof(BridgeLoader))); return(null); } bool isLoaderExit = false; BridgeLoader bridgeLoader = ResourcesLoaderMgr.GetOrCreateLoaderInstance <BridgeLoader>(url, ref isLoaderExit); bridgeLoader.m_OnCompleteAct.Add(onCompleteAct); bridgeLoader.m_IsLoadSceneAsset = isloadSceneAsset; if (isLoaderExit && bridgeLoader.IsCompleted) { bridgeLoader.LoadassetModel = LoadAssetModel.Sync; bridgeLoader.OnCompleteLoad(bridgeLoader.IsError, bridgeLoader.Description, bridgeLoader.ResultObj, true); //如果当前加载器已经完成加载 则手动触发事件 return(bridgeLoader); //如果已经存在 且当前加载器还在加载中,则只需要等待加载完成则回调用回调 } if (bridgeLoader.LoadassetModel == LoadAssetModel.Async) { bridgeLoader.ForceBreakLoaderProcess(); } bridgeLoader.LoadassetModel = LoadAssetModel.Sync; #if UNITY_EDITOR if (Application.isPlaying == false) { bridgeLoader.LoadAssetByPriority_Editor(url, bridgeLoader, isloadSceneAsset); bridgeLoader.LoadAssetSync(url, bridgeLoader); return(bridgeLoader); }//编辑器下非运行状态特殊处理 #endif bridgeLoader.LoadAssetByPrioritySync(url, bridgeLoader, isloadSceneAsset); bridgeLoader.LoadAssetSync(url, bridgeLoader); return(bridgeLoader); }