In a project where I am implementing common dialog
, as well as a common mvc
structure,
I am loading first, the default.uss
asset, followed by loading my own framework.asset
.
However, the default stylesheet defines unity-button with a font size with 12px, and I am trying to default my UI to 16px.
No matter what approach I use (outside of overriding a button directly, inline), I cannot get UIToolkit to apply my font-size override, even though my stylesheet is loaded and applied after the default style. And such the unity-button class always renders with 12px fonts.
In code, I am applying the two stylesheest like this, applied to a global root visual element via a UIDocument.
var baseStyle = styleSettings.BaseStyle; // currently: default.uss
var defaultStyle = styleSettings.DefaultStyle; // currently: framework.uss
var gameStyle = styleSettings.GameStyle; // currently: null
if (baseStyle ) root.AddStyleSheet(baseStyle);
if (defaultStyle ) root.AddStyleSheet(defaultStyle);
if (gameStyle ) root.AddStyleSheet(gameStyle);
I also have a setting for applying a default font, and a global default font size via a configuration asset, currently set to 16px:
var defaultFont = styleSettings.defaultFont;
if (defaultFont)
root.SetFont(new StyleFont(defaultFont));
root.style.fontSize = new Length(styleSettings.defaultFontSize, LengthUnit.Pixel);
Because .unity-button defines 12px font size, it will ignore my global-font size.
So I attempted to instead, override this inside Framework.uss, but i do not wish to force it using !important
I have tried to force it globally in my USS with the following at the beginning of my stylesheet. The buttons on my dialogs have both fw-button and unity-button classes assigned.
All other VisualElements respect my desired font size.
There are absolutly no other cases within my USS where I have attempted to set font size.
*,
* . *,
* .fw-button,
* .fw-button *,
.unity-button,
* .unity-button
{
-unity-font-size: 16px;
font-size: 16px;
}
/* .unity-button font size refuses to override at the above 16px, it stays permanently at 12px */
The Accept and Cancel dialog buttons as they appear at runtime:
UIToolkit Debugger shows both stylesheets have been loaded successfully, and clearly shows the above rules are recognized:
But the button still refuses to to override it’s font-size: as reported by both visual representation and the debugger.
SIDE: Can we please get a copy of default.uss.asset in text form (default.uss) as it is not possible to copy and edit it’s values (because it is a generated asset). Or perhaps a method of dumping all the rules of an existing stylesheet asset into a new text-based USS stylesheet