Tilemap 组件是一个存储和处理瓦片资源以便创建 2D 关卡的系统。此组件将所需信息从放置在组件上的瓦片传输到其他相关组件,例如 Tilemap Renderer 和 Tilemap Collider 2D。
Use this component with the Grid component, or a parent Grid GameObject, to lay out Tiles on the associated Grid. When creating a Tilemap (menu: GameObject > 2D Object > Tilemap), Unity automatically creates a Grid GameObject and sets it as the parent of a child Tilemap GameObject.
要修改瓦片并将其放置到瓦片地图上,请打开瓦片面板 (Tile Palette)(菜单:Window > 2D > Tile Palette)。请参阅有关瓦片面板和绘制瓦片地图的文档以了解更多信息。
属性 | 功能 |
---|---|
Animation Frame Rate | Unity 播放瓦片动画的速率。增加或减少此值会根据等效因子更改速度(例如,如果将此值设置为 2,Unity 将以两倍速度播放瓦片动画)。 |
Color | 使用所选颜色为此瓦片地图上的瓦片进行着色。设置为白色时,Unity 会渲染没有色调的瓦片。 |
Tile Anchor | 此瓦片地图上瓦片的锚定偏移。通过调整位置值可以偏移关联网格上瓦片的单元格位置。 |
Orientation | 瓦片地图上瓦片的方向。如果需要在特定平面上定位瓦片(尤其是在 3D 视图中),请使用此属性。 |
XY | Unity 在 XY 平面上定位瓦片。 |
XZ | Unity 在 XZ 平面上定位瓦片。 |
YX | Unity 在 YX 平面上定位瓦片。 |
YZ | Unity 在 YZ 平面上定位瓦片。 |
ZX | Unity 在 ZX 平面上定位瓦片。 |
ZY | Unity 在 ZY 平面上定位瓦片。 |
Custom | Unity 根据下方参数设置的自定义方向矩阵设置来布置瓦片,当选择此选项时,这些设置将变为可编辑。 |
Position | 显示当前方向矩阵的位置偏移。 只有在 Tilemap 的 Orientation 设置为 Custom 时才能编辑此属性。 |
Rotation | 当前方向矩阵的旋转。 只有在 Tilemap 的 Orientation 设置为 Custom 时才能编辑此属性。 |
Scale | 当前方向矩阵的缩放。 只有在 Tilemap 的 Orientation 设置为 Custom 时才能编辑此属性。 |
以下是创建和绘制__瓦片地图__的一般工作流程:
1.创建 Tilemap 游戏对象。此过程还会自动创建 Grid 游戏对象。 2.直接创建瓦片资源,或从精灵生成瓦片。 3.使用所选的__瓦片资源__创建瓦片面板。 4.使用__瓦片面板__在__瓦片地图__上进行绘制。 5.(可选)可将 Tilemap Collider 2D 组件连接到瓦片地图以便使瓦片地图与 Physics2D 交互。
Unity 还支持特殊类型的瓦片地图,例如六边形 (Hexagonal) 和等距 (Isometric) 瓦片地图。有关这些瓦片地图的具体工作流程,请参阅各自页面上的文档。
可从 2D Extra GitHub 代码仓库下载脚本化瓦片和画笔的示例。可从 2D Techdemos Github 代码仓库获取包含这些脚本化游戏对象的示例项目。有关不同脚本和用法信息的描述,请参阅每个代码仓库的 README.md。
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.