| | |
| | | return component; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void AddListener(this Button _button, UnityAction _action) |
| | | { |
| | | if (_button == null) |
| | |
| | | _button.onClick.AddListener(_action); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void RemoveAllListeners(this Button _button) |
| | | { |
| | | if (_button == null) |
| | |
| | | _button.onClick.RemoveAllListeners(); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void SetListener(this Button button, UnityAction action) |
| | | { |
| | | if (button == null) |
| | |
| | | { |
| | | return; |
| | | } |
| | | _toggle.onValueChanged.RemoveAllListeners(); |
| | | _toggle.onValueChanged.AddListener(_action); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void SetListener(this Toggle toggle, UnityAction<bool> action) |
| | | { |
| | | if (toggle == null) |
| | |
| | | _toggle.onValueChanged.RemoveAllListeners(); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void AddListener(this Slider _slider, UnityAction<float> _action) |
| | | { |
| | | if (_slider == null) |
| | |
| | | _slider.onValueChanged.AddListener(_action); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void SetListener(this Slider slider, UnityAction<float> action) |
| | | { |
| | | if (slider == null) |
| | |
| | | _slider.onValueChanged.RemoveAllListeners(); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void AddListener(this InputField _inputField, UnityAction<string> _action) |
| | | { |
| | | if (_inputField == null) |
| | |
| | | inputField.onValueChanged.AddListener(action); |
| | | } |
| | | |
| | | |
| | | |
| | | public static void RemoveAllListeners(this InputField _inputField) |
| | | { |
| | | if (_inputField == null) |
| | |
| | | // EnableButtonConfig.SetEnable(_btn, _btnTxt, _enable, _type); |
| | | // } |
| | | |
| | | |
| | | |
| | | public static void SetColorful(this Button _btn, Text _btnTxt, bool _colorful, int pattern = 0) |
| | | { |
| | | if (_btn != null) |
| | |
| | | switch (pattern) |
| | | { |
| | | case 1: |
| | | _btnTxt.color = UIHelper.GetUIColor(_colorful ? TextColType.LightYellow : TextColType.White); |
| | | _btnTxt.color = UIHelper.GetUIColor(_colorful ? TextColType.LightWhite : TextColType.White); |
| | | break; |
| | | case 2: |
| | | _btnTxt.color = UIHelper.GetUIColor(_colorful ? TextColType.Green : TextColType.White); |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | |
| | | public static void SetInteractable(this Button _btn, Text _btnText, bool _interactable) |
| | | { |
| | | if (_btn != null) |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | //通过ICON表加载 |
| | | public static void SetSprite(this Image _image, string _id) |
| | | { |
| | | if (_image == null) |
| | |
| | | return; |
| | | } |
| | | |
| | | var sprite = ResManager.Instance.LoadAsset<Sprite>("Sprite", _id); |
| | | var sprite = UILoader.LoadSprite(_id); |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | |
| | | |
| | | public static void SetSprite(this TextImage _textImage, string _id) |
| | | { |
| | | if (_textImage == null) |
| | |
| | | return; |
| | | } |
| | | |
| | | var sprite = ResManager.Instance.LoadAsset<Sprite>("Sprite", _id); |
| | | var sprite = UILoader.LoadSprite(_id); |
| | | _textImage.sprite = sprite; |
| | | } |
| | | |
| | | //通过图片名加载, 如物品表 技能表等,节省在Icon表做多余配置 |
| | | public static void SetOrgSprite(this Image _image, string iconName, string folderName = "icon") |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var sprite = UILoader.LoadSprite(folderName, iconName); |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetItemSprite(this Image _image, int itemID) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var itemConfig = ItemConfig.Get(itemID); |
| | | if (itemConfig == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var sprite = UILoader.LoadSprite("icon", itemConfig.IconKey); |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetSkillSprite(this Image _image, int skillID) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var skillConfig = SkillConfig.Get(skillID); |
| | | if (skillConfig == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var sprite = UILoader.LoadSprite("SkillIcon", skillConfig.IconName); |
| | | _image.overrideSprite = sprite; |
| | | } |
| | | |
| | | public static void SetActive(this Component compoent, bool active) |
| | | { |
| | |
| | | } |
| | | } |
| | | |
| | | |
| | | public static void SetTexture2D(this RawImage _image, string _id) |
| | | { |
| | | if (_image == null) |
| | | { |
| | | return; |
| | | } |
| | | |
| | | var texture = UILoader.LoadTexture2D(_id); |
| | | _image.texture = texture; |
| | | } |
| | | } |