GUI Texture
GUI Textures are displayed as flat images in 2D. They are made especially for user interface elements, buttons, or decorations. Their positioning and scaling is performed along the x and y axes only, and they are measured in Screen Coordinates, rather than World Coordinates.
GUI贴图是显示在2D视图里的平面图。它们主要被用来制作用户接口元件,按键,或者装饰。它们的位置和缩放只由x和y轴来决定,它们的单位是以屏幕坐标,而不是空间坐标来描述的。
The GUI Texture Inspector
GUI贴图检视图
Please Note: Unity 2.0 introduced UnityGUI, a GUI Scripting system. You may prefer creating user interface elements with UnityGUI instead of GUI Textures. Read more about how to use UnityGUI in the GUI Scripting Guide.
请注意:Unity2.0中介绍UnityGUI为一种GUI脚本系统。你可以能更喜欢使用UnityGUI来制作用户接口元件,而不是GUI贴图。想了解更多关于UnityGUI,请阅读GUI Scripting Guide。
Properties
属性
Texture
贴图 Reference to the Texture that will be used as the texture’s display.
参考将被用于贴图显示的Texture。
Color
颜色 Color that will tint the Texture drawn on screen.
绘制在屏幕上的贴图所着的颜色。
Pixel Inset
像素插入 Used for pixel-level control of the scaling and positioning of the GUI Texture. All values are measured relative to the position of the GUI Texture’s Transform.
用于控制GUI贴图缩放和位置的像素级别的控制。所有的数值的测量都是依据GUI贴图形变的位置。
X
X Left-most pixel position of the texture.
贴图的最左端像素位置。
Y
Y Bottom-most pixel position of the texture.
贴图的最下端像素位置。
Width
宽度 Right-most pixel position of the texture.
贴图的最右端像素位置。
Height
高度 Top-most pixel position of the texture.
贴图的最上端像素位置。
Left Border
左边界 Number of pixels from the left that are not affected by scale.
在左端,不受缩放影响的边框的像素个数。
Right Border
右边界 Number of pixels from the right that are not affected by scale.
在右端,不受缩放影响的边框的像素个数。
Top Border
上边界 Number of pixels from the top that are not affected by scale.
在上端,不受缩放影响的边框的像素个数。
Bottom Border
下边界 Number of pixels from the bottom that are not affected by scale.
在下端,不受缩放影响的边框的像素个数。
Details
细节
To create a GUITexture:
创造一个GUI贴图:
1. Select a Texture in the Project View
2. Choose GameObject->Create Other->GUI Texture from the menu bar
在项目视图中选择一个贴图
从菜单从菜单栏中选择GameObject->Create Other->GUI Texture
GUI Textures are perfect for presenting game interface backgrounds, buttons, or other elements to the player. Through scripting, you can easily provide visual feedback for different “states” of the texture — when the mouse is hovering over the texture, or is actively clicking it for example. Here is the basic breakdown of how the GUI Texture is calculated:
GUI贴图适合于在游戏中,对用户的游戏接口背景,按键和其他元件。通过脚本,你可以轻松的提高贴图的不同状态的可视化反馈—当鼠标略过贴图时候,或者被点击激活后。这里是GUI贴图如何计算的基本分类:
GUI Textures are laid out according to these rules
GUI贴图的摆放是根据他们的规则。
The GUI elements seen here were all created with GUI Textures
这里看到的GUI元件都是由GUI贴图制作的。
Borders
边界
The number of pixels that will not scale with the texture at each edge of the image. As you rarely know the resolution your game runs in, chances are your GUI will get scaled. Some GUI textures have a border at the edge that is meant to be an exact number of pixels. In order for this to work, set the border sizes to match those from the texture.
边界指的是图像的每一个边框,这个边框的像素数量是不随着图片缩放而变化的。尽管你很少知道你所运行的游戏的分辨率,你仍有机会调整缩放你的GUI。GUI贴图都一个拥有固定像素个数的边框在边缘处。要让这些起作用,就为这些贴图设置合适的边框尺寸。
Pixel Inset
像素插入
The purpose of the Pixel Inset is to prevent textures from scaling with screen resolution, and keeping thim in a fixed pixel size. This allows you to render a texture without any scaling. This means that players who run your game in higher resolutions will see your textures in smaller areas of the screen, allowing them to have more screen real-estate for your gameplay graphics.
像素插入的目的是为防止贴图以屏幕分辨率缩放过程中,让他们保持在一个固定的像素尺寸。这允许你不用任何缩放,就能渲染一个贴图。这意味着运行游戏的玩家在一个高分辨率的屏幕中,看到你的贴图只是这个屏幕的一块区域,允许他们为你的显卡节约更多的资源。
To use it effectively, you need to set the scale of the GUI Texture’s Transform to (0, 0, 0). Now, the Pixel Inset is in full control of the texture’s size and you can set the Pixel Inset values to be the exact pixel size of your Texture.
为了有效地使用,你需要设置GUI贴图的变形缩放参数到(0,0,0)。现在,像素插入功能已经可以实现贴图尺寸的全部控制功能了,你可以设置像素插入数值为你的贴图的精确的像素数值。
Hints
提示
• The depth of each layered GUI Texture is determined by its individual Z Transform position, not the global Z position.
• GUI Textures are great for making menu screens, or pause/escape menu screens.
• You should use Pixel Inset on any GUI Textures that you want to be a specific number of pixels for the width and height.
每一层的GUI贴图都由独立的Z变形位置来检测,而不是全局的Z位置。
GUI贴图适合于制作菜单屏幕,或者停止/退出菜单屏幕。
如果你想是一个指定高度和宽度的GUI贴图,你也可以使用像素插入来实现。