| | |
| | | using UnityEngine.UI; |
| | | using UnityEngine.Events; |
| | | using System; |
| | | using Cysharp.Threading.Tasks; |
| | | |
| | | |
| | | public static class ComponentExtersion |
| | |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static async UniTask SetSpriteAsync(this Image _image, string _id) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(_id)) |
| | | { |
| | | Debug.LogError("Image SetSpriteAsync id is null or empty " + _id); |
| | | return; |
| | | } |
| | | |
| | | var sprite = await UILoader.LoadSpriteAsync(_id); |
| | | if (_image != null) |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | |
| | | public static void SetSprite(this TextImage _textImage, string _id) |
| | | { |
| | |
| | | |
| | | var sprite = UILoader.LoadSprite(_id); |
| | | _textImage.sprite = sprite; |
| | | } |
| | | |
| | | public static async UniTask SetSpriteAsync(this TextImage _textImage, string _id) |
| | | { |
| | | if (_textImage == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(_id)) |
| | | { |
| | | Debug.LogError("TextImage SetSpriteAsync id is null or empty " + _id); |
| | | return; |
| | | } |
| | | |
| | | var sprite = await UILoader.LoadSpriteAsync(_id); |
| | | if (_textImage != null) |
| | | _textImage.sprite = sprite; |
| | | } |
| | | |
| | | //通过图片名加载, 如物品表 技能表等,节省在Icon表做多余配置 |
| | |
| | | var sprite = UILoader.LoadSprite(folderName, iconName); |
| | | if (null == sprite) return; |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static async UniTask SetOrgSpriteAsync(this Image _image, string iconName, string folderName = "icon") |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(iconName)) |
| | | { |
| | | Debug.LogError("SetOrgSpriteAsync iconName is null or empty " + iconName); |
| | | return; |
| | | } |
| | | |
| | | var sprite = await UILoader.LoadSpriteAsync(folderName, iconName); |
| | | if (_image != null && sprite != null) |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetItemSprite(this Image _image, int itemID) |
| | |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static async UniTask SetSkillSpriteAsync(this Image _image, int skillID) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var skillConfig = SkillConfig.Get(skillID); |
| | | if (skillConfig == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | if (string.IsNullOrEmpty(skillConfig.IconName)) |
| | | { |
| | | Debug.LogError("SetSkillSpriteAsync IconName is null or empty for skillID " + skillID); |
| | | return; |
| | | } |
| | | |
| | | var sprite = await UILoader.LoadSpriteAsync("SkillIcon", skillConfig.IconName); |
| | | if (_image != null) |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetActive(this Component compoent, bool active) |
| | | { |
| | | if (compoent != null) |
| | |
| | | _image.texture = texture; |
| | | } |
| | | |
| | | public static async UniTask SetTexture2DAsync(this RawImage _image, string _id) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var texture = await UILoader.LoadTexture2DAsync(_id); |
| | | if (_image != null) |
| | | _image.texture = texture; |
| | | } |
| | | |
| | | |
| | | public static void SetTexture2DPNG(this RawImage _image, string _id) |
| | | { |