UXML 태그 이름을 커스터마이즈하고, 기본 클래스 속성의 기본값을 오버라이드하고, 커스텀 컨트롤의 허용 속성을 제한할 수 있습니다.
기본적으로 커스텀 컨트롤에 대한 UXML의 태그 이름은 C# 클래스명입니다.태그의 이름이 C# 클래스와 다르지 않도록 하는 것이 좋습니다.하지만 이름이 충돌하는 경우에는 태그 이름을 커스터마이즈할 수 있습니다.
UXML 태그 이름을 커스터마이즈하려면 IUxmlFactory.uxmlName
및 IUXmlFactory.uxmlQualifiedName
프로퍼티를 오버라이드합니다.다음을 확인하십시오.
uxmlName
이 네임스페이스에서 고유함uxmlQualifiedName
이 프로젝트에서 고유함두 이름이 고유하지 않은 경우 Unity는 어셈블리를 로드할 때 예외를 발생시킵니다.
다음 코드 예시에서는 UXML 태그 이름을 오버라이드하고 커스터마이즈합니다.
public class FactoryWithCustomName : UxmlFactory<..., ...>
{
public override string uxmlName
{
get { return "UniqueName"; }
}
public override string uxmlQualifiedName
{
get { return uxmlNamespace + "." + uxmlName; }
}
}
기본적으로 IUxmlFactory
는 요소를 인스턴스화하고, 요소 이름을 사용하여 요소를 선택합니다.선택 요소에 대한 속성 값을 고려하려면 IUXmlFactory.AcceptsAttributeBag()
를 오버라이드합니다.팩토리는 요소 속성을 검사하여 UXML 요소의 오브젝트를 인스턴스화할 수 있는지 결정합니다.
VisualElement
클래스가 일반 클래스인 경우 팩토리에서 요소 속성을 검사하도록 하는 것이 좋습니다.이러한 경우 클래스의 전문화를 위한 클래스 팩토리는 UXML type
속성의 값을 검사할 수 있습니다.값에 따라 인스턴스화가 허용되거나 거절될 수 있습니다.
두 개 이상의 팩토리가 요소를 인스턴스화할 수 있는 경우에는 첫 번째로 등록된 팩토리가 선택됩니다.
기본 클래스에서 선언된 속성의 기본값을 변경하려면 파생된 UxmlTraits
클래스에서 defaultValue
를 설정합니다.
다음 코드 예시에서는 m_TabIndex
의 기본값을 변경합니다.
class MyElementTraits : VisualElement.UxmlTraits
{
public MyElementTraits()
{
m_TabIndex.defaultValue = 0;
}
}
기본적으로 생성된 UXML 스키마는 요소가 모든 속성을 가질 수 있다고 명시합니다.이는 선언된 속성의 값이 해당 선언과 일치하는지 확인하는 XML 검증기와 대조됩니다.
추가 속성을 IUxmlAttributes
백에 포함하여 IUxmlFactory.AcceptsAttributBag()
및 IUxmlFactory.Init()
함수에 전달할 수 있습니다.이러한 추가 속성의 사용 여부는 팩토리 구현에 따라 달라집니다.기본 동작은 추가 속성을 폐기하는 것입니다.이러한 추가 속성들은 인스턴스화된 VisualElement
에 연결되지 않으며, UQuery를 사용하여 이러한 속성을 쿼리할 수 없습니다.
새 요소를 정의할 때 허용되는 속성을 IUxmlAttributes
백에 명시적으로 선언된 속성으로 제한하려면, UxmlTraits
생성자에서 UxmlTraits.canHaveAnyAttribute
속성을 false
로 설정합니다.
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.