lcy
3 天以前 f1e5df1fc8eadd0eb27e0a6870501fa25a42b5a1
Main/Utility/ComponentExtersion.cs
@@ -255,7 +255,40 @@
        }
    }
    public static void SetColorful(this GroupButtonEx _btn, Text _btnTxt, bool _colorful, int pattern = 0)
    {
        if (_btn != null)
        {
            if (_btn.selectIcon != null)
            {
                _btn.selectIcon.gray = !_colorful;
            }
            if (_btn.unSelectIcon != null)
            {
                _btn.unSelectIcon.gray = !_colorful;
            }
        }
        if (_btnTxt != null)
        {
            switch (pattern)
            {
                case 1:
                    _btnTxt.color = UIHelper.GetUIColor(_colorful ? TextColType.LightWhite : TextColType.White);
                    break;
                case 2:
                    _btnTxt.color = UIHelper.GetUIColor(_colorful ? TextColType.Green : TextColType.White);
                    break;
                default:
                    //false 灰色,true 原色
                    if (!_colorful)
                        _btnTxt.text = UIHelper.AppendColor(TextColType.NavyGray, _btnTxt.text);    //不改变组件颜色,只改变显示颜色
                    else
                        _btnTxt.text = UIHelper.AppendColor(_btnTxt.color, _btnTxt.text);
                    break;
            }
        }
    }
    // 设置按钮是否可点击,且取第一个文本组件置灰或置原色
    // 要先设置文本再调用该函数 因为没有改变文本组件的颜色避免颜色被还原,同理恢复可以不用改变颜色改文字即可
    // 更多功能请使用SetColorful
@@ -290,6 +323,12 @@
            return;
        }
        if (string.IsNullOrEmpty(_id))
        {
            Debug.LogError("Image SetSprite id is null or empty " + _id);
            return;
        }
        var sprite = UILoader.LoadSprite(_id);
        _image.overrideSprite = sprite;
    }
@@ -302,6 +341,12 @@
            return;
        }
        if (string.IsNullOrEmpty(_id))
        {
            Debug.LogError("TextImage SetSprite id is null or empty " + _id);
            return;
        }
        var sprite = UILoader.LoadSprite(_id);
        _textImage.sprite = sprite;
    }
@@ -311,6 +356,12 @@
    {
        if (_image == null)
        {
            return;
        }
        if (string.IsNullOrEmpty(iconName))
        {
            Debug.LogError("SetOrgSprite iconName is null or empty " + iconName);
            return;
        }
@@ -332,6 +383,12 @@
            return;
        }
        if (string.IsNullOrEmpty(itemConfig.IconKey))
        {
            Debug.LogError("SetItemSprite IconKey is null or empty for itemID " + itemID);
            return;
        }
        var sprite = UILoader.LoadSprite("icon", itemConfig.IconKey);
        _image.overrideSprite = sprite;
    }
@@ -346,6 +403,12 @@
        var skillConfig = SkillConfig.Get(skillID);
        if (skillConfig == null)
        {
            return;
        }
        if (string.IsNullOrEmpty(skillConfig.IconName))
        {
            Debug.LogError("SetSkillSprite IconName is null or empty for skillID " + skillID);
            return;
        }
@@ -388,6 +451,12 @@
            return;
        }
        if (string.IsNullOrEmpty(_id))
        {
            Debug.LogError("SetTexture2DPNG id is null or empty " + _id);
            return;
        }
        var texture = UILoader.LoadTexture2DPNG(_id);
        _image.texture = texture;
    }