学习
引擎类
ReflectionService
无法创建
服务
未复制

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


概要
方法
GetClass(className: string,filter: Dictionary):ReflectedClass?
GetClasses(filter: Dictionary):{ReflectedClass}
GetEventsOfClass(className: string,filter: Dictionary):{ReflectedEvent}
GetMethodsOfClass(className: string,filter: Dictionary):{ReflectedMethod}
GetPropertiesOfClass(className: string,filter: Dictionary):{ReflectedProperty}
继承成员
代码示例
ReflectionService 概述
local ReflectionService = game:GetService("ReflectionService")
-- 创建一个具有所有能力的 SecurityCapabilities 对象
local allCapabilities = SecurityCapabilities.new(table.unpack(Enum.SecurityCapability:GetEnumItems()))
-- 获取所有可访问的类,具有所有能力
local allClasses = ReflectionService:GetClasses({ Security = allCapabilities })
print("总类数:", #allClasses)
-- 获取特定类
local partClass = ReflectionService:GetClass("Part")
if partClass then
print("\nPart 类:")
print(" 名称:", partClass.Name)
print(" 超类:", partClass.Superclass and tostring(partClass.Superclass) or "无")
end
-- 获取类的前 5 个属性
local properties = ReflectionService:GetPropertiesOfClass("Part", { Security = allCapabilities })
print("\nPart 属性:", #properties)
for i = 1, math.min(5, #properties) do
print(" -", properties[i].Name)
end

API 参考
方法
GetClass
ReflectionService:GetClass(
className:string, filter:Dictionary
):ReflectedClass?
参数
className:string
filter:Dictionary
默认值:"nil"
返回
ReflectedClass?

GetClasses
ReflectionService:GetClasses(filter:Dictionary):{ReflectedClass}
参数
filter:Dictionary
默认值:"nil"
返回
{ReflectedClass}

GetEventsOfClass
ReflectionService:GetEventsOfClass(
className:string, filter:Dictionary
):{ReflectedEvent}
参数
className:string
filter:Dictionary
默认值:"nil"
返回
{ReflectedEvent}

GetMethodsOfClass
ReflectionService:GetMethodsOfClass(
className:string, filter:Dictionary
):{ReflectedMethod}
参数
className:string
filter:Dictionary
默认值:"nil"
返回
{ReflectedMethod}

GetPropertiesOfClass
ReflectionService:GetPropertiesOfClass(
className:string, filter:Dictionary
):{ReflectedProperty}
参数
className:string
filter:Dictionary
默认值:"nil"
返回
{ReflectedProperty}

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。