表示在 2D 游戏中使用的精灵对象。
精灵 是一种 2D 图形对象,用于 2D 游戏中的角色、道具、飞弹和其他游戏元素。图形是从位图图像 Texture2D 获取的。Sprite 类主要标识应该用于特定精灵的图像部分。然后,GameObject 上的 SpriteRenderer 组件可以使用该信息来实际显示图形。
另请参阅:SpriteRenderer 类。
associatedAlphaSplitTexture | 返回包含源纹理的 Alpha 通道的纹理。对于源代码中具有 Alpha 通道、需要使用 ETC1 等技术进行压缩的精灵,Unity 在底层为其生成该纹理。如果源精灵没有关联的 Alpha 纹理,则返回 NULL。如果精灵尚未设置为使用 ETC1 压缩,就会出现这种情况。 |
border | 返回精灵的边框大小。 |
bounds | 精灵的 Bounds,由精灵的中心和范围(采用世界空间单位)指定。 |
packed | 如果该精灵打包在图集中,则返回 true。 |
packingMode | 如果精灵已打包(请参阅 Sprite.packed),则返回其 SpritePackingMode。 |
packingRotation | 如果精灵已打包(请参阅 Sprite.packed),则返回其 SpritePackingRotation。 |
pivot | 精灵的中心点在原始纹理的 Rect 中的位置(以像素为单位指定)。 |
pixelsPerUnit | 对应世界空间中一个单位的精灵中的像素数。(只读) |
rect | 精灵在原始纹理中的位置(以像素为单位指定)。 |
texture | 获取对使用的纹理的引用。如果已打包,则指向图集;如果未打包,则指向源精灵。 |
textureRect | 获取该精灵在其纹理上使用的矩形。如果该精灵紧密打包在图集中,则引发异常。 |
textureRectOffset | 获取该精灵在其纹理上使用的矩形到原始精灵边界的偏移。如果精灵网格类型为 FullRect,则偏移为零。 |
triangles | 返回包含精灵网格三角形的数组的副本。 |
uv | 精灵网格的基础纹理坐标。 |
vertices | 返回包含精灵网格顶点位置的数组的副本。 |
GetPhysicsShape | 按索引从精灵获取物理形状。 |
GetPhysicsShapeCount | 精灵的物理形状数量。 |
GetPhysicsShapePointCount | 所选的精灵物理形状中的点数。 |
OverrideGeometry | 设置新的精灵几何形状。 |
OverridePhysicsShape | 设置新的精灵物理形状。 |
Create | 创建新的 Sprite 对象。 |
GetInstanceID | 返回对象的实例 ID。 |
ToString | 返回对象的名称。 |
Destroy | 移除 GameObject、组件或资源。 |
DestroyImmediate | 立即销毁对象 /obj/。强烈建议您改用 Destroy。 |
DontDestroyOnLoad | 在加载新的 Scene 时,请勿销毁 Object。 |
FindObjectOfType | 返回第一个类型为 type 的已加载的激活对象。 |
FindObjectsOfType | 返回所有类型为 type 的已加载的激活对象的列表。 |
Instantiate | 克隆 original 对象并返回克隆对象。 |
bool | 该对象是否存在? |
operator != | 比较两个对象是否引用不同的对象。 |
operator == | 比较两个对象引用,判断它们是否引用同一个对象。 |
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.