요약
메서드
BindAction(actionName: string,functionToBind: function,createTouchButton: boolean,inputTypes: Tuple):() |
BindActionToInputTypes(actionName: string,functionToBind: function,createTouchButton: boolean,inputTypes: Tuple):() |
BindActivate(userInputTypeForActivation: Enum.UserInputType,keyCodesForActivation: Tuple):() |
GetBoundActionInfo(actionName: string):Dictionary |
SetDescription(actionName: string,description: string):() |
SetPosition(actionName: string,position: UDim2):() |
UnbindAction(actionName: string):() |
UnbindActivate(userInputTypeForActivation: Enum.UserInputType,keyCodeForActivation: Enum.KeyCode):() |
UnbindAllActions():() |
이벤트
LocalToolEquipped(toolEquipped: Instance):RBXScriptSignal |
LocalToolUnequipped(toolUnequipped: Instance):RBXScriptSignal |
상속된 멤버
코드 샘플
ContextActionService 도구 재장전
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "재장전"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("재장전 중!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)API 참조
메서드
BindAction
반환
()
코드 샘플
ContextActionService 도구 재장전
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "재장전"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("재장전 중!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)일반 작업 핸들러
local ContextActionService = game:GetService("ContextActionService")
local function handleAction(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("Handling action: " .. actionName)
print(inputObj.UserInputType)
end
-- 이 함수는 아무것도 반환하지 않기 때문에, 이 핸들러는
-- 입력을 "sink"하고 이후 다른 작업 핸들러는 호출되지 않습니다.
end
ContextActionService:BindAction("BoundAction", handleAction, false, Enum.KeyCode.F)스택 액션 핸들러
local ContextActionService = game:GetService("ContextActionService")
-- FirstAction에 대한 액션 핸들러 정의
local function actionHandlerOne(actionName, inputState, _inputObj)
if inputState == Enum.UserInputState.Begin then
print("액션 핸들러 원: " .. actionName)
end
-- 이 액션 핸들러는 nil을 반환하므로,
-- 이를 통해 액션을 제대로 처리한다고 가정합니다.
end
-- FirstAction(스택의 하단에 위치)에 액션 바인딩
ContextActionService:BindAction("FirstAction", actionHandlerOne, false, Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C)
-- SecondAction에 대한 액션 핸들러 정의
local function actionHandlerTwo(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("액션 핸들러 투: " .. actionName)
end
if inputObj.KeyCode == Enum.KeyCode.X then
return Enum.ContextActionResult.Pass
else
-- nil을 반환하면 암묵적으로 입력을 가라앉힙니다.
return Enum.ContextActionResult.Sink
end
end
-- 가장 최근에 바인딩된 FirstAction 위에 SecondAction 바인딩(스택의 상단에 위치)
-- SecondAction이 동일한 키를 사용한다는 점에 유의하세요.
ContextActionService:BindAction("SecondAction", actionHandlerTwo, false, Enum.KeyCode.Z, Enum.KeyCode.X)BindActionAtPriority
반환
()
코드 샘플
ContextActionService 바인드 액션 우선순위
local ContextActionService = game:GetService("ContextActionService")
local INPUT_KEY1 = Enum.KeyCode.Q
local INPUT_KEY2 = Enum.KeyCode.E
local function handleThrow(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print(`Action [{actionName}] occurred. KeyCode [{inputObject.KeyCode}] pressed.`)
return Enum.ContextActionResult.Sink
end
local function handlePunch(actionName: string, inputState: Enum.UserInputState, inputObject: InputObject)
if inputState ~= Enum.UserInputState.Begin then
return Enum.ContextActionResult.Pass
end
print(`Action [{actionName}] occurred. KeyCode [{inputObject.KeyCode}] pressed.`)
return Enum.ContextActionResult.Sink
end
-- 우선순위를 지정하지 않으면 가장 최근에 바인딩된 액션이 우선 호출됩니다,
-- 따라서 INPUT_KEY1을 누르면 "Punch"가 출력되고 입력이 차단됩니다.
ContextActionService:BindAction("DefaultThrow", handleThrow, false, INPUT_KEY1)
ContextActionService:BindAction("DefaultPunch", handlePunch, false, INPUT_KEY1)
-- 여기서는 위와 동일한 순서로 두 함수를 바인딩하지만,
-- 명시적으로 우선순위를 변경합니다.
-- 즉, "Throw"에 더 높은 우선순위인 2를 부여하여 먼저 호출되도록 합니다,
-- 비록 "Punch"가 더 최근에 바인딩되었더라도 말입니다.
-- INPUT_KEY2를 누르면 "Throw"가 출력되고 입력이 차단됩니다.
ContextActionService:BindActionAtPriority("PriorityThrow", handleThrow, false, 2, INPUT_KEY2)
ContextActionService:BindActionAtPriority("PriorityPunch", handlePunch, false, 1, INPUT_KEY2)BindActionToInputTypes
BindActivate
ContextActionService:BindActivate(
):()
매개 변수
반환
()
GetBoundActionInfo
매개 변수
SetDescription
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?가 있는 말풍선 이미지
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("검사 중")
end
end
-- 터치 장치의 경우, 3번째 매개변수를 통해 화면에 버튼이 자동으로 생성됩니다.
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- 버튼을 사용자 정의하기 위해 이러한 함수를 사용할 수 있습니다:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "보기")
ContextActionService:SetDescription(ACTION_INSPECT, "무언가를 검사하세요.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButton을 사용하여 버튼을 직접 조작할 수 있습니다.
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 기억하세요: 비터치 장치는 아무것도 반환하지 않습니다!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButton을 녹색으로 색칠합니다.
endSetImage
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?가 있는 말풍선 이미지
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("검사 중")
end
end
-- 터치 장치의 경우, 3번째 매개변수를 통해 화면에 버튼이 자동으로 생성됩니다.
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- 버튼을 사용자 정의하기 위해 이러한 함수를 사용할 수 있습니다:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "보기")
ContextActionService:SetDescription(ACTION_INSPECT, "무언가를 검사하세요.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButton을 사용하여 버튼을 직접 조작할 수 있습니다.
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 기억하세요: 비터치 장치는 아무것도 반환하지 않습니다!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButton을 녹색으로 색칠합니다.
endSetPosition
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?가 있는 말풍선 이미지
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("검사 중")
end
end
-- 터치 장치의 경우, 3번째 매개변수를 통해 화면에 버튼이 자동으로 생성됩니다.
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- 버튼을 사용자 정의하기 위해 이러한 함수를 사용할 수 있습니다:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "보기")
ContextActionService:SetDescription(ACTION_INSPECT, "무언가를 검사하세요.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButton을 사용하여 버튼을 직접 조작할 수 있습니다.
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 기억하세요: 비터치 장치는 아무것도 반환하지 않습니다!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButton을 녹색으로 색칠합니다.
endSetTitle
반환
()
코드 샘플
컨텍스트 액션 서비스 터치 버튼
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- ?가 있는 말풍선 이미지
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("검사 중")
end
end
-- 터치 장치의 경우, 3번째 매개변수를 통해 화면에 버튼이 자동으로 생성됩니다.
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- 버튼을 사용자 정의하기 위해 이러한 함수를 사용할 수 있습니다:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "보기")
ContextActionService:SetDescription(ACTION_INSPECT, "무언가를 검사하세요.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- ContextActionService:GetButton을 사용하여 버튼을 직접 조작할 수 있습니다.
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- 기억하세요: 비터치 장치는 아무것도 반환하지 않습니다!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- ImageButton을 녹색으로 색칠합니다.
endUnbindAction
매개 변수
반환
()
코드 샘플
ContextActionService 도구 재장전
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "재장전"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("재장전 중!")
end
end
tool.Equipped:Connect(function()
ContextActionService:BindAction(ACTION_RELOAD, handleAction, true, Enum.KeyCode.R)
end)
tool.Unequipped:Connect(function()
ContextActionService:UnbindAction(ACTION_RELOAD)
end)UnbindActivate
ContextActionService:UnbindActivate(
):()
매개 변수
| 기본값: "Unknown" |
반환
()
UnbindAllActions
ContextActionService:UnbindAllActions():()
반환
()
이벤트
LocalToolEquipped
매개 변수
LocalToolUnequipped
매개 변수