Skip to content

DebugService ​

Debug 调试信息服务,提供单位模型面数/物理面数、碰撞体信息、空间区域统计与全场景统计等调试信息查询。

概览 ​

调试信息服务,用于统计单位在渲染与物理层面的开销数据。它既能按单位查询模型面数、物理碰撞体面数、碰撞体体积与碰撞体包围盒尺寸,也能按指定的空间区域统计面数信息并筛出落在区域内的单位,便于定位性能热点。层级明细还支持写入 JSON 文件以便进一步查看。

Get by:

lua
-- @runtime editor
local service = editor:GetService("DebugService")

函数 ​

GetUnitModelFaceCount ​

获取指定单位模型的面数。includeChildren 为可选参数,用于控制是否将子级一并统计。

参数

参数类型说明
unitUnit要查询的单位对象
includeChildrenBool是否包含子组件;默认 true

返回值

类型说明
Int模型面数

查询场景首个单位的模型面数

lua
-- @runtime editor
local units = editor:GetService("World"):GetDescendants()
local unit = units[1]
if unit == nil then return end
local debugService = editor:GetService("DebugService")
print(debugService:GetUnitModelFaceCount(unit, true))

GetUnitPhysicsFaceCount ​

获取指定单位物理碰撞体的面数。includeChildren 为可选参数,用于控制是否将子级一并统计。

参数

参数类型说明
unitUnit要查询的单位对象
includeChildrenBool是否包含子组件;默认 true

返回值

类型说明
Int物理碰撞体面数

查询场景首个单位的物理面数

lua
-- @runtime editor
local units = editor:GetService("World"):GetDescendants()
local unit = units[1]
if unit == nil then return end
local debugService = editor:GetService("DebugService")
print(debugService:GetUnitPhysicsFaceCount(unit, true))

GetUnitCollisionVolume ​

获取指定单位碰撞体包围盒的体积数值。

参数

参数类型说明
unitUnit要查询的单位对象

返回值

类型说明
Float碰撞体包围盒体积

查询场景首个单位的碰撞体体积

lua
-- @runtime editor
local units = editor:GetService("World"):GetDescendants()
local unit = units[1]
if unit == nil then return end
local debugService = editor:GetService("DebugService")
print(debugService:GetUnitCollisionVolume(unit))

GetUnitCollisionExtent ​

获取指定单位碰撞体包围盒的尺寸,返回值是按 [x, y, z] 排列的尺寸数组。

参数

参数类型说明
unitUnit要查询的单位对象

返回值

类型说明
Array包围盒尺寸 [x, y, z]

查询场景首个单位的碰撞体尺寸

lua
-- @runtime editor
local units = editor:GetService("World"):GetDescendants()
local unit = units[1]
if unit == nil then return end
local debugService = editor:GetService("DebugService")
local extent = debugService:GetUnitCollisionExtent(unit)
print(extent[1], extent[2], extent[3])

GetRegionFaceInfo ​

统计并返回指定区域内的调试信息表,表中包含模型面数、物理面数与单位数。

参数

参数类型说明
minPosArray区域最小角点 [x, y, z];也接受 Vector3
maxPosArray区域最大角点 [x, y, z];也接受 Vector3

返回值

类型说明
Table区域调试信息 {模型面数, 物理面数, 单位数}

统计原点附近区域的调试信息

lua
-- @runtime editor
local debugService = editor:GetService("DebugService")
local info = debugService:GetRegionFaceInfo({-100, -100, -100}, {100, 100, 100})
print("区域单位数:", info["单位数"])

GetRegionUnits ​

获取指定坐标区域内的单位列表。minPos 与 maxPos 分别给出区域的最小点与最大点,返回值为落在该区域内的单位对象列表。

参数

参数类型说明
minPosArray区域最小角点 [x, y, z];也接受 Vector3
maxPosArray区域最大角点 [x, y, z];也接受 Vector3

返回值

类型说明
Array区域内的单位对象列表

获取原点附近区域的单位

lua
-- @runtime editor
local debugService = editor:GetService("DebugService")
local units = debugService:GetRegionUnits({-100, -100, -100}, {100, 100, 100})
print("区域单位数:", #units)