主题
DebugService
Debug 调试信息服务,提供单位模型面数/物理面数、碰撞体信息、空间区域统计与全场景统计等调试信息查询。
概览
调试信息服务用于在编辑器环境中提供资源与碰撞相关的量化数据:既能统计单个单位的模型面数与物理碰撞体面数,也能读取碰撞体体积和包围盒各方向的尺寸;还可按最小坐标与最大坐标划定的空间区域汇总单位列表与面数明细。它面向排查性能开销、核对碰撞配置等调试场景,区域明细可写入文件便于逐项查看。
Get by:
lua
-- @runtime editor
local service = editor:GetService("DebugService")函数
GetUnitModelFaceCount
获取指定单位模型的面的数量,返回整数形式的模型面数。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
unit | Unit | 要查询的单位对象 |
includeChildren | Bool | 是否包含子组件;默认 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
获取指定单位物理碰撞体的面的数量,返回整数形式的物理碰撞体面数。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
unit | Unit | 要查询的单位对象 |
includeChildren | Bool | 是否包含子组件;默认 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
获取指定单位碰撞体包围盒的体积,以浮点数形式返回。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
unit | Unit | 要查询的单位对象 |
返回值
| 类型 | 说明 |
|---|---|
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] 数组的形式返回三个方向上的长度。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
unit | Unit | 要查询的单位对象 |
返回值
| 类型 | 说明 |
|---|---|
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
统计指定空间区域内的调试信息,返回一个表,其中包含该区域的模型面数、物理面数和单位数三项统计数据。
参数
| 参数 | 类型 | 说明 |
|---|---|---|
minPos | Array | 区域最小角点 [x, y, z];也接受 Vector3 |
maxPos | Array | 区域最大角点 [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 | Array | 区域最小角点 [x, y, z];也接受 Vector3 |
maxPos | Array | 区域最大角点 [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)