Version: 2020.1
创建瓦片
在瓦片地图上绘制

Creating a Tile Palette

Place a selection of Tiles onto Tile Palettes so that you can pick Tiles from the Palette to paint on Tilemaps. To create a Tile Palette, open the Tile Palette window by going to Window > 2D > Tile Palette. If you do not have this option, then the 2D Tilemap Editor package may not be installed. If so, download the 2D Tilemap Editor package from the Package Manager.

The Tile Palette window is empty by default. Select the New Palette drop-down menu to open a list of Tile Palettes available in the Project, or for the option to create a new Palette. Select the Create New Palette option to create a new Palette.

Select the Create New Palette option from the drop-down menu.
Select the Create New Palette option from the drop-down menu.

After selecting the option to create anew Palette, the Create New Palette dialog box becomes available. It contains the different property settings and options available when creating a new Palette:

Create New Palette options. Expanded Grid options.

属性 功能
Name 为创建的瓦片面板资源提供一个名称。
Grid 选择要将创建的瓦片面板绘制到的网格布局。
    Rectangle 如果要为默认矩形瓦片地图创建面板,请选择此选项。
    Hexagon 如果要为六边形瓦片地图 (Hexagonal Tilemap) 创建面板,请选择此选项。
    Isometric 如果要为等距瓦片地图 (Isometric Tilemap) 创建面板,请选择此选项。请参阅创建用于等距瓦片地图的瓦片面板以了解更多信息。
Isometric Z as Y 如果要为 Isometric Z as Y Tilemap 创建面板,请选择此选项。请参阅创建用于等距瓦片地图的瓦片面板以了解更多信息。
     * Hexagon Type(仅当 Grid 类型设置为 Hexagon 时可用) 选择要将瓦片面板绘制到的六边形瓦片地图的类型。请参阅有关六边形瓦片地图的文档以了解更多信息。
Cell Size 要将瓦片绘制到的单元格的大小。
    Automatic Cell Size 以 Unity 单位自动设置,并基于用于创建瓦片资源的精灵的大小。如果有多个瓦片,则会调整 Cell Size 以匹配面板左下角的第一个瓦片,使其完全适合单元格。
    Manual 选择此选项可输入自定义大小值。

Give the newly create Palette a name and select the desired settings, then select the Create button. Select the folder to save the Palette Asset file into when prompted. The newly created Palette is automatically loaded in the Tile Palette window.

A blank Tile Palette
A blank Tile Palette

Drag and drop Textures or Sprites from the Assets folder onto the Tile Palette, and choose where to save the new Tile Assets when prompted. New Tile Assets are generated in the selected save location, and the Tiles are placed on the grid of the active Tile Palette window.

使用以下快捷方式和操作来导航 Palette 窗口,并开始在编辑器窗口中选取瓦片以在瓦片地图上绘制

快捷方式/操作 功能
单击一个瓦片 选择瓦片
选择并将鼠标拖过多个瓦片 选择多个瓦片
Alt + 鼠标左键并拖动 平移
__ 单击鼠标中键并拖动__ 平移
旋转滚轮键 放大/缩小

Active Brush Inspector

Active Brush Inspector 位于 Tile Palette 窗口底部。在此处可以更改当前有效的画笔及其属性。默认情况下会最小化。要将其展开,请向上拖动底部的工具栏。

Brush drop-down menu highlighted.
Brush drop-down menu highlighted.

Use the ‘Brush’ drop-down menu to change the active Brush from the ‘Default Brush’ to other Brushes, such as Scriptable Brushes.

属性 功能
Script 显示当前分配的脚本资源,该资源为瓦片地图的绘制提供一组固定的 API。默认为 GridBrush。用户可以使用或创建自己的可编写脚本的画笔,以供从下拉选单中使用。Script 属性更新以反映当前活动的画笔。
Can Change Z Position 启用此属性可更改活动画笔的 z 位置。禁用则防止对活动画笔的当前 z 位置进行任何更改。
Z Position 仅在启用 Can Change Z Position 时可用。为此画笔输入绘制瓦片时所需的 z 轴值(仅限整数),这也会调整 Z as Y 等距瓦片地图 上瓦片的相对高度。请参阅有关在瓦片面板中调整瓦片高度的文档以了解更多信息。

编辑瓦片面板 (Tile Palette)

The tools for picking and painting with Tiles can also be used to edit the Tile Palette directly, allowing you to move and manipulate the Tiles currently placed on the Tile Palette. Select the Palette you want to edit from the ‘Palette’ drop-down menu, then click Edit to unlock the Palette for editing.

请参阅关于在瓦片地图上绘制的文档,了解面板工具的快捷方式和功能,这些工具同样可用于编辑面板。

从现有网格预制件创建面板资源

您可以将现有的预制件转换为面板资源,以便在 Tile Palette 窗口中使用。为此,预制件不能已经是面板资源,并且在其最顶层的游戏对象上必须有一个 Grid 组件。

Tile Palette 工具栏
Tile Palette 工具栏

要转换预制件,请将其拖放到 Tile Palette 工具栏上(在上图中突出显示)。编辑器会自动将其转换为面板资源,并添加网格面板资源。新的面板资源与其源的名称相同,并可从 Palette 下拉选单中选择。

瓦片面板小工具

瓦片面板可在当前面板资源上显示图标(小工具),以帮助您可视化特定条件。例如,您可以添加一个为不包含精灵的瓦片显示特殊图标的小工具。

要在瓦片面板上显示默认的 Unity 和瓦片资源的小工具,请启用 Gizmos 开关(在上图中突出显示)。瓦片面板会立即显示面板资源中任何带有 MonoBehaviour.OnDrawGizmos() 的组件。

要将带有 DrawGizmo 的组件添加到面板资源:

  1. 在 Project 窗口中选择面板资源。

  2. 预制件模式打开面板资源。

  3. 在预制件模式下添加组件。

  4. 在预制件模式下保存资源。

  5. 退出预制件模式。


  • 页面内容和屏幕截图更新于 2020.1 NewIn20201
  • 2017.2 版中添加了瓦片地图 NewIn20172
创建瓦片
在瓦片地图上绘制