Skip to content

ContextActionService

成员函数

voidBindActivate (int userInputTypeForActivate, int keyCodeForActivate)
绑定激活
voidUnbindActivate (int userInputTypeForActivate, int keyCodeForActivate)
解绑激活
获取当前所有绑定的事件信息
获取当前绑定actionName的事件信息
SandboxNodeGetButton (string actionName)
通过绑定名称获取该按钮节点
获取当前本地tool图片
voidSetDescription (string actionName, string description)
设置描述
voidSetImage (string actionName, string image)
设置图片
voidSetPosition (string actionName, Vector2 position)
设置位置
voidSetTitle (string actionName, string title)
设置标题
voidBindContext (string actionname, LuaFunction func, bool createTouchBtn, ReflexVariant hotkey)
绑定一个回调函数到指定输入上
voidBindContextAtPriority (string actionname, LuaFunction func, bool createTouchBtn, int priority, ReflexVariant hotkey)
绑定一个回调函数到指定输入上,并指定优先级
voidUnbindContext (string actionname)
取消指定的用户绑定
voidUnbindAllContext ()
移除所有的函数绑定
voidCallFunction (string actionName, UserInputState state, SandboxNode inputObject)
lua回调函数
voidBindAction (string actionName, LuaFunction func, int nActionType, int nSubType)
这套新接口)
voidBindActionWithButton (string actionName, LuaFunction func, int nActionType, int nSubType)
这套新接口)
voidBindActionAtPriority (string actionName, LuaFunction func, int priority, int nActionType, int nSubType)
这套新接口)
voidUnbindAction (string actionName)
这套新接口)
voidUnbindAllActions ()
这套新接口)

事件

SBXSignalBoundActionChanged (string actionName, string propname, ReflexMap table)
当绑定行为发生改变时,会触发一个BoundActionChanged时间
SBXSignalBoundActionAdded (string actionName, bool bCreateTouchBtn, ReflexMap table)
新增某绑定行为
移除某绑定行为

代码示例

lua
-- 推荐使用
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:BindContext("WkeydownactionName", function(actionName, inputState, inputObj)
	if inputState == Enum.UserInputState.InputBegin.Value then
		print("ContextActionService begin", actionName)
	else
		print("ContextActionService end", actionName)
	end
end, false,  Enum.KeyCode.W )

-- 即将废弃
local ContextActionService = game:GetService("ContextActionService")
local curActionName = "moveForwardAction"
local function handleMoveForward(actionName, inputState, inputObj)
	print(actionName)     -- 打印 moveForwardAction
	if inputState == Enum.UserInputState.InputBegin.Value then
		self.ForwardBackValue = 1
	else
		self.ForwardBackValue = 0
	end
	self.LocalCharacter:Move(Vector3.New(self.LeftRightValue,0,self.ForwardBackValue),true)
end
ContextActionService:BindAction(
	curActionName,
	handleMoveForward,
	Enum.ContextActionType.KeyBoard.Value,
	Enum.KeyCode.W.Value )