/// <summary> /// 设置Image指定图片(从Sprite Atlas里) /// </summary> /// <param name="timg">Image组件</param> /// <param name="atlasname">图集名</param> /// <param name="spritename">图片名</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSpriteAtlas(TImage timg, string atlasname, string spritename, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(timg == null, "setImageSpriteAtlas不允许传空TImage!"); ResourceModuleManager.Singleton.requstResource(atlasname, (abi) => { DIYLog.Log("加载SpriteAtlas AB完成!"); // 清除老的资源引用 if (timg.ABI != null) { timg.ABI.releaseOwner(timg); } if (abi != null) { DIYLog.Log("加载SpriteAtlas之前!"); var spriteatlas = abi.getAsset <SpriteAtlas>(timg, atlasname); DIYLog.Log("加载SpriteAtlas之后!"); timg.sprite = spriteatlas.GetSprite(spritename); DIYLog.Log("SpriteAtlas.GetSprite()之后!"); } timg.ABI = abi; timg.AtlasName = atlasname; timg.SpriteName = spritename; }, loadtype, loadmethod); }
/// <summary> /// 设置TImage指定图片(单图的时候) /// </summary> /// <param name="timg">TImage组件</param> /// <param name="spritepath">Sprite路径</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setTImageSingleSprite(TImage timg, string spritepath, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(timg == null, "setTImageSingleSprite!"); ResourceModuleManager.Singleton.requstResource(spritepath, (abi) => { // 清除老的资源引用 if (timg.ABI != null && !string.IsNullOrEmpty(timg.AtlasPath)) { timg.ABI.releaseOwner(timg); } if (abi != null) { // Sprite统一为小写 var spritename = Path.GetFileNameWithoutExtension(spritepath).ToLower(); var sprite = abi.getAsset <Sprite>(timg, spritename); timg.sprite = sprite; timg.ABI = abi; timg.AtlasPath = spritepath; timg.SpriteName = spritename; } else { timg.ABI = null; timg.AtlasPath = string.Empty; timg.SpriteName = string.Empty; } }, loadtype, loadmethod); }
/// <summary> /// 设置Image指定图片(单图的时候) /// </summary> /// <param name="img">Image组件</param> /// <param name="spritepath">Sprite路径</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSingleSprite(Image img, string spritepath, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(img == null, "setImageSingleSprite!"); ResourceModuleManager.Singleton.requstResource(spritepath, (abi) => { // Sprite统一为小写 var spritename = Path.GetFileNameWithoutExtension(spritepath).ToLower(); var sprite = abi.getAsset <Sprite>(img, spritename); img.sprite = sprite; }, loadtype, loadmethod); }
/// <summary> /// 设置Image指定图片 /// </summary> /// <param name="trawimg">Image组件</param> /// <param name="texturename">纹理名</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setRawImage(TRawImage trawimg, string texturename, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(trawimg == null, "setRawImage不允许传空TRawImage!"); ResourceModuleManager.Singleton.requstResource(texturename, (abi) => { // 清除老的资源引用 if (trawimg.ABI != null && !string.IsNullOrEmpty(trawimg.TextureName)) { trawimg.ABI.releaseOwner(trawimg); } if (abi != null) { var texture = abi.getAsset <Texture>(trawimg, texturename); trawimg.texture = texture; } trawimg.ABI = abi; trawimg.TextureName = texturename; }, loadtype, loadmethod); }
/// <summary> /// 设置Image指定图片 /// </summary> /// <param name="timg">Image组件</param> /// <param name="atlasname">图集名</param> /// <param name="spritename">图片名</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSprite(TImage timg, string atlasname, string spritename, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(timg == null, "setImageSprite不允许传空TImage!"); ResourceModuleManager.Singleton.requstResource(atlasname, (abi) => { // 清除老的资源引用 if (timg.ABI != null && !string.IsNullOrEmpty(timg.AtlasName)) { timg.ABI.releaseOwner(timg); } if (abi != null) { var sprite = abi.getAsset <Sprite>(timg, spritename); timg.sprite = sprite; } timg.ABI = abi; timg.AtlasName = atlasname; timg.SpriteName = spritename; }, loadtype, loadmethod); }
/// <summary> /// 设置Image指定图片(从Sprite Atlas里) /// </summary> /// <param name="timg">Image组件</param> /// <param name="atlaspath">图集路径</param> /// <param name="spritename">Sprite名</param> /// <param name="loadtype">资源加载类型</param> /// <param name="loadmethod">资源加载方式</param> /// <returns></returns> public void setImageSpriteAtlas(TImage timg, string atlaspath, string spritename, ResourceLoadType loadtype = ResourceLoadType.NormalLoad, ResourceLoadMethod loadmethod = ResourceLoadMethod.Sync) { DIYLog.Assert(timg == null, "setImageSpriteAtlas不允许传空TImage!"); ResourceModuleManager.Singleton.requstResource(atlaspath, (abi) => { DIYLog.Log("加载SpriteAtlas AB完成!"); // 清除老的资源引用 if (timg.ABI != null && !string.IsNullOrEmpty(timg.AtlasPath)) { timg.ABI.releaseOwner(timg); } if (abi != null) { var atlasname = Path.GetFileNameWithoutExtension(atlaspath); DIYLog.Log("加载SpriteAtlas之前!"); var spriteatlas = abi.getAsset <SpriteAtlas>(timg, atlasname); DIYLog.Log("加载SpriteAtlas之后!"); // Sprite统一为小写 spritename = spritename.ToLower(); timg.sprite = spriteatlas.GetSprite(spritename); DIYLog.Log("SpriteAtlas.GetSprite()之后!"); timg.ABI = abi; timg.AtlasPath = atlaspath; timg.SpriteName = spritename; } else { timg.ABI = null; timg.AtlasPath = string.Empty; timg.SpriteName = string.Empty; } }, loadtype, loadmethod); }