监听器动作脚本(Listener Action Scripts)
监听器(Listeners) 会在状态机特定事件发生时触发。
监听器动作脚本(Listener Action Scripts)允许你在该时刻执行自定义逻辑(副作用)。
创建监听器动作脚本
创建新脚本 并选择 监听器动作(Listener Action Script)。
脚本结构(Anatomy)
type MyListenerAction = {
context: Context,
}
-- Called once when the script initializes.
function init(self: MyListenerAction, context: Context): boolean
-- Context gives you access to your main view model and other data.
self.context = context
return true
end
-- Called when the Listener fires.
-- Use this to perform side effects (no return value).
function perform(self: MyListenerAction, pointerEvent: PointerEvent)
end
-- Return a factory function that Rive uses to build the Listener Action instance.
return function(): ListenerAction<MyListenerAction>
return {
init = init,
perform = perform,
context = late(),
}
end