精灵渲染器 (Sprite Renderer)
Sprite Renderer
组件用于渲染__精灵__并控制其在
2D 和 3D 项目
场景中的可视化效果。
创建精灵 (
GameObject > 2D Object > Sprite
) 时,Unity 会自动创建一个附加了
Sprite Renderer
组件的游戏对象。还可以通过
Components
菜单 (
Component > Rendering > Sprite Renderer
) 将该组件添加到现有的游戏对象。
Sprite Renderer Inspector
Size
(Sliced 或 Tiled)
输入精灵的新 Width 和 Height 值以正确缩放 9 切片精灵。在应用 9 切片属性时,也可使用
矩形变换组件工具
来缩放精灵。
Tiled
默认情况下,此模式会使 9 切片精灵的中间部分在精灵尺寸发生变化时平铺而不是缩放。使用
Tile Mode
可控制精灵的平铺行为。
Continuous
这是默认的
Tile Mode
设置。在 Continuous 模式下,当精灵尺寸发生变化时,中间部分会均匀地平铺。
Adaptive
在 Adaptive 模式下,精灵纹理在尺寸发生变化时会拉伸,类似于 Simple 模式。当更改的尺寸的缩放大小达到 Stretch Value 时,中间部分开始平铺。
Stretch Value
使用滑动条设置 0 到 1 之间的值。最大值为 1,表示原始精灵缩放的两倍。
Sorting Layer
设置精灵的
排序图层 (Sorting Layer)
,此图层用于控制渲染期间的精灵优先级。从下拉框中选择现有的排序图层,或创建新的排序图层。
Order In Layer
设置精灵在其
排序图层
中的渲染优先级。首先渲染编号较低的精灵,编号较高的精灵叠加在前者之上。
Mask Interaction
设置精灵渲染器在与
精灵遮罩
交互时的行为方式。请参阅下面的
遮罩交互 (Mask Interaction)
部分中不同选项的示例。
The Sprite Renderer does not interact with any Sprite Mask in the Scene. This is the default option.
Visible Inside Mask
精灵在精灵遮罩覆盖精灵的地方是可见的,而在遮罩外部不可见。
Visible Outside Mask
The Sprite is visible outside the Sprite Mask, but not inside it. The Sprite Mask hides the sections of the Sprite it overlays.
Sprite Sort Point
在计算精灵和摄像机之间的距离时,在精灵中心 (Center) 或其轴心点 (Pivot Point) 之间进行选择。请参阅
精灵排序点 (Sprite Sort Point)
部分以了解更多详细信息。
使用材质的
材质和着色器设置
可控制 Unity 如何渲染材质。请参阅
材质、着色器和纹理
以了解有关这些设置的更多信息。
新创建的精灵的默认材质为
Sprites - Default
。场景光照不会影响此默认精灵。要让精灵对光照做出反应,请指定材质
Default - Diffuse
。要执行此操作,请单击 Material 字段旁边的小圆圈以显示对象选择器窗口,然后选择
Default-Diffuse
材质。
遮罩交互 (Mask Interaction)
遮罩交互可控制精灵渲染器与
精灵遮罩
交互的方式。从下拉菜单中选择
Visible Inside Mask
或
Visible Outside Mask
。以下示例演示了使用方形精灵和圆形遮罩时每个选项的影响:
要与精灵遮罩进行交互,请从下拉菜单中选择
Visible Inside Mask
或
Visible Outside Mask
。
在 2D 项目中,主摄像机 (Main Camera) 默认设置为
正交投影 (Orthographic Projection) 模式
。在此模式下,Unity 按照精灵相对于摄像机的距离(沿着摄像机视图的方向)的顺序渲染精灵。
正交摄像机:
Side 视图(上)和 Game 视图(下)
By default, a Sprite’s
Sort Point
is set to its
Center
, and Unity measures the distance between the camera’s Transform position and the
Center
of the Sprite to determine their render order.
To set to a different
Sort Point
from the
Center
, select the
Pivot
option. Edit the Sprite’s
Pivot
position in the
Sprite Editor
.
2018–10–05 页面已修订并进行了
编辑审查
Ability to sort Sprite-based renderers using the pivot position added in
2017.3
NewIn20173