Version: 6000.3
语言: 中文
创建自定义控件
定义内置类型的 UXML 属性

自定义自定义控件UXML标签名称

默认情况下,自定义控件的 UXML 中的标签名称是 C# 类名称。虽然不建议使用其他标签名称,但您可以根据需要对其进行自定义。

要自定义UXL标签名称,请添加name参数设置为UxmlElement属性。

注意:标签名称必须是唯一的,并且你必须在UXL中引用类的命名空间。

例如,如果您创建以下自定义按钮:

using UnityEngine.UIElements;

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

然后,你可以使用自定义名称或C#类名称在UXML中引用自定义按钮:

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

其他资源

创建自定义控件
定义内置类型的 UXML 属性