ContextActionService
ContextActionService : Instance
Overview
ํน์ ์กฐ๊ฑด์์๋ง ํ์ฑํ๋๋ ๋์์ ์ฌ์ฉ์ ์ ๋ ฅ๊ณผ ์ฐ๊ฒฐํด์ฃผ๋ ์์คํ ์ผ๋ก, ํ๋ ์ด์ด๊ฐ ํน์ ๋๊ตฌ๋ฅผ ์ฅ์ฐฉํ์ ๋๋, ์ด๋ค ์์น์ ์์ ๋๋ง ๋ฒํผ ์ ๋ ฅ์ด ์๋ํ๋๋ก ์ค์ ํ ์ ์์ต๋๋ค.
๊ฐ ์ ๋ ฅ ๋์์ ๋ฌธ์์ด๋ก ์ ์๋๋ฉฐ, ์ด๋ฅผ ํตํด ์ด๋ค ์ ๋ ฅ ๊ธฐ๋ฅ์ธ์ง ๊ตฌ๋ถํ ์ ์์ต๋๋ค. ๋์ผํ ์ด๋ฆ์ ์ฌ๋ฌ ๋์์ด ์ฐ๊ฒฐ๋ ๊ฒฝ์ฐ, ๊ฐ์ฅ ์ต๊ทผ์ ๋ฐ์ธ๋ฉ๋ ๋์์ด ์ฐ์ ์ ์ฉ๋๋ฉฐ, ํด์ ๋๋ฉด ์ด์ ์ ์ฐ๊ฒฐ๋ ๋์์ด ๋ค์ ํ์ฑํ๋ฉ๋๋ค.
์ด ์์คํ ์ ํด๋ผ์ด์ธํธ ํ๊ฒฝ์์๋ง ์ฌ์ฉ๋๋ฉฐ, ์ปจํ ์คํธ ๊ธฐ๋ฐ์ผ๋ก ์ ๋ ฅ์ ๊ด๋ฆฌํ ์ ์์ด, ๋ณต์กํ ์ํ ํ์ธ ์์ด๋ ์ํฉ์ ๋ฐ๋ผ ์ ์ ํ ๋์์ ์ ์ฉํ ์ ์์ต๋๋ค.
๋ํ, ํค๋ณด๋๋ ํฐ์น ์ ๋ ฅ์ด ํจ๊ป ์ฐ๋๋์ด ๋ค์ํ ํ๋ซํผ์์ ์ผ๊ด๋ ์ฌ์ฉ์ ๊ฒฝํ์ ์ ๊ณตํ ์ ์์ต๋๋ค.
Properties
Methods
BindAction
ํน์ ๋ฌธ์์ด์ ์ ๋ ฅ ๋์์ ์ ์ํ๊ณ , ํด๋น ์ ๋ ฅ์ด ๋ฐ์ํ์ ๋ ์ฐ๊ฒฐ๋ ํจ์๊ฐ ํธ์ถ๋๋๋ก ์ค์ ํ ์ ์์ต๋๋ค.
์ง์ ํ ํค๋ณด๋ ํค๋ ํฐ์น ๋ฒํผ์ด ๋๋ฆด ๊ฒฝ์ฐ, ์ ๋ ฅ ์ ๋ณด์ ์ ๋ ฅ ์ํ๊ฐ ์ฐ๊ฒฐ๋ ํจ์์ ์ธ์๋ก ์ ๋ฌ๋ฉ๋๋ค.
Parameters
string
ActionName
๋์์ ์๋ณํ๊ธฐ ์ํ ์ด๋ฆ์ ๋๋ค.
Value
FunctionToBind
์ ๋ ฅ์ด ๊ฐ์ง๋์์ ๋ ์คํ๋๋ ํจ์๋ก, ์ฐ๊ฒฐ๋ ํจ์์๋ ๋ค์๊ณผ ๊ฐ์ ์ธ์๋ค์ด ์ ๋ฌ๋ฉ๋๋ค:
string
ActionName: BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆEnum.UserInputState
: ์ ๋ ฅ ์ํInputObject
InputObject: ์ ๋ ฅ๊ณผ ๊ด๋ จ๋ ์ธ๋ถ ์ ๋ณด๋ฅผ ํฌํจํ๋ ๊ฐ์ฒด์ ๋๋ค.
bool
bCreateTouchButton
๋์์ ์คํํ ๋ฒํผ์ ํ๋ฉด์ ํ์ํ ์ง ์ฌ๋ถ์ ๋๋ค.
Tuple
InputType
Enum.KeyCode๋ฅผ ์ฌ์ฉํ์ฌ ๋์์ ์คํํ ํค๋ฅผ ์ง์ ํ ์ ์์ผ๋ฉฐ, ์ฌ๋ฌ ๊ฐ์ ํค๋ฅผ ์ค์ ํ๋ ๊ฒ๋ ๊ฐ๋ฅํฉ๋๋ค.
Return
void
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
local IsCreateTouchButton = true
local KeyCode = Enum.KeyCode.F
local function OnAction(actionName, inputState, inputObject)
if inputState == Enum.UserInputState.Begin then
print(actionName .. " triggered!")
end
end
ContextActionService:BindAction(ActionName, OnAction, IsCreateTouchButton, KeyCode)
UnbindAction
ํน์ ๋ฌธ์์ด์ ์ ์๋ ์ ๋ ฅ ๋์์ ํด์ ํฉ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
Return
void
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
ContextActionService:UnbindAction(ActionName)
GetAllBoundActionInfo
๋ฐ์ธ๋ฉ๋ ๋ชจ๋ ์ก์ ์ ๋ณด๋ฅผ ํ ์ด๋ธ ํํ๋ก ๋ฐํํฉ๋๋ค.
๋ฐํ๋ ํ ์ด๋ธ์ ๊ฐ ์ก์ ์ ์ด๋ฆ์ ํค๋ก ํ๋ฉฐ, ํด๋น ์ด๋ฆ์ GetBoundActionInfo()์ ์ ๋ฌํ์ ๋ ์ป์ ์ ์๋ ์์ธ ์ ๋ณด๊ฐ ๊ฐ์ผ๋ก ํฌํจ๋ฉ๋๋ค.
์ฌ๋ฌ ์ก์ ์ด ๋์์ ๋ฐ์ธ๋ฉ๋์ด ์์ ๋ ์ฐ์ ์์๊ฐ ์ฌ๋ฐ๋ฅด๊ฒ ์ ์ฉ๋๊ณ ์๋์ง, ๋๋ ์ด๋ค ์ก์ ์ด ๋ฎ์ด์ฐ๊ธฐ ๋์๋์ง๋ฅผ ํ์ธํ ๋ ์ ์ฉํ๊ฒ ์ฌ์ฉํ ์ ์์ต๋๋ค.
Parameters
Return
Dictionary
๋ฐ์ธ๋ฉ๋ ๋ชจ๋ ์ก์ ์ ๋ณด๊ฐ ๊ตฌ์ฑ๋ ๋์ ๋๋ฆฌ์ ๋๋ค.
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local AllActions = ContextActionService:GetAllBoundActionInfo()
for actionName, actionInfo in pairs(AllActions) do
print("Action Name : ", actionName)
print("Input Types : ", actionInfo.InputTypes)
end
GetBoundActionInfo
ํน์ ์ก์ ์ด๋ฆ์ ๊ธฐ์ค์ผ๋ก, ๊ทธ ์ก์ ์ ๋ฐ์ธ๋ฉ๋ ์ ๋ ฅ ์ ๋ณด์ ์์ฑ๋ค์ ๋ฐํํฉ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
Return
Dictionary
์ก์ ์ ๋ณด๊ฐ ๊ตฌ์ฑ๋ ๋์ ๋๋ฆฌ์ ๋๋ค.
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
local ActionInfo = ContextActionService:GetBoundActionInfo(ActionName)
if ActionInfo then
print("Action Name : ", ActionName)
print("Input Types : ", ActionInfo.InputTypes)
else
print("Action not found.")
end
SetDescription
BindAction()์ ํตํด ์ ์๋ ์ก์ ์ ์ค๋ช ํ ์คํธ๋ฅผ ์ค์ ํ๋ ๊ธฐ๋ฅ์ ๋๋ค.
์ค์ ํ ํ ์คํธ๋ UI์ง์ ํ์๋์ง๋ ์์ผ๋ฉฐ, ์ก์ ์ ๋ํ ์ ๋ณด๋ฅผ ์ค๋ช ํ๊ฑฐ๋ ๊ตฌ๋ถํ๊ธฐ ์ํ ์ฉ๋๋ก๋ง ์ฌ์ฉ๋ฉ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
string
InDescription
์ค์ ํ ์ค๋ช ์ ๋๋ค.
Return
void
Code Samples
local ContextActionService = game:GetService("ContextActionService")
ContextActionService:SetDescription(ActionName, "Press the button to jump.")
for actionName, actionInfo in pairs(AllActions) do
print("Action Name : ", actionName)
print("Description : ", actionInfo.Description)
end
SetImage
BindAction()์ ํตํด ์์ฑ๋ ํฐ์น ๋ฒํผ์ ์ด๋ฏธ์ง๋ฅผ ์ค์ ํ๋ ๊ธฐ๋ฅ์ ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
string
ImageId
ํฐ์น ๋ฒํผ์ ํ์ํ ์ด๋ฏธ์ง์ AssetId์ ๋๋ค.
Return
void
Code Samples
ContextActionService:SetImage(ActionName, "ovdrassetid://1234")
SetPosition
BindAction()์ ํตํด ์์ฑ๋ ํฐ์น ๋ฒํผ์ ํ๋ฉด ๋ด ์์น๋ฅผ ์ค์ ํ๋ ๊ธฐ๋ฅ์ ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
UDim2
InPosition
์ค์ ํ ์์น์ ๋๋ค.
Return
void
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
ContextActionService:SetPosition(ActionName, UDim2.new(0.5, 0, 0.8, 0))
SetTitle
BindAction()์ ํตํด ์์ฑ๋ ํฐ์น ๋ฒํผ์ ํ์๋๋ ๊ธ์๋ฅผ ์ค์ ํ๋ ๊ธฐ๋ฅ์ ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
string
InTitle
์ค์ ํ ๋ด์ฉ์ ๋๋ค.
Return
void
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
ContextActionService:SetTitle(ActionName, "Action")
GetButton
BindAction()์ ํตํด ์์ฑ๋ ํฐ์น ๋ฒํผ์ ImageButton ๊ฐ์ฒด๋ก ๋ฐํํฉ๋๋ค.
ํฐ์น ๋ฒํผ์ ์ฌ์ฉํ์ง ์๋ ์ก์ ์ธ ๊ฒฝ์ฐ, nil์ ๋ฐํํฉ๋๋ค.
Parameters
string
ActionName
BindAction()์ ์ํด ์ ์๋ ๋์์ ์ด๋ฆ
Return
Instance
์์ฑ๋ ํฐ์น ๋ฒํผ์ ๋๋ค.
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"
local ActionButton = ContextActionService:GetButton(ActionName)
print(ActionButton)
Events
LocalToolEquipped
ํ๋ ์ด์ด๊ฐ ๋๊ตฌ๋ฅผ ์ฅ์ฐฉํ ๋ ์คํ๋๋ ์ด๋ฒคํธ์ ๋๋ค.
Parameters
Tool
Tool
์ฅ์ฐฉํ ๋๊ตฌ์ ๋๋ค.
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local function OnToolEquipped(tool)
print("OnToolEquipped")
end
ContextActionService.LocalToolEquipped:Connect(OnToolEquipped)
LocalToolUnequipped
ํ๋ ์ด์ด๊ฐ ์ฅ์ฐฉํ ๋๊ตฌ๋ฅผ ํด์ ํ ๋ ์คํ๋๋ ์ด๋ฒคํธ์ ๋๋ค.
Parameters
Tool
Tool
์ฅ์ฐฉ ํด์ ํ ๋๊ตฌ์ ๋๋ค.
Code Samples
local ContextActionService = game:GetService("ContextActionService")
local function OnToolUnequipped(tool)
print("OnToolUnequipped")
end
ContextActionService.LocalToolUnequipped:Connect(OnToolUnequipped)
See also
๋ชจ๋ฐ์ผ ์กฐ์ ์ฒ๋ฆฌLast updated