Version: 2021.2
Write style sheets
Control behavior with Events

Apply styles with C# scripts

Unity represents USS files as StyleSheet objects in C#. For information on how to manage references to your USS assets, see Manage UI asset references from C# scripts.

To can use the styleSheets property of VisualElement attach a StyleSheet object to any element. For example, given a style sheet in local variable styleSheet and an element in local variable element, you can do the following to attach the style sheet to the element:

element.styleSheets.Add(styleSheet);

Unity applies the selectors from the style sheet to the element itself and all its descendants. Unity doesn’t apply the selectors to parent elements or siblings of the element.

Note: In Unity, any change to the USS file automatically refreshes the UI(User Interface) Allows a user to interact with your application. Unity currently supports three UI systems. More info
See in Glossary
that uses this style sheet.

Write style sheets
Control behavior with Events
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961