css - Unity 用户界面工具包 : DropdownField styling

标签 css unity3d

我正在使用 Unity 的新型 UI 工具包实现表单 View ,并且使用 UI 构建器来设计我自己的东西的样式很简单。没什么大不了的。

当涉及到 Unity 的预构建“控件”时,UI 构建器中的样式非常有限。我可以在最外层的父级上设置一些样式,但我不能弄乱内部控件。

但是,我可以查看这些组件使用的类,并且我可以通过简单地手动编辑 USS 文件来覆盖它们的规则。不确定为什么会有此限制,但就这样吧。

然而,使用 DropdownField,我可以轻松地设置输入和箭头等的样式,但我找不到实际下拉面板的类,我想成为还可以修复它的颜色、字体、大小等,所以它看起来没那么糟糕

enter image description here

查看 DropdownField 的源代码,我可以找到一些我在 UI 构建器中看不到的类名,但即使在向它们发送垃圾 CSS 规则时,我似乎也没有打对了

来自 DropdownField.cs

internal static readonly string ussClassNameBasePopupField = "unity-base-popup-field";
internal static readonly string textUssClassNameBasePopupField = DropdownField.ussClassNameBasePopupField + "__text";
internal static readonly string arrowUssClassNameBasePopupField = DropdownField.ussClassNameBasePopupField + "__arrow";
internal static readonly string labelUssClassNameBasePopupField = DropdownField.ussClassNameBasePopupField + "__label";
internal static readonly string inputUssClassNameBasePopupField = DropdownField.ussClassNameBasePopupField + "__input";
internal static readonly string ussClassNamePopupField = "unity-popup-field";
internal static readonly string labelUssClassNamePopupField = DropdownField.ussClassNamePopupField + "__label";
internal static readonly string inputUssClassNamePopupField = DropdownField.ussClassNamePopupField + "__input";

来 self 的 USS 文件

.unity-base-popup-field {
    font-size: 42px;
}
.unity-base-popup-field__text {
    font-size: 42px;
}
.unity-base-popup-field__input {
    font-size: 42px;
}
.unity-base-popup-field__label {
    font-size: 42px;
}

.unity-popup-field {
    font-size: 42px;
}
.unity-popup-field__text {
    font-size: 42px;
}
.unity-popup-field__input {
    font-size: 42px;
}
.unity-popup-field__label {
    font-size: 42px;
}

我不太确定如何从这里取得进展...对找到我正在寻找的东西有帮助吗?还是我应该换一种方式?

编辑:我暂时忘记了这是堆栈溢出,我们会因为轻微的冒犯而被斩首,所以我拿出了一些有用的屏幕截图并复制到一些代码块中/shrug

最佳答案

经过大量挖掘,设法自己解决了我的问题。 Full discussion here

对于愤怒的 SO-Meta 编辑的免责声明,他们喜欢关闭所有内容而不是提供帮助:我已在答案中附上照片。非常抱歉,但这是解释事物如何连接在一起的最具说明性的方式。答案中没有涉及代码。只是编辑引用。

我查看了 UI 调试器,我可以看到 DropdownField 抽屉被实例化为层次结构中的全局元素,而不是我的任何 UXML 文档的子元素。我所有的 UXML 文档都引用了一个共享的 Menu.uss 文件作为样式,但是由于这个抽屉变成了根组件,所以它根本不会从我的 USS 中读取。 UI 调试器证实了这一点。

我的 UXML:

enter image description here

下拉抽屉:

enter image description here

因此,在论坛上来回搜索之后,我进行了挖掘,并找到了解决方法。

在运行时呈现 UI 的 UI Document 组件有面板设置:

enter image description here

面板设置有一个主题样式表:

enter image description here

制作默认样式表的副本并引用您的副本。然后在那里添加您的样式表,这将确保每个元素都选择样式:

enter image description here

现在一切正常:

enter image description here

关于css - Unity 用户界面工具包 : DropdownField styling,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/73221735/

相关文章:

jquery - 使用 jQuery 交叉淡入淡出背景图像

html - 没有 float 或位置 :absolute 的并排 Div

html - 如何在 Bootstrap 的顶部制作面板标题 'fixed'?

javascript - 在 IE 中使用 JS、HTML 和 CSS 自定义文件上传

c# - Unity 无法列出目标平台

c# - 对象如何站在动画平台上

c# - 在 Unity 中使用 OnMouseDrag 在屏幕上拖动时如何禁用按钮 OnClick