ContextActionService
*이 콘텐츠는 AI(베타)를 사용해 번역되었으며, 오류가 있을 수 있습니다. 이 페이지를 영어로 보려면 여기를 클릭하세요.
경험이 사용자 입력을 컨텍스트 작업이나 특정 조건이나 시간에만 활성화된 작업에 바인딩할 수 있도록 허용합니다.예를 들어, 플레이어가 가까이 있을 때만 문을 열도록 허용합니다.코드에서 액션은 서비스에서 고유 작업을 구분하기 위해 사용하는 단순한 문자열(작업 이름)입니다.동작 문자열은 다른 멤버 함수 중 BindAction 및 UnbindAction 에 제공됩니다.두 동작이 동일한 입력에 바인딩되어 있으면 가장 최근에 바인딩된 동작이 우선 적용됩니다.가장 최근의 작업이 해제될 때, 그 전에 바인딩된 작업이 다시 제어를 맡습니다.이 서비스는 사용자 입력을 처리하므로 클라이언트 측에서만 사용할 수 있습니다 LocalScripts.
컨텍스트 및 액션
A 컨텍스트 는 플레이어가 일부 액션수행할 수 있는 조건일 뿐입니다.일부 예시에는 차에서 Tool 를 들고 있거나, 문 근처에 서 있거나, 차 안에서 seated 하는 것이 포함됩니다.상황이 어떻든, 컨텍스트가 입력되면 를 호출하고 컨텍스트가 남으면 을 호출해야 합니다.
액션 은 해당 컨텍스트에서 플레이어가 수행할 수 있는 몇 가지 입력입니다.이러한 작업은 메뉴를 열거나 닫거나, 보조 도구 작업을 트리거하거나, RemoteFunction:InvokeServer()를 사용하여 서버에 요청을 보낼 수 있습니다.동작은 두 개의 BindAction 및 UnbindAction의 첫 번째 매개 변수로 고유한 문자열에 의해 식별됩니다.문자열은 무엇이든 될 수 있지만, 사용 중인 입력이 아닌 행동이 반영되어야 합니다 .예를 들어, "KeyH"를 작업 이름으로 사용하지 마십시오 - "CarHorn"을 대신 사용하십시오.코드에서 최소 세 곳 이상에서 사용할 것이기 때문에 스크립트 상단에 상수로 작업을 정의하는 것이 가장 좋습니다.
동작 컨텍스트에 따라 바인딩하기
대부분의 경우 ContextActionService의 BindAction 보다는 UserInputService.InputBegan 를 사용하는 것이 좋습니다.For UserInputService.InputBegan , 연결된 함수는 플레이어가 수행 중인 작업의 컨텍스트에 있는지 확인해야 합니다.대부분의 경우, 컨텍스트가 입력되거나 떠날 때 함수를 호출하는 것보다 더 어렵습니다.예를 들어, 플레이어가 안에 앉아 있는 동안 H 키가 자동차 경적 소리를 트리거하도록 하려면 플레이어가 채팅에서 "hello"를 입력하거나 다른 무언가를 위해 H 키를 사용할 수 있습니다.다른 것이 H 키를 사용하고 있는지 여부를 결정하기가 더 어렵습니다(예: 채팅) - 차는 플레이어가 의도하지 않았을 때 울릴 수 있습니다.플레이어가 차에 들어가거나 나갈 때 BindAction 및 UnbindAction 키를 사용하는 대신, ContextActionService 는 플레이어가 가장 최근에 바인딩된 액션트리거하도록 H 키 누르기가 수행되도록 합니다.다른 것(예: 채팅)이 제어를 가져가면 확인할 필요가 없습니다.
바인딩 작업 검사
작업 및 바인딩 입력 목록을 보려면 개발자 콘솔의 "액션 바인딩" 탭(게임 중 F9)을 검사할 수 있습니다.여기에는 Roblox 코어 스크립트와 기본 카메라/컨트롤 스크립트에 의해 바인딩된 모든 것도 포함됩니다.이는 작업이 올바른 시간에 바인딩/언바인딩되는지, 또는 다른 작업이 액션에서 입력을 훔치는지 디버깅하는 데 유용합니다.예를 들어, WASD 을 바인딩하려고 하면 기본 캐릭터 이동 스크립트가 동일한 키에 바인딩되는 경우가 있습니다.마찬가지로, 카메라 제어 스크립트는 스크립트가 당신 이후에 실행되면 오른쪽 클릭 입력을 훔칠 수 있습니다.
키보드 없는 입력
이 서비스는 게임패드 및 터치 입력을 지원하는 데 특히 유용합니다.게임패드 입력의 경우, B 버튼을 다른 메뉴에 들어갈 때 사용자를 이전 메뉴로 되돌리는 작업에 바인딩하도록 선택할 수 있습니다.터치를 위해, 키 입력 버튼은 키 입력 버튼 대신 사용할 수 있습니다: 이 버튼은 작업이 바인딩될 때만 표시되며, 이 버튼의 위치, 텍스트 및/또는 이미지는 이 서비스를 통해 구성할 수 있습니다.이 서비스에서 제공하는 사용자 지정의 양이 약간 제한되며, 일반적으로 ImageButton 또는 TextButton를 사용하여 화면에서 자체 버튼을 만드는 것이 더 좋습니다.
코드 샘플
This example properly shows how to use ContextActionService in binding user input to a contextual action. The context is the tool being equipped; the action is reloading some weapon. Test this code sample by placing it in a LocalScript parented to a Tool. When the Tool is equipped, a "Reload" action is bound, and when the Tool is unequipped the "Reload" action is unbound. When the player presses R with the Tool equipped, the message "Reloading!" will appear.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
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)
요약
메서드
- BindAction(actionName : string,functionToBind : function,createTouchButton : boolean,inputTypes : Tuple):()
사용자 입력을 작업 처리 함수에 바인딩하여 작업을 수행합니다.Bind user input to an action given an action handling function.
BindAction와 같은 동작을 하지만 겹치는 입력 유형에 우선 순위를 할당할 수도 있습니다(높음에서 낮음).
특정 Enum.KeyCode 와 함께 바인딩하여 이벤트 Enum.UserInputType 및 Tool.Activation 및 ClickDetector 을 트리거합니다.
모든 바인딩된 작업에 대한 정보 테이블을 가져오십시오(키는 BindAction 에 전달된 이름, 값은 키로 호출할 때 GetBoundActionInfo 의 테이블).
처음에 이름으로 전달된 바인딩된 작업에 대한 정보 테이블을 가져옵니다.Get a table of information about a bound action given its name originally passed to BindAction .
현재 에 의해 의 를 반환하십시오.
터치 버튼으로 바인딩된 액션의 이름을 지정하여 액션의 설명을 설정합니다.
actionName 키에 바인딩된 액션이 있으면 image 터치 버튼의 이미지로 설정됩니다.
터치 버튼으로 바인딩된 액션의 이름을 고려하여 컨텍스트 버튼프레임 내의 버튼 위치를 설정합니다.
터치 버튼으로 바인딩된 액션의 이름을 지정하여 버튼에 표시되는 텍스트를 설정합니다.
이름을 입력받은 액션을 해제합니다.
- UnbindActivate(userInputTypeForActivation : Enum.UserInputType,keyCodeForActivation : Enum.KeyCode):()
트리거와 바인딩될 때 와 특정 에서 트리거가 발동되지 않도록 해제하십시오.
바인딩된 모든 함수를 제거합니다. 작업 이름이 남지 않습니다. 모든 터치 버튼이 제거됩니다.
만든 터치 입력 버튼이 있는 ImageButton 행동의 bound 을 검색합니다.
이벤트
속성
메서드
BindAction
작업 처리 함수에 사용자 입력에 대한 작업을 바인딩하여 작업을 처리합니다.Bind an action to user input given an action handling function.일치하는 입력이 수행되면 아래에 나열된 인수로 액션 처리기 함수가 호출됩니다.유효한 입력 열거형 항목에는 팔로잉중 하나가 포함됩니다: Enum.KeyCode, Enum.UserInputType 또는 Enum.PlayerActions.플레이어가 컨텍스트에 액션을 수행할 수 있는 상황 에 들어갈 때 이 함수를 호출하십시오.플레이어가 컨텍스트를 떠날 때, 동일한 UnbindAction로 actionName를 호출하십시오.CallFunction를 사용하여 액션의 액션 처리 함수를 수동으로 호출할 수 있습니다.
아래 코드 샘플은 키(), 게임 패드 버튼 또는 터치 스크린 버튼이 누르힐 때 가 어떻게 될 수 있는지 보여줍니다.
local ContextActionService = game:GetService("ContextActionService")
-- 자동차 경적 소리
local honkSound = Instance.new("Sound", workspace)
honkSound.Looped = true
honkSound.SoundId = "rbxassetid://9120386436"
local function handleAction(actionName, inputState, inputObject)
if actionName == "HonkHorn" then
if inputState == Enum.UserInputState.Begin then
honkSound:Play()
else
honkSound:Pause()
end
end
end
-- 플레이어가 차량에 앉을 때:
ContextActionService:BindAction("HonkHorn", handleAction, true, Enum.KeyCode.H, Enum.KeyCode.ButtonY)
-- 플레이어가 나올 때:
ContextActionService:UnbindAction("HonkHorn")
액션 처리기 매개 변수
액션 처리기 함수는 다음 매개변수로 호출됩니다:
<th>유형</th><th>설명</th></tr><tr><td>1</td><td><code>문자열</code></td><td>원래 BindAction에 전달된 동일한 문자열†</td></tr><tr><td>2</td><td><code>Enum.UserInputState</code></td><td>입력 상태(시작, 변경, 종료 또는 취소)*</td></tr><tr><td>3</td><td><code>입력 개체</code></td><td>입력에 대한 정보가 포함된 개체(사용자 입력 유형에 따라 다름)</td></tr>
# |
† 필요한 경우 한 함수가 여러 작업을 한 번에 처리할 수 있도록 합니다.일부 입력이 진행 중이고 다른 작업이 진행 중 입력에 바인딩되었거나 진행 중 바인딩 작업이 unbound 였으면 취소가 전송됩니다.
액션 바인딩 스택
작업 바인딩은 스택처럼 작동합니다: 두 작업이 동일한 사용자 입력에 바인딩되면 가장 최근에 바인딩된 작업 처리기가 사용됩니다.액션 처리기가 Enum.ContextActionResult.Pass 를 반환하면 다음으로 가장 최근에 바인딩된 액션 처리기가 호출되고, 입력을 반환하기 위해 nil 또는 Enum.ContextActionResult.Sink 을 반환할 때까지 계속됩니다.UnbindAction 가 호출되면 액션 처리기가 스택에서 제거됩니다.이 스택 동작은 BindActionAtPriority 를 사용하여 재정의할 수 있으며, createTouchButton 이후의 추가 우선 순위 매개 변수가 작업의 바인딩 순서(높은 순서 전에 낮은 순서)를 재정의할 수 있습니다.
터치 버튼
입력 유형 외에도 이 함수의 세 번째 매개 변수는 버튼이 TouchEnabled 장치에 대해 생성되는지 여부를 제어합니다.처음 터치 버튼의 작품시, "ContextActionGui"라는 이름의 ScreenGui 가 PlayerGui 에 추가됩니다.ScreenGui 내에 "ContextButtonFrame"이라는 것이 추가되었습니다. Frame이 프레임에서는 바인딩된 작업에 대해 ImageButtons 가 부모로 지정되며, 사용자 지정을 위해 GetButton 를 사용하여 이러한 버튼을 검색할 수 있습니다.
매개 변수
수행되는 작업을 나타내는 문자열(예: "HonkHorn" 또는 "OpenDoor").
바인딩된 입력이 트리거될 때 다음 매개변수로 호출되는 작업 처리 함수: string(actionName), Enum.UserInputState 및 InputObject.
터치 입력 장치에 대한 작업에 대해 GUI 버튼을 만들어야 하는지 여부.
액션에 바인딩할 입력을 나타내는 Enum.KeyCode 또는 Enum.UserInputType의 모든 숫자.
반환
코드 샘플
This example properly shows how to use ContextActionService in binding user input to a contextual action. The context is the tool being equipped; the action is reloading some weapon. Test this code sample by placing it in a LocalScript parented to a Tool. When the Tool is equipped, a "Reload" action is bound, and when the Tool is unequipped the "Reload" action is unbound. When the player presses R with the Tool equipped, the message "Reloading!" will appear.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
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)
This code sample uses ContextActionService to bind an action named "BoundAction" to a general action handler function on the F key. Place this in a LocalScript inside StarterPlayerScripts and press F to see the message "Handling action: BoundAction".
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
-- Since this function does not return anything, this handler will
-- "sink" the input and no other action handlers will be called after
-- this one.
end
ContextActionService:BindAction("BoundAction", handleAction, false, Enum.KeyCode.F)
This code sample demonstrates how BindAction acts like a stack. It binds two actions, FirstAction (Z, X, and C keys) and SecondAction (Z and X keys) to two action handling functions. The second one will pass on a certain input (the X key).
Both actions use the Z and X keys, however the second handler will pass input only if X is pressed. So, when X is pressed, the second handler is called and then the first. The first action is also bound to the C key, and can be triggered even though the other two inputs are "covered" by the second action.
Test this code out by pasting it into a LocalScript within StarterPlayerScripts, then pressing Z, X and C. Observe which action handlers are called with what actions.
local ContextActionService = game:GetService("ContextActionService")
-- Define an action handler for FirstAction
local function actionHandlerOne(actionName, inputState, _inputObj)
if inputState == Enum.UserInputState.Begin then
print("Action Handler One: " .. actionName)
end
-- This action handler returns nil, so it is assumed that
-- it properly handles the action.
end
-- Binding the action FirstAction (it's on the bottom of the stack)
ContextActionService:BindAction("FirstAction", actionHandlerOne, false, Enum.KeyCode.Z, Enum.KeyCode.X, Enum.KeyCode.C)
-- Define an action handler for SecondAction
local function actionHandlerTwo(actionName, inputState, inputObj)
if inputState == Enum.UserInputState.Begin then
print("Action Handler Two: " .. actionName)
end
if inputObj.KeyCode == Enum.KeyCode.X then
return Enum.ContextActionResult.Pass
else
-- Returning nil implicitly Sinks inputs
return Enum.ContextActionResult.Sink
end
end
-- Binding SecondAction over the first action (since it bound more recently, it is on the top of the stack)
-- Note that SecondAction uses the same keys as
ContextActionService:BindAction("SecondAction", actionHandlerTwo, false, Enum.KeyCode.Z, Enum.KeyCode.X)
BindActionAtPriority
BindActionAtPriority는 BindAction와 같이 동작하지만 바인딩된 액션에 우선 순위를 할당할 수도 있습니다.여러 작업이 동일한 입력에 바인딩되면 작업이 바인딩된 순서와 상관없이 우선 순위가 높은 함수가 호출됩니다.즉, 이 함수는 BindAction의 일반적인 "스택" 동작을 재정의합니다.
매개 변수
수행되는 작업을 나타내는 문자열(예: "HonkHorn" 또는 "OpenDoor").
바인딩된 입력이 트리거될 때 다음 매개변수로 호출되는 작업 처리 함수: string(actionName), Enum.UserInputState 및 InputObject.
터치 입력 장치에 대한 작업에 대해 GUI 버튼을 만들어야 하는지 여부.
액션을 바인딩해야 하는 우선 순위 레벨(낮은 순으로 고려됨).
액션에 바인딩할 입력을 나타내는 Enum.KeyCode 또는 Enum.UserInputType의 모든 수입니다.
반환
코드 샘플
This code sample demonstrates how ContextActionService:BindActionAtPriority() can be used to bind actions out of order yet still have the same priority levels. Normally, BindAction() would operate on order (last bound action has highest priority), but priority levels override this. You can test this code by pasting it into a Script with RunContext = Client in ReplicatedStorage.
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
-- Without specifying priority, the most recently bound action is called first,
-- so pressing INPUT_KEY1 prints "Punch" and then sinks the input.
ContextActionService:BindAction("DefaultThrow", handleThrow, false, INPUT_KEY1)
ContextActionService:BindAction("DefaultPunch", handlePunch, false, INPUT_KEY1)
-- Here we bind both functions in the same order as above, but with explicitly swapped priorities.
-- That is, we give "Throw" a higher priority of 2 so it will be called first,
-- despite "Punch" still being bound more recently.
-- Pressing INPUT_KEY2 prints "Throw" and then sinks the input.
ContextActionService:BindActionAtPriority("PriorityThrow", handleThrow, false, 2, INPUT_KEY2)
ContextActionService:BindActionAtPriority("PriorityPunch", handlePunch, false, 1, INPUT_KEY2)
BindActivate
에서 까지 사용할 수 있는 바인딩 을, 에서 까지 이벤트를 활성화하고, 에서 까지 사용할 수 있습니다.지정된 키/버튼이 누르면, 마우스에 전송된 Mouse.Button1Down 이벤트에 대해 Tool.Equipped 이벤트가 발생합니다.이로 인해 Tool.Activated 이벤트가 발생하고 Tool.ManualActivationOnly 가 참으로 설정되지 않으면 이벤트가 발생합니다.게임패드 입력의 경우, 이 함수는 ButtonR2 Enum.KeyCode 을 바인딩하기 위해 기본 제어 스크립트에 의해 호출됩니다.
지정된 Enum.UserInputType 는 유효하려면 Keyboard 또는 Gamepad1 을 통해 Gamepad8 에서 유효해야 합니다.
매개 변수
게임패드8을 통해 키보드 또는 게임패드1여야 합니다.
반환
GetAllBoundActionInfo
GetAllBoundActioninfo는 모든 작업의 이름(원래 전달된 것은 BindAction )을 액션 이름과 동일한 테이블로 매핑하는 테이블을 반환하며, 액션 이름 자체로 호출되면 GetBoundActionInfo에서 반환된 테이블입니다.이 함수를 사용하여 현재 바인딩된 모든 작업을 검사할 수 있습니다.우선 순위 수준이나 스택 순서를 디버깅할 때 유용합니다.
반환
GetBoundActionInfo
GetBoundActionInfo는 이름에 바인딩된 작업을 지정하는 다음 키가 있는 테이블을 반환합니다.모든 작업에 대해 한 번에 동일한 정보를 가져오려면 GetAllBoundActionInfo를 사용하십시오.
<th>유형</th><th>설명</th></tr><tr><td><code>스택 순서</code></td><td>번호</td><td>스택에서 액션의 인덱스(증가)를 설명합니다</td></tr><tr><td><code>우선 순위 수준</code> \*</td><td>번호</td><td>동작의 <code>Class.ContextActionService:BindActionAtPriority()|priority</code> 수준을 설명합니다</td></tr><tr><td><code>터치 버튼 생성</code></td><td>bool</td><td>터치 버튼을 <code>Class.UserInputService.TouchEnabled|TouchEnabled</code> 장치에 생성해야 하는지 여부를 설명합니다</td></tr><tr><td><code>입력 유형</code></td><td>테이블</td><td>이 작업이 트리거될 <code>Class.ContextActionService:BindAction()|BindAction</code>에 전달된 입력 유형</td></tr><tr><td><code>설명</code> †</td><td>문자열</td><td>클래스.ContextActionService에 의해 설정된 작업의 설명 <code>Class.ContextActionService:SetDescription()|SetDescription</code></td></tr><tr><td><code>타이틀</code> †</td><td>문자열</td><td>클래스.ContextActionService에 의해 설정된 작업의 제목 <code>Class.ContextActionService:SetTitle()|SetTitle</code></td></tr><tr><td><code>이미지</code> †</td><td>문자열</td><td>클래스.ContextActionService에 의해 설정된 액션터치 버튼 이미지 <code>Class.ContextActionService:SetImage()|SetImage</code></td></tr>
이름 |
우선 순위 레벨은 사용되지 않았더라도 BindActionAtPriority 포함될 것입니다. 기본값은 2000입니다.
† 연결된 메서드가 지정된 액션대해 호출되지 않은 경우 이 필드가 nil가 될 것임을 나타냅니다.
매개 변수
반환
GetCurrentLocalToolIcon
GetCurrentLocalToolIcon는 현재 에서 현재 에 의해 반환되거나 에 해당 도구가 없거나 플레이어가 부족한 경우 입니다.
반환
도구의 텍스처ID에서 콘텐츠 문자열, 또는 nil 없을 경우.
SetDescription
SetDescription는 BindAction에 바인딩된 액션의 설명을 설정합니다.사용 가능한 작업 목록에서 이것은 지정된 작업을 설명하는 텍스트가 될 것입니다.
이름이 이 메서드가 생성하는 작업에 대한 터치 버튼을 사용자 정의하는 함수 가족과 관련이 있다고 제안하더라도 이 메서드는 그러한 버튼에 영향을 주지 않습니다(SetTitle, SetImage 및 SetPosition).이 메서드는 단순히 액션의 텍스트 설명을 설정하고 그 이상은 없습니다.
매개 변수
BindAction에 처음 전달된 작업의 이름.
액션텍스트 설명, 예를 들어 "자동차의 경적을 울리거나" 또는 "인벤토리 열기".
반환
코드 샘플
This code sample demonstrates binding an "Inspect" action to a touch button created automatically by ContextActionService. The button is customized using SetImage(), SetTitle(), SetDescription() and SetPosition(). The button is further customized by using GetButton() to get a reference to the ImageButton itself and tinting it green by setting ImageButton.ImageColor3.
Paste this code into a LocalScript placed within StarterPlayerScripts to test it. In Studio, be sure to toggle the touch device emulator in order for the button to actually be created.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspecting")
end
end
-- For touch devices, a button is created on-screen automatically via the 3rd parameter
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- We can use these functions to customize the button:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Look")
ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- We can manipulate the button directly using ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Remember: non-touch devices won't return anything!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
end
SetImage
이 메서드는 BindAction()에서 생성된 터치 버튼에 표시된 이미지를 설정합니다.특히, 그것은 ImageLabel.Image 속성을 설정하여 반환될 ImageLabel 내의 ImageButton 내에서 GetButton에 의해 반환될 것입니다.이러한 바인딩 작업이 없는 경우(예:GetButton에서 아무것도 반환되지 않으므로 이 함수는 아무것도 하지 않고 오류를 던지지 않습니다.
이 함수는 액션터치 버튼을 사용자 지정하는 메서드 가족의 일부입니다. 이 가족에는 SetPosition 및 SetTitle 가 포함됩니다.
매개 변수
반환
코드 샘플
This code sample demonstrates binding an "Inspect" action to a touch button created automatically by ContextActionService. The button is customized using SetImage(), SetTitle(), SetDescription() and SetPosition(). The button is further customized by using GetButton() to get a reference to the ImageButton itself and tinting it green by setting ImageButton.ImageColor3.
Paste this code into a LocalScript placed within StarterPlayerScripts to test it. In Studio, be sure to toggle the touch device emulator in order for the button to actually be created.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspecting")
end
end
-- For touch devices, a button is created on-screen automatically via the 3rd parameter
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- We can use these functions to customize the button:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Look")
ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- We can manipulate the button directly using ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Remember: non-touch devices won't return anything!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
end
SetPosition
이 메서드는 BindAction()에서 생성된 터치 버튼의 위치를 설정합니다.특히, 반환될 GuiObject.Position 속성의 ImageButton 속성을 설정합니다. that would be returned by GetButton .이러한 바인딩 작업이 없는 경우(예:GetButton에서 아무것도 반환되지 않으므로 이 함수는 아무것도 하지 않고 오류를 던지지 않습니다.
이 함수는 액션터치 버튼을 사용자 지정하는 메서드 가족의 일부입니다. 이 가족에는 SetImage 및 SetTitle 가 포함됩니다.
매개 변수
반환
코드 샘플
This code sample demonstrates binding an "Inspect" action to a touch button created automatically by ContextActionService. The button is customized using SetImage(), SetTitle(), SetDescription() and SetPosition(). The button is further customized by using GetButton() to get a reference to the ImageButton itself and tinting it green by setting ImageButton.ImageColor3.
Paste this code into a LocalScript placed within StarterPlayerScripts to test it. In Studio, be sure to toggle the touch device emulator in order for the button to actually be created.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspecting")
end
end
-- For touch devices, a button is created on-screen automatically via the 3rd parameter
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- We can use these functions to customize the button:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Look")
ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- We can manipulate the button directly using ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Remember: non-touch devices won't return anything!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
end
SetTitle
SetTitle은 BindAction에서 생성된 터치 버튼에 표시된 텍스트를 설정합니다.특히, 이것은 TextLabel.Text 속성을 설정하여 반환될 TextLabel 내의 ImageButton 내에서 GetButton에 의해 반환될 수 있습니다.이러한 바인딩 작업이 없는 경우(예:GetButton에서 아무것도 반환되지 않으므로 이 함수는 아무것도 하지 않고 오류를 던지지 않습니다.
이 함수는 액션터치 버튼을 사용자 지정하는 메서드 가족의 일부입니다. 이 가족에는 SetImage 및 SetPosition 가 포함됩니다.
매개 변수
반환
코드 샘플
This code sample demonstrates binding an "Inspect" action to a touch button created automatically by ContextActionService. The button is customized using SetImage(), SetTitle(), SetDescription() and SetPosition(). The button is further customized by using GetButton() to get a reference to the ImageButton itself and tinting it green by setting ImageButton.ImageColor3.
Paste this code into a LocalScript placed within StarterPlayerScripts to test it. In Studio, be sure to toggle the touch device emulator in order for the button to actually be created.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_INSPECT = "Inspect"
local INPUT_INSPECT = Enum.KeyCode.E
local IMAGE_INSPECT = "rbxassetid://1826746856" -- Image of a speech bubble with ? in it
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_INSPECT and inputState == Enum.UserInputState.End then
print("Inspecting")
end
end
-- For touch devices, a button is created on-screen automatically via the 3rd parameter
ContextActionService:BindAction(ACTION_INSPECT, handleAction, true, INPUT_INSPECT)
-- We can use these functions to customize the button:
ContextActionService:SetImage(ACTION_INSPECT, IMAGE_INSPECT)
ContextActionService:SetTitle(ACTION_INSPECT, "Look")
ContextActionService:SetDescription(ACTION_INSPECT, "Inspect something.")
ContextActionService:SetPosition(ACTION_INSPECT, UDim2.new(0, 0, 0, 0))
-- We can manipulate the button directly using ContextActionService:GetButton
local imgButton = ContextActionService:GetButton(ACTION_INSPECT)
if imgButton then -- Remember: non-touch devices won't return anything!
imgButton.ImageColor3 = Color3.new(0.5, 1, 0.5) -- Tint the ImageButton green
end
UnbindAction
UnbindAction는 사용자 입력의 이름으로 액션을 해제하여 액션 처리기 함수가 더 이상 호출되지 않도록 합니다.이 함수를 호출하면 사용자 인터페이스 닫기, 자동차 종료 또는 등의 작업 컨텍스트가 더 이상 해당않을 때 발생합니다.바인딩된 작업이 어떻게 작동하는지에 대한 자세한 정보는 BindAction에 참조하십시오.
이 함수 는 지정된 문자열에 해당 작업이 바인딩되지 않으면 오류를 발생시키지 않습니다. GetAllBoundActionInfo 또는 개발자 콘솔의 "액션 바인딩" 탭을 사용하여 현재 바인딩된 액션을 찾을 수 있습니다.
매개 변수
반환
코드 샘플
This example properly shows how to use ContextActionService in binding user input to a contextual action. The context is the tool being equipped; the action is reloading some weapon. Test this code sample by placing it in a LocalScript parented to a Tool. When the Tool is equipped, a "Reload" action is bound, and when the Tool is unequipped the "Reload" action is unbound. When the player presses R with the Tool equipped, the message "Reloading!" will appear.
local ContextActionService = game:GetService("ContextActionService")
local ACTION_RELOAD = "Reload"
local tool = script.Parent
local function handleAction(actionName, inputState, _inputObject)
if actionName == ACTION_RELOAD and inputState == Enum.UserInputState.Begin then
print("Reloading!")
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
UnbindActivate는 Enum.KeyCode를 사용하여 활성화하는 Enum.UserInputType 또는 Tool (또는 HopperBin )를 활성화하기 위해 BindActivate를 사용합니다.이 함수는 본질적으로 해당 함수에 의해 수행된 작업을 취소합니다.
매개 변수
BindActivate에 처음 전송된 동일한 UserInputType.
BindActivate에 원래 전송된 동일한 KeyCode.
반환
UnbindAllActions
바인딩된 모든 함수를 제거합니다.행동 이름이 남지 않습니다. No actionNames will remain.모든 터치 버튼이 제거됩니다.버튼이 수동으로 조작되면 정리될 것이라는 보장이 없습니다.