yyl
2025-10-17 c124d98bdf9659cf764bebb799bee42c30eb152f
Main/Utility/ComponentExtersion.cs
@@ -256,7 +256,10 @@
    }
    public static void SetInteractable(this Button _btn, Text _btnText, bool _interactable)
    // 设置按钮是否可点击,且取第一个文本组件置灰或置原色
    // 要先设置文本再调用该函数 因为没有改变文本组件的颜色避免颜色被还原,同理恢复可以不用改变颜色改文字即可
    // 更多功能请使用SetColorful
    public static void SetInteractable(this Button _btn, bool _interactable, Text _btnText = null)
    {
        if (_btn != null)
        {
@@ -267,10 +270,15 @@
                imageEx.gray = !_interactable;
            }
        }
        if (_btnText == null)
            _btnText = _btn.GetComponentInChildren<Text>();
        if (_btnText != null)
        {
            _btnText.color = UIHelper.GetUIColor(_interactable ? TextColType.NavyBrown : TextColType.White);
            //_btnText.color = _btnText.color.SetA(_interactable ? 1 : 0.5f);
            //false 灰色,true 原色
            if (!_interactable)
                _btnText.text = UIHelper.AppendColor(TextColType.NavyGray, _btnText.text);    //不改变组件颜色,只改变显示颜色
            else
                _btnText.text = UIHelper.AppendColor(_btnText.color, UIHelper.RemoveColor(_btnText.text));
        }
    }
@@ -370,4 +378,16 @@
        var texture = UILoader.LoadTexture2D(_id);
        _image.texture = texture;
    }
    public static void SetTexture2DPNG(this RawImage _image, string _id)
    {
        if (_image == null)
        {
            return;
        }
        var texture = UILoader.LoadTexture2DPNG(_id);
        _image.texture = texture;
    }
}