请注意:该组件涉及将 UI 纹理和图像绘制到屏幕的传统方法。您应改用 Unity 的最新 UI 系统。此外,这与 IMGUI 系统无关。
__GUI 纹理__在 2D 模式下显示为平面图像。这些纹理专门用于用户界面元素、按钮或装饰。纹理的定位和缩放仅沿 x 轴和 y 轴执行,并且这两个轴在__屏幕坐标__中而不是在__世界坐标__中测量。
属性: | 功能: |
---|---|
Texture | 引用将用作纹理显示效果的纹理。 |
Color | 将为屏幕上绘制的__纹理__着色的颜色。 |
Pixel Inset | 用于 GUI 纹理的缩放和定位的像素级控制。所有值都是相对于 GUI 纹理 Transform 位置的测量值。 |
X | 纹理的最左侧像素位置。 |
Y | 纹理的最底部像素位置。 |
Width | 纹理的最右侧像素位置。 |
Height | 纹理的最顶部像素位置。 |
Left Border | 左侧不受缩放比例影响的像素数。 |
Right Border | 右侧不受缩放比例影响的像素数。 |
Top Border | 顶部不受缩放比例影响的像素数。 |
Bottom Border | 底部不受缩放比例影响的像素数。 |
要创建 GUITexture,请执行以下操作:
1.在 Project 视图__中选择一个纹理 1.从菜单栏中选择 GameObject > Create General > GUI Texture__
GUI 纹理非常适合向玩家呈现游戏界面背景、按钮或其他元素。通过编写脚本,您可以轻松地为纹理的不同“状态”(例如,鼠标悬停在纹理上时,或者主动单击它时)提供视觉反馈。以下是 GUI 纹理计算原理的基本细节:
边框是图像每个边缘的区域(由像素宽度指定),在缩放纹理的其余部分时,并不会缩放边框。您很少知道游戏运行的分辨率,您的 GUI 很可能会缩放。有些 GUI 纹理在边缘处的边框需要具有确切像素数。为了实现此目的,请设置边框大小以匹配纹理中的大小值。
Pixel Inset 的目的是防止纹理随屏幕分辨率缩放,将它们保持在固定的像素大小。此功能允许您在渲染纹理时不进行任何缩放。这意味着以较高分辨率运行游戏的玩家将在屏幕的较小区域内看到您的纹理,从而为您的游戏画面留出更多屏幕空间。
为了有效地使用它,您需要将 GUI 纹理的 Transform 的缩放比例设置为 (0, 0, 0)。现在,__Pixel Inset__ 将完全控制纹理的大小,而您可以将 Pixel Inset 值设置为纹理的确切像素大小。
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.