Version: 2022.3
创建用于等距瓦片地图的瓦片面板
可编程画笔

Tilemap Renderer 模式

Tilemap Renderer 组件用于渲染场景中的瓦片地图 (Tilemap)。Unity 会创建默认附加了 Tilemap Renderer 组件的瓦片地图。Tilemap Renderer 可以:

The Render Mode affects the sorting of Tilemap Sprites when rendered.

在 Chunk Mode 模式下进行批量渲染

Chunk Mode 是 Tilemap Renderer 的默认渲染模式:

When set to Chunk Mode, the Tilemap Renderer handles Sprites on a Tilemap in batches and renders them together. They’re treated as a single sort item when sorted in the 2D Transparent Queue. While this reduces draw calls, other renderers can’t render between any part of the Tilemap, preventing other rendered Sprites from interweaving with Tilemap Sprites.

使用精灵图集进行排序(仅限 Chunk Mode 模式)

In Chunk Mode, the Tilemap Renderer isn’t able to sort Tiles from multiple textures individually and doesn’t render the tile sprites consistently (refer to the example below).

将构成瓦片地图的所有精灵个体打包到单个精灵图集中可解决此问题。为此需要执行以下操作:

  1. 从 Assets 菜单创建精灵图集(选择:Atlas > Create > Sprite Atlas)。

  2. 向精灵图集添加精灵,方法是在精灵图集的 Inspector 窗口中将精灵拖到 Objects for Packing 列表中。

  3. 单击 Pack Preview。Unity 在播放模式下将精灵打包到精灵图集中,并正确排序和渲染精灵。仅播放模式下在 Editor 中可见。 标签

在 Individual Mode 模式下进行单独渲染

Individual Mode 模式下,Tilemap Renderer 会对瓦片地图上的精灵进行排序和渲染,同时考虑场景中的其他渲染器,例如 Sprite RendererMesh Renderer。如果其他渲染器与瓦片地图上的精灵和对象进行交互,请使用此模式。

In this mode, the Tilemap Renderer sorts sprites based on their position on the Tilemap and the sorting properties set in the Tilemap Renderer. For example, this allows a character sprite to go in-between obstacle sprites (refer to the example below).

在 Individual Mode 模式下,角色精灵可在塔楼精灵后面渲染,也出现在地面精灵之上。
在 Individual Mode 模式下,角色精灵可在塔楼精灵后面渲染,也出现在地面精灵之上。

Using the same example in Chunk Mode, character sprites might get hidden behind ground sprites:

同样的场景在 Chunk Mode 模式下的渲染结果。
同样的场景在 Chunk Mode 模式下的渲染结果。

Using Individual Mode might reduce performance as there is more overhead when rendering each sprite individually on the Tilemap.

Individual Mode 模式下的 Z as Y Tilemap 瓦片地图的 Custom Axis 排序模式

To sort and render tile sprites on an Isometric Z as Y Tilemap, set the Transparency Sort Axis to a Custom Axis. To do this:

  1. Set the Tilemap Renderer component Mode to Individual.
  2. Navigate to Edit > Project Settings > Graphics.
  3. Set Transparency Sort Mode to Custom Axis.
  4. Set the Transparency Sort Axis Y-value to 1 and the Z-value to –0.26.

Refer to the page on Creating an Isometric Tilemap for more information about the Transparency Sort Axis settings.

创建用于等距瓦片地图的瓦片面板
可编程画笔