Version: Unity 6.3 Beta (6000.3)
Language : English
Create a custom control
Define UXML attributes for built-in types

Customize the custom control UXML tag name

By default, the tag name in UXML for your custom control is the C# class name. While it’s not recommended to use a different tag name, you can customize it if needed.

To customize a UXML tag name, add a name argument to the UxmlElement attribute.

Note: The tag name must be unique and you must reference the classes’ namespace in UXML.

For example, if you create the following custom button:

using UnityEngine.UIElements;

namespace MyNamespace
{
    [UxmlElement("MyButton")]
    public partial class CustomButtonElement : Button
    {
    }
}

You can then reference the custom button in UXML with the custom name or the C# class name:

<ui:UXML xmlns:ui="UnityEngine.UIElements">
    <MyNamespace.MyButton />
    <MyNamespace.CustomButtonElement />
</ui:UXML>

Additional resources

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