Unity3d 无法在编辑器窗口中更改按钮样式背景

Unity3d 无法在编辑器窗口中更改按钮样式背景,unity3d,user-interface,unity-editor,unity3d-editor,Unity3d,User Interface,Unity Editor,Unity3d Editor,统一版本:2019.4.1f1 我正在尝试更改编辑器窗口中按钮的背景。尝试在正常状态下按下按钮以实现效果: 结果如下: 即使我明确设置了背景,问题仍然存在: buttonStyleToggled.normal.background = buttonStyleToggled.active.background; buttonStyleToggled.normal.scaledBackgrounds = buttonStyleToggled.active.scaledBackgrounds;

统一版本:2019.4.1f1

我正在尝试更改编辑器窗口中按钮的背景。尝试在正常状态下按下按钮以实现效果:

结果如下:

即使我明确设置了背景,问题仍然存在:

 buttonStyleToggled.normal.background = buttonStyleToggled.active.background;
 buttonStyleToggled.normal.scaledBackgrounds = buttonStyleToggled.active.scaledBackgrounds;

我看不出您在哪里为按钮的活动状态设置纹理或颜色

Color activeButtonColor = new Color(0.3f, 0.3f, 0.3f, 1.0f);

buttonStyleToggled.active.background = activeButtonColor;

背景是纹理2D,而不是颜色。buttonStyleToggled.active必须已在背景字段中包含纹理。在底部代码块中,我设置了:buttonStyleToggled.normal.background=buttonStyleToggled.active.background。
Color activeButtonColor = new Color(0.3f, 0.3f, 0.3f, 1.0f);

buttonStyleToggled.active.background = activeButtonColor;