USS를 사용할 때 UI 코드에서 빌트인 VisualElement
프로퍼티 또는 커스텀 프로퍼티에 대한 값을 지정할 수 있습니다.
USS 파일에서 값을 읽는 것 외에도 빌트인 프로퍼티 값은 VisualElement
의 C# 프로퍼티를 사용하여 C#으로 할당할 수 있습니다. C#으로 할당한 값은 Unity 스타일시트(USS)의 값을 오버라이드합니다.
커스텀 프로퍼티를 사용하여 USS를 확장할 수 있습니다. 커스텀 USS 프로퍼티에는 --
접두사가 필요합니다.
이 섹션에는 지원되는 타입이 나와 있습니다.
UI 툴킷은 길이 측정 단위로 픽셀(px
)과 백분율(%
)을 지원합니다. 픽셀 값은 절대적이지만, 백분율은 대개 요소의 부모에 대해 상대적입니다.
예제:
width:200px;
200픽셀의 너비를 표현합니다.width:50%;
부모 요소 너비의 절반을 표현합니다.측정 단위를 지정하는 것이 중요합니다. 측정 단위를 지정하지 않으면 UI 툴킷은 프로퍼티 값이 픽셀로 표현된다고 가정합니다.
참고: 0
은 측정 단위가 필요하지 않은 특수 값입니다.
숫자 값은 부동 소수점 또는 정수 리터럴로 표시됩니다(예: flex:1.0
).
특정한 키워드는 일부 빌트인 프로퍼티에서 지원됩니다 .키워드는 숫자가 아니라 설명적인 이름을 제공합니다(예: position:absolute
). 모든 프로퍼티는 프로퍼티를 기본값으로 재설정하는 initial
전역 키워드를 지원합니다. 키워드 리스트는 지원되는 프로퍼티를 참조하십시오.
UI 툴킷은 다음의 리터럴 컬러 값 및 함수를 지원합니다.
#FFFF00
(채널당 rgba 1바이트), #0F0
(rgb)rgb(255, 255, 0)
rgba(255, 255, 0, 1.0)
blue
, transparent
resource()
또는 url()
함수 중 하나를 사용하여 에셋을 참조할 수 있습니다. 예를 들어 background-image: resource("Images/img.png")
를 지정하면 Images
디렉토리에 img.png
를 배경 이미지로 지정할 수 있습니다. 참조된 에셋은 임포트 중에 확인됩니다.
resource()
함수는 Resources
폴더 또는 Editor Default Resources
폴더에 있는 파일을 허용합니다. 단, 다음 사항에 유의하십시오.
Resources
폴더에 있는 경우 파일 확장자를 포함하지 마십시오. 예: background-image: resource("Images/my-image")
Editor Default Resources
폴더에 있는 경우 파일 확장자를 포함해야 합니다. 예: background-image: resource("Images/default-image.png")
또한 텍스처를 로드할 때 resource()
는 편리한 방식으로 고DPI/Retina 스크린을 처리하도록 지원합니다. 파일 이름이 동일하고 @2x
접미사를 가진 텍스처가 동일한 위치에 존재하면 Unity는 스크린 DPI에 따라 해당 텍스처를 자동으로 로드합니다. 예를 들어 USS에서 resource("myimage")
를 사용하면 Unity는 Resources/myimage.png 또는 Resources/myimage@2x.png 를 로드합니다.
url()
함수는 파일 경로가 프로젝트 루트 또는 USS 파일이 담긴 폴더와 관련된다고 예상합니다. 파일 확장자는 반드시 포함해야 합니다. 다음 예제에서 USS 파일은 Assets\Editor\USS 에 있고 thumb.png 배경 이미지는 Assets\Editor\Resources 에 있습니다.
url("../Resources/thumb.png");
url("/Assets/Editor/Resources/thumb.png");
또는 url("project:/Assets/Editor/Resources/thumb.png");
또는 url("project:///Assets/Editor/Resources/thumb.png");
예: background-image: url("Images/my-image.png")
.큰따옴표를 사용하여 문자열 값을 지정하십시오. 예: --my-property: "foo"
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.