LUACN论坛

 找回密码
 加入我们

QQ登录

只需一步,快速开始

搜索
热搜: YJWOW MagicStone BoL
查看: 199|回复: 0

[综合] 【搬运Wowpedia】事件Events(二)

[复制链接]
发表于 2023-7-9 23:45:03 | 显示全部楼层 |阅读模式
本帖最后由 懒动行不行 于 2023-7-10 10:08 AM 编辑

EventRegistry

来源: SharedXML\GlobalCallbackRegistry.lua

回调事件
事件注册Details
  • 需要注意的是,如果通过事件注册表注册的某个函数执行时间过长(脚本超时),则注册表中同一事件的所有其他回调也可能无法执行。
  • EventRegistry事件及其有效载荷在触发时显示在 Event Trace 面板中。

例子
常见的使用案例是注册暴雪回调事件, 例如当Mount Journa(坐骑日志)打开时( opened)
[Lua] 纯文本查看 复制代码
EventRegistry:RegisterCallback("MountJournal.OnShow", function()
        print("showed the mount journal")
end)

注册对自定义事件的两个回调.

[Lua] 纯文本查看 复制代码
local function a(ownerID, ...)
        print("a", ...) -- prints "a", "foo", "bar"
end

local function b(ownerID, ...)
        print("b", ...) -- prints "b", "foo", "bar"
end

EventRegistry:RegisterCallback("HelloWorld.OnSomething", a)
EventRegistry:RegisterCallback("HelloWorld.OnSomething", b)

-- /run EventRegistry:TriggerEvent("HelloWorld.OnSomething", "foo", "bar")

注销
回调由所有者句柄注销。注册回调时,所有者可以是表、函数或字符串;如果省略,它将被分配一个内部编号。[1]

[Lua] 纯文本查看 复制代码
local cb = function(ownerID, journal, tabID)
        print("switched to collections tab", tabID)
end

local ownerID = EventRegistry:RegisterCallback("CollectionsJournal.TabSet", cb) -- omitted owner param

Example = ownerID
-- /run EventRegistry:UnregisterCallback("CollectionsJournal.TabSet", Example)

框架事件
这允许您响应事件,而无需创建框架并向其注册事件。
[Lua] 纯文本查看 复制代码
EventRegistry:RegisterFrameEventAndCallback("PLAYER_ENTERING_WORLD", function(ownerID, ...)
        print(...) -- on login this prints: "foo", "bar", true, false
end, nil, "foo", "bar")

私有回调注册
创建您自己的CallbackRegistry对象,而不是使用EventRegistry。
[Lua] 纯文本查看 复制代码
local cr = CreateFromMixins(CallbackRegistryMixin)
cr:OnLoad()
cr:SetUndefinedEventsAllowed(true)
cr:RegisterCallback("MyCustomEvent", function(ownerID, ...)
        print("a", ...) -- prints "a", "foo", "bar"
end)

Example = cr
-- /run Example:TriggerEvent("MyCustomEvent", "foo", "bar")

外链
Search FrameXML for TriggerEvent











本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?加入我们

x
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 加入我们

本版积分规则

小黑屋|手机版|Archiver|LUACN论坛

GMT+8, 2024-5-2 08:42 PM , Processed in 0.042080 second(s), 14 queries , Gzip On, Redis On.

Powered by Discuz! X3.4

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表