主题
SelectionService
Selection 选择管理服务。 管理编辑器中当前选中的 Unit,支持获取、替换、追加和移除选中。
Overview
该服务负责管理编辑器当前选中的单位集合,统一维护选中状态,并提供整体替换、追加与移除等操作入口。基于它可以在脚本中同步读取或修改编辑器选中内容,是实现批量编辑与联动操作的基础服务。
Get by:
lua
-- @runtime client
local service = editor:GetService("Selection")Public
Get
获取当前选中对象列表。该服务维护一份当前的选中集合,此方法用于读取这份选中结果。
返回值
| 类型 | 说明 |
|---|---|
Array | 当前选中的单位数组 |
调用 Get
lua
-- @runtime client
local selectionService = editor:GetService("Selection")
local result = selectionService:Get() -- 返回 Array
if result ~= nil then
for index, item in ipairs(result) do
print(index, item)
end
endSet
用指定单位数组替换当前选中集合中的全部内容。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
units | Array | Unit 对象列表 |
调用 Set
lua
-- @runtime client
local selectionService = editor:GetService("Selection")
local units = {} -- Array
selectionService:Set(units)
print("已调用 Set", units)Add
向当前选中集合中追加指定单位,追加不会替换已有的选中内容。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
units | Array | Unit 对象列表 |
调用 Add
lua
-- @runtime client
local selectionService = editor:GetService("Selection")
local units = {} -- Array
selectionService:Add(units)
print("调用完成", selectionService)Remove
从当前选中集合中移除指定单位。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
units | Array | Unit 对象列表 |
调用 Remove
lua
-- @runtime client
local selectionService = editor:GetService("Selection")
local units = {} -- Array
selectionService:Remove(units)
print("调用完成", selectionService)