USS Variables are regular USS style properties with custom user-defined names that can hold any style value type. They can then be used in place of a value on any other USS style property. USS variables are primarily used for themes, with the default Unity themes exposing a long list of standard variables to make your UI more consistent with standard controls. The example below demonstrates variable definition and usage in USS:
* {
--my-var: 20px;
}
.my-button {
width: var(--my-var);
}
To assign a variable to a StyleSheet USS style property in UI Builder:
This option will temporarily convert the style field into a text field and allow you to input the name of the USS variable:
As you type the name of the variable, a dropdown menu displays any found matching variables coming from either:
The variable dropdown will also let you select a variable option and see its current value and the StyleSheet asset it’s coming from. Pressing Enter will set the variable and revert the style field back to its original type.
For style fields that are already text fields, you can also assign a variable by starting to type --
instead of a number.
どのスタイルフィールドにすでに変数が割り当てられているかは、フィールドのラベルを見て、それがボックスで囲まれているかどうかでわかります。
To remove a variable assignment, select Set Variable and delete the variable name.
A few additional points to keep in mind when using USS Variables in UI Builder: