RegisterProcessConsoleExecPreHook
注册一个回调,在调用 UObject::ProcessConsoleExec 前执行。
除字符串、布尔值和 FOutputDevice 外,参数必须通过 Param:Get() 读取,通过 Param:Set() 设置。
如果回调不返回任何值(或返回 nil),则使用 ProcessConsoleExec 的原返回值。
如果回调返回 true 或 false,该值会覆盖 ProcessConsoleExec 的原返回值。
参数
| # | 类型 | 说明 |
|---|---|---|
| 1 | function | 要注册的回调 |
回调参数
| # | 类型 | 说明 |
|---|---|---|
| 1 | UObject | 对象上下文 |
| 2 | string | 完整命令字符串 |
| 3 | table | 全部命令组成部分,包括命令名称 |
| 4 | FOutputDevice | AR 输出设备 |
| 5 | UObject | 执行者 |
回调返回值
| # | 类型 | 说明 |
|---|---|---|
| 1 | bool | 是否覆盖 ProcessConsoleExec 的原返回值 |
示例
RegisterProcessConsoleExecPreHook(function(Context, FullCommand, CommandParts, Ar, Executor)
print("RegisterProcessConsoleExecPreHook:\n")
local ContextObject = Context:get()
local ExecutorObject = Executor:get()
print(string.format("Context FullName: %s\n", ContextObject:GetFullName()))
if ExecutorObject:IsValid() then
print(string.format("Executor FullName: %s\n", ExecutorObject:GetFullName()))
end
print(string.format("Command: %s\n", FullCommand))
print(string.format("Number of command parts: %i\n", #CommandParts))
if #CommandParts > 0 then
print(string.format("Command Name: %s\n", CommandParts[1]))
for PartNumber, CommandPart in ipairs(CommandParts) do
print(string.format("CommandPart: #%i -> '%s'\n", PartNumber, CommandPart))
end
end
Ar:Log("Write something to game console")
return true
end)
-- Entered into console: CommandExample param1 "param 2" 3
-- Output
--[[
RegisterProcessConsoleExecPreHook:
Context FullName: GameState /Game/Maps/Map_MainMenu.Map_MainMenu:PersistentLevel.GameState_2147479851
Executor FullName: BP_MainMenuPawn_C /Game/Maps/Map_MainMenu.Map_MainMenu:PersistentLevel.BP_MainMenuPawn_C_2147479061
Command: CommandExample param1 "param 2" 3
Number of command parts: 4
Command Name: CommandExample
CommandPart: #1 -> 'CommandExample'
CommandPart: #2 -> 'param1'
CommandPart: #3 -> 'param 2'
CommandPart: #4 -> '3'
--]]
原文:docs/lua-api/global-functions/registerprocessconsoleexecprehook.md · 固定提交 560411f18512 · 来源与 MIT 许可