Configure the custom control name and visibility in UI Builder
Use the UxmlElement attribute to change how your custom controls appear in UXML and in the UI Builder library.
읽는 시간 2분최근 업데이트: 한 달 전
Use the attribute to change how your custom controls appear in UXML and in the UI Builder library.
UxmlElementCustomize 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 argument to the attribute.
nameUxmlElementFor 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>
Configure path and visibility
By default, custom controls appear in the UI Builder library under a path that matches their C# namespace. You can use the argument to customize the path of the attribute.
libraryPathUxmlElementBy default, namespaces that start with , , or are reserved, so elements in these namespaces don’t appear in the UI Builder library. You can use the argument to override this and make your controls visible.
UnityUnityEngineUnityEditorvisibleThe following example shows how to make a custom control visible in the UI Builder library under a custom path, and how to hide another custom control:
using UnityEngine.UIElements;namespace Unity.MyGame{ // This element is visible in the UI Builder library under "My Game/Inventory". [UxmlElement(libraryPath = "My Game/Inventory", visibility = LibraryVisibility.Visible)] public partial class VisibleItem : VisualElement { [UxmlAttribute] public string description { get; set; } }}// This element is hidden from the UI Builder library.// However, you can still use it in UXML or C# code.[UxmlElement(visibility = LibraryVisibility.Hidden)]public partial class HiddenItem : VisualElement{ [UxmlAttribute] public string description { get; set; }}