Attention: Here be dragons

This is the latest (unstable) version of this documentation, which may document features not available in or compatible with released stable versions of Godot.

TileSetScenesCollectionSource

继承: TileSetSource < Resource < RefCounted < Object

以图块的形式向 TileSet 资源暴露一组场景。

描述

当放置在 TileMap 上时,来自 TileSetScenesCollectionSource 的图块将自动在 TileMap 中单元格的位置上实例化相关场景。

TileMap 进入树时,场景被实例化为 TileMap 的子级。如果在 TileMap 中添加/移除已经在树内的场景图块,TileMap 将自动实例化/释放相应的场景。

注意:场景图块占用同一个图块槽,使用备用图块 ID 来标识场景索引。TileSetSource.get_tiles_count() 将始终返回 1。使用 get_scene_tiles_count() 获取 TileSetScenesCollectionSource 中的场景数量。

如果想在 TileMapLayer 中查找给定图块的场景路径,请使用此代码:

var source_id = tile_map_layer.get_cell_source_id(Vector2i(x, y))
if source_id > -1:
    var scene_source = tile_map_layer.tile_set.get_source(source_id)
    if scene_source is TileSetScenesCollectionSource:
        var alt_id = tile_map_layer.get_cell_alternative_tile(Vector2i(x, y))
        # 分配的 PackedScene。
        var scene = scene_source.get_scene_tile_scene(alt_id)

方法

int

create_scene_tile(packed_scene: PackedScene, id_override: int = -1)

int

get_next_scene_tile_id() const

bool

get_scene_tile_display_placeholder(id: int) const

int

get_scene_tile_id(index: int)

PackedScene

get_scene_tile_scene(id: int) const

int

get_scene_tiles_count()

bool

has_scene_tile_id(id: int)

void

remove_scene_tile(id: int)

void

set_scene_tile_display_placeholder(id: int, display_placeholder: bool)

void

set_scene_tile_id(id: int, new_id: int)

void

set_scene_tile_scene(id: int, packed_scene: PackedScene)


方法说明

int create_scene_tile(packed_scene: PackedScene, id_override: int = -1) 🔗

从给定的场景创建基于场景的图块。

返回新生成的唯一 ID。


int get_next_scene_tile_id() const 🔗

返回后续调用 create_scene_tile() 时会返回的场景 ID。


bool get_scene_tile_display_placeholder(id: int) const 🔗

返回 ID 为 id 的场景图块是否在编辑器中显示占位图。


int get_scene_tile_id(index: int) 🔗

返回索引为 index 的场景图块的场景图块 ID。


PackedScene get_scene_tile_scene(id: int) const 🔗

返回 ID 为 id 的场景图块的 PackedScene 资源。


int get_scene_tiles_count() 🔗

返回该 TileSet 源中场景图块的数量。


bool has_scene_tile_id(id: int) 🔗

返回该 TileSet 源是否包含 ID 为 id 的场景图块。


void remove_scene_tile(id: int) 🔗

移除 ID 为 id 的场景图块。


void set_scene_tile_display_placeholder(id: int, display_placeholder: bool) 🔗

设置 ID 为 id 的场景图块是否应该在编辑器中显示为占位符。对不可见的场景可能有用。


void set_scene_tile_id(id: int, new_id: int) 🔗

将场景图块的 ID 从 id 改为 new_id。如果已经存在 ID 为 new_id 的图块则会失败。


void set_scene_tile_scene(id: int, packed_scene: PackedScene) 🔗

PackedScene 资源分配给 ID 为 id 的场景图块。如果该场景扩展的不是 CanvasItem 则会失败,因为将场景放置到 TileMap 上需要位置属性。