이 섹션에서는 PropertyField
를 통해 지원되는 필드와 데이터 타입 전환을 설명합니다.
UI 툴킷의 빌트인 컨트롤 대부분은 특정 데이터 타입에 대해 INotifyValueChanged
인터페이스를 구현합니다. 예를 들어 DoubleField
는 INotifyValueChanged<Double>
을 구현하는데, 이는 DoubleField
컨트롤을 double
타입의 프로퍼티에 바인딩할 수 있다는 뜻입니다. 바인딩 시스템을 사용하여 더 많은 데이터 타입을 바인딩할 수 있습니다. 예를 들어 int
타입의 프로퍼티를 DoubleField
에 바인딩할 수 있습니다.
다음 표에는 바인딩할 수 있는 소스 및 타겟 데이터 타입이 나열되어 있습니다.
소스 데이터 타입 | INotifyValueChanged 의 타겟 데이터 타입 |
---|---|
long |
|
int |
|
double |
|
float |
|
char |
|
참고:데이터 손실을 방지하려면 PropertyField
를 사용하거나 아래의 PropertyField 표에서 지원하는 필드에 표시된 대로 적절한 데이터 타입을 사용하십시오.
PropertyField
에서 지원하는 필드인스펙터 창이 채워진 경우, 타입에 대해 커스텀 에디터가 존재하지 않으면 바인딩 시스템은 InspectorElement.FillDefaultInspector()
를 호출합니다. 이렇게 하면 SerializedObject
의 각 SerializedProperty
에 대해 PropertyField
가 생성됩니다.
각 PropertyField
아래에는 매칭되는 컨트롤이 있습니다(예: int
를 표현하는 IntegerField
, 또는 bool
을 표현하는 Toggle
). 프로퍼티에 하위 프로퍼티가 있는 경우 PropertyField
에 Foldout
컨트롤이 포함됩니다. 이 Foldout
은 각 하위 프로퍼티 아래에 적절한 기본 컨트롤을 갖습니다. 프로퍼티에 대해 커스텀 PropertyDrawer
를 생성한 경우 PropertyDrawer
의 CreatePropertyGUI()
메서드에서 반환되는 비주얼 트리가 대신 사용됩니다.
참고:
커스텀 UI를 생성하는 경우, 특정 컨트롤을 찾을 수 없는 경우가 아니라면 PropertyField
를 사용하지 마십시오. 예를 들어 비주얼 트리에서 컨트롤을 생성하고 이를 Color
에 바인딩하려면 PropertyField
가 아닌 ColorField
를 사용합니다. 이렇게 하면 비주얼 트리가 더 가볍고 빠르게 작동합니다.
PropertyField
를 사용하면 바인딩 후 사용할 구체적인 필드를 확인하기 때문에 추가 오버헤드가 발생합니다. 이러한 추가 단계는 성능에 영향을 미칠 수 있습니다. 하지만 PropertyField
는 일부 경우에 유용합니다. 예를 들어, 특정 프로퍼티를 개인화된 방식으로 처리하는 데 사용할 수 있는 커스텀 드로어를 지원합니다. 이렇게 하면 드로잉을 위해 필드 타입을 추측할 필요가 없으므로 오류를 줄일 수 있습니다.
다음 표에는 PropertyField
에서 지원하는 필드와 해당 데이터 타입이 나열되어 있습니다.
필드 | 데이터 타입 |
---|---|
BoundsField |
Bounds |
BoundsIntField |
BoundsInt |
ColorField |
색상 |
CurveField |
AnimationCurve |
FloatField |
float |
GradientField |
그레디언트 |
Hash128Field |
Hash128 |
IntegerField |
int |
IntegerField |
int, for the ArraySize |
LayerMaskField |
unit |
LongField |
long |
ObjectField |
UnityEngine.Object |
PopupField <string> |
열거형 |
RectField |
Rect |
RectIntField |
RectInt |
TextField |
문자열 |
TextField , with a maxLength=1 |
char |
Toggle |
bool |
Vector2Field |
Vector2 |
Vector2IntField |
Vector2Int |
Vector3Field |
Vector3 |
Vector3IntField |
Vector3Int |
Vector4Field |
Vector4 |
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.