包含此页的版本:
不含此页的版本:
默认情况下,自定义控件的 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>