//异步加载图片 会自动识别图集:回调方式(image 和button已经封装 外部使用时候 谨慎使用) public static async ETTask <Sprite> LoadImageAsync(this ImageLoaderComponent self, string image_path, Action <Sprite> callback = null) { Sprite res = null; CoroutineLock coroutineLock = null; try { coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, image_path.GetHashCode()); self.__GetSpriteLoadInfoByPath(image_path, out int asset_type, out string asset_address, out string subasset_name); if (asset_type == ImageLoaderComponent.SpriteType.Sprite) { res = await self.__LoadSingleImageAsyncInternal(asset_address, callback); } if (asset_type == ImageLoaderComponent.SpriteType.DynSpriteAtlas) { res = await self.__LoadDynSpriteImageAsyncInternal(asset_address, callback); } else { res = await self.__LoadSpriteImageAsyncInternal(asset_address, subasset_name, callback); } } catch (Exception ex) { Log.Error(ex); } finally { coroutineLock?.Dispose(); } return(res); }
//异步加载图片: 回调方式,按理除了预加载的时候其余时候是不需要关心图集的 public static async ETTask <Sprite> LoadSingleImageAsync(this ImageLoaderComponent self, string atlas_path, Action <Sprite> callback = null) { Sprite res; CoroutineLock coroutineLock = null; try { coroutineLock = await CoroutineLockComponent.Instance.Wait(CoroutineLockType.Resources, atlas_path.GetHashCode()); res = await self.__LoadSingleImageAsyncInternal(atlas_path, callback); callback?.Invoke(res); } finally { coroutineLock?.Dispose(); } return(res); }