Version: 2023.1
Structure UI with C# scripts
Create a custom control

Custom controls

You can create custom controls and implement custom logic for user interface elements. A good custom control is abstract, self-contained, and recurring.

A Slide Toggle is a good example of a custom control:

  • It’s abstract. You use it to switch between one setting and another.
  • It’s self-contained. You give it a label and an initial value. A Slide Toggle triggers an event when its state changes.
  • It’s recurring. You can use it in multiple places in an application.

The menu bar of your application isn’t a good example of a custom control:

  • It’s not abstract. It’s specific to your application.
  • It’s not self-contained. It probably has dependencies to other parts of your application.
  • It’s not recurring. There is probably only one menu in your application.

After you have created a custom control, you can style it with USS, add logic to handle events in C#, and expose and use it in UI Builder.

Topic 描述
Create custom controls Understand all aspects of creating and using custom controls.
Expose custom controls to UXML and UI Builder Understand how to expose your custom controls and define attributes for your custom controls.
Customize UXML tag names and attributes Understand how to customize a UXML tag name, override the default value of a base class attribute, or restrict the accepted attributes for your custom controls.

其他资源

Structure UI with C# scripts
Create a custom control
Copyright © 2023 Unity Technologies
优美缔软件(上海)有限公司 版权所有
"Unity"、Unity 徽标及其他 Unity 商标是 Unity Technologies 或其附属机构在美国及其他地区的商标或注册商标。其他名称或品牌是其各自所有者的商标。
公安部备案号:
31010902002961