Creator Guide
Korean
Korean
  • OVERDARE
    • 🚩OVERDARE 소개
    • 🐤시작하기
      • OVERDARE App
      • OVERDARE Studio
    • 📌운영 정책
      • 커뮤니티 가이드라인
      • UGC 콘텐츠 제작 가이드라인
      • UGC의 외부 활용 가이드라인
      • LOGO 활용 가이드라인
      • 지식 재산권 정책
      • 신고 안내
      • 콘텐츠 제재 이의 신청 안내
      • 크리에이터 정산 정책
      • OVERDARE 수익화 가이드라인
    • 🅰️OVERDARE Glossary
  • MANUAL
    • 🏰스튜디오 메뉴얼
      • 시작하기
        • 스튜디오 인터페이스
        • 월드 템플릿
        • 좌표계
        • 스튜디오 테스트 플레이
        • 월드 퍼블리시
        • Collaboration
      • 에셋 & 리소스 제작
        • 에셋 임포트
        • 애니메이션 에디터
      • 게임 제작
        • 게임 설정
        • 스크립트 에디터
        • 정렬
        • Material Manager
        • Collision Groups
        • Tag Editor
        • 퍼포먼스 가이드
      • Object
        • 파트
        • 모델
        • 카메라
        • 물리
        • 조명
        • Tool
        • VFX
        • Sound
      • 캐릭터
        • 캐릭터 애니메이션
        • Humanoid Description
      • GUI
    • 📝스크립트 메뉴얼
      • 시작하기
        • 스크립트 개요
        • 루아 기초 가이드
        • 코딩 스타일
        • 오브젝트 참조
        • 유니티 개발자용 가이드
      • 이벤트 및 통신
        • 이벤트
        • 서버-클라 통신
        • BindableEvent
        • Value Objects
      • 입력 및 조작
        • 모바일 조작 처리
        • TPS Strafing System
      • 게임 고도화
        • Saving & Loading Data
        • 트윈
        • 모듈 스크립트
      • 디버깅 & 최적화
        • 중단점
        • 스크립트 최적화 실전 가이드
  • 💸수익화
    • Payout Guideline
  • DEVELOPMENT
    • 📚API Reference
      • Enums
        • ActuatorRelativeTo
        • AnimationPriority
        • AspectType
        • AssetTypeVerification
        • BorderMode
        • CameraMode
        • CameraType
        • ContextActionResult
        • CoreGuiType
        • DominantAxis
        • EasingDirection
        • EasingStyle
        • ForceLimitMode
        • HttpCompression
        • HttpContentType
        • HumanoidDisplayDistanceType
        • HumanoidStateType
        • KeyCode
        • Material
        • MaterialPattern
        • NormalId
        • ParticleEmitterShape
        • ParticleEmitterShapeInOut
        • ParticleEmitterShapeStyle
        • ParticleFlipbookLayout
        • ParticleFlipbookMode
        • ParticleOrientation
        • PartType
        • PlaybackState
        • RaycastFilterType
        • RollOffMode
        • RotationType
        • UserInputState
        • UserInputType
        • VelocityConstraintMode
      • DataTypes
        • BlendSpaceSampleSata
        • BrickColor
        • CFrame
        • Color3
        • ColorSequence
        • ColorSequenceKeypoint
        • Content
        • Enum
        • EnumItem
        • NumberRange
        • NumberSequence
        • NumberSequenceKeypoint
        • OverlapParams
        • PhysicalProperties
        • Ray
        • RaycastParams
        • RaycastResult
        • ScriptConnection
        • ScriptSignal
        • TweenInfo
        • Udim
        • Udim2
        • Vector2
        • Vector3
      • Classes
        • Animation
        • AngularVelocity
        • AnimationTrack
        • Animator
        • Atmosphere
        • Attachment
        • Backpack
        • BackpackItem
        • BasePart
        • BaseScript
        • Beam
        • BindableEvent
        • BlendSpace
        • BoolValue
        • Bone
        • Camera
        • CharacterMesh
        • CollectionService
        • Constraint
        • ContextActionService
        • CoreGui
        • DataStore
        • DataModel
        • DataStoreGetOptions
        • DataStoreIncrementOptions
        • DataStoreInfo
        • DataStoreKeyPages
        • DataStoreKeyInfo
        • DataStoreService
        • DataStoreListingPages
        • DataStoreSetOptions
        • FormFactorPart
        • Frame
        • Folder
        • GlobalDataStore
        • GuiBase2d
        • GuiButton
        • GuiObject
        • HttpService
        • Humanoid
        • HumanoidDescription
        • ImageButton
        • ImageLabel
        • InputObject
        • IntValue
        • LayerCollector
        • Instance
        • Light
        • Lighting
        • LinearVelocity
        • LocalScript
        • LuaSourceContainer
        • MaterialService
        • MaterialVariant
        • MeshPart
        • Model
        • ModuleScript
        • Mouse
        • OrderedDataStore
        • Pages
        • Part
        • ParticleEmitter
        • PhysicsService
        • Player
        • PlayerGui
        • Players
        • PlayerScripts
        • PointLight
        • PVInstance
        • ReplicatedStorage
        • RemoteEvent
        • ScreenGui
        • RunService
        • Script
        • ServerStorage
        • ServiceProvider
        • Skeleton
        • ServerScriptService
        • Sound
        • SoundService
        • SoundGroup
        • SpotLight
        • SpawnLocation
        • StarterCharacterScripts
        • StarterPack
        • StarterGui
        • StarterPlayer
        • StarterPlayerScripts
        • StringValue
        • SurfaceGui
        • SurfaceGuiBase
        • Team
        • Teams
        • TextLabel
        • TextButton
        • Tool
        • Trail
        • Tween
        • TweenService
        • TweenBase
        • UIAspectRatioConstraint
        • UserGameSettings
        • UserInputService
        • UserSettings
        • VectorForce
        • Workspace
        • WrapLayer
        • WorldRoot
        • WrapTarget
  • UPDATE
    • 📰Release Note
Powered by GitBook
On this page
  • 개요
  • 특징
  • 사용 방법
  • 1. 액션 생성하기
  • 2. 액션 해제하기
  • 3. 입력 상태별 처리
  • 4. 특정 액션 가져오기
  • 5. 생성된 액션 모두 가져오기
  • 기본 입력 처리
  • 모바일 조이스틱, 점프 버튼 표시 제어
  • 모바일 화면 터치 감지
  • 모바일 조이스틱 입력 감지
  1. MANUAL
  2. 스크립트 메뉴얼
  3. 입력 및 조작

모바일 조작 처리

개요

ContextActionService는 게임플레이 중 키보드, 마우스, 터치 등 다양한 입력 방식을 효과적으로 처리하고, 상황에 맞는 인터페이스를 손쉽게 구현할 수 있도록 도와줍니다. 이를 통해 플레이어 입력을 간편하게 관리하고, 게임 내 Context에 따라 유연하게 동작을 할당하거나 해제할 수 있습니다.

특징

  • 키보드, 마우스, 터치 등 여러 입력 장치를 동일한 방식으로 처리할 수 있습니다.

  • PC 환경의 Studio와 모바일 플랫폼에서 호환되며, 입력 처리를 간소화합니다.

  • 메뉴 화면, 게임플레이 등 특정 상황에 따라 필요한 입력만 활성화할 수 있습니다.

  • UserInputState를 통해 입력 상태를 구분해 세부적인 동작을 설정할 수 있습니다.

사용 방법

1. 액션 생성하기

LocalScript에서 BindAction 함수를 이용해 액션을 생성할 수 있습니다. 액션을 생성할 때, 액션의 이름과 TouchButton 생성 여부, PC에서 사용할 입력 키를 지정할 수 있습니다.

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)

생성한 액션은 다음과 같이 글자나 버튼의 이미지, 위치를 설정할 수 있습니다.

ContextActionService:SetTitle(ActionName, "TEST")
ContextActionService:SetImage(ActionName, "ovdrassetid://1234")
ContextActionService:SetPosition(ActionName, UDim2.new(0.5, 0, 0.8, 0))

2. 액션 해제하기

상점에 입장했을 때 공격 버튼을 비활성화하는 등, 특정 액션이 필요하지 않을 때 UnbindAction 함수를 이용해 비활성화할 수 있습니다.

local ContextActionService = game:GetService("ContextActionService")
local ActionName = "JumpAction"

ContextActionService:UnbindAction(ActionName)

3. 입력 상태별 처리

UserInputState를 이용하여 입력 시작, 입력 중, 입력 종료와 같은 상태별 처리를 구현할 수 있습니다.

local function OnAction(actionName, inputState, inputObject)
    if inputState == Enum.UserInputState.Begin then
        print("Begin!")
        
    elseif inputState == Enum.UserInputState.Change then
        print("Change!")
        
    elseif inputState == Enum.UserInputState.End then
        print("End!")
        
    elseif inputState == Enum.UserInputState.Cancel then
        print("Cancel!")
    end
end
ContextActionService:BindAction(ActionName, OnAction, IsCreateTouchButton, KeyCode)
Type
설명

Begin

입력이 시작될 때

Change

입력이 지속 중일 때

End

입력이 종료될 때

Cancel

입력이 중단될 때 (예 : 입력점이 버튼 영역에서 이탈)

4. 특정 액션 가져오기

GetButton 함수로 특정 버튼을 가져올 수 있습니다.

local ActionButton = ContextActionService:GetButton(ActionName)

5. 생성된 액션 모두 가져오기

GetAllBoundActionInfo 함수로 모든 버튼을 가져올 수 있습니다.

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

기본 입력 처리

모바일 조이스틱, 점프 버튼 표시 제어

SetCoreGuiEnabled 함수로 모바일의 조이스틱과 점프 버튼의 표시 여부를 설정할 수 있습니다.

local StarterGui = game:GetService("StarterGui")

StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.Joystick, false)
StarterGui:SetCoreGuiEnabled(Enum.CoreGuiType.JumpButton, false)

모바일 화면 터치 감지

TouchStarted, TouchMoved, TouchEnded 이벤트를 사용하면 각각 터치 시작, 위치 변화, 종료에 대한 처리를 수행할 수 있습니다. 이 이벤트들의 연결 함수에는 input과 _gameProcessed가 인자로 전달됩니다.

  • input : 터치 입력 시점, 상태, 위치 등 관련 정보가 구성된 객체

  • _gameProcessed : 입력 위치가 아래에 나열된 UI 요소들과 겹치는 경우, true를 반환합니다.

    • 채팅창과 같은 네이티브 UI

    • 조이스틱, 점프 버튼과 같은 기본 조작 버튼

    • Active가 true인 GUI 버튼

    • BindAction으로 바인딩된 액션

local UserInputService = game:GetService("UserInputService")
local ActiveTouches = {} -- 동시에 발생하는 여러 터치 입력을 개별적으로 처리하기 위한 테이블

local function OnScreenTouchStart(input, _gameProcessed)
    local keyCode = input.KeyCode    
    if keyCode == Enum.KeyCode.Joystick then
        return
    end
    
    table.insert(ActiveTouches, input)
    
    local inputState = input.UserInputState -- End
    local inputType = input.UserInputType   -- Touch
    local delta = input.Delta
    local pos = input.Position    

    -- Do Something
end
UserInputService.TouchStarted:Connect(OnScreenTouchStart)

local function OnScreenTouchMove(input, _gameProcessed)
    local keyCode = input.KeyCode    
    if keyCode == Enum.KeyCode.Joystick then
        return
    end
        
    for i = 1, #ActiveTouches do
        -- 여러 터치 입력 중에서 현재 입력(input)에 해당하는 터치를 탐색
        if input == ActiveTouches[i] then
            local inputState = input.UserInputState -- End
            local inputType = input.UserInputType   -- Touch
            local delta = input.Delta
            local pos = input.Position            
            
            -- Do Something
        end
    end
end
UserInputService.TouchMoved:Connect(OnScreenTouchMove)

local function OnScreenTouchEnd(input, _gameProcessed)
    local keyCode = input.KeyCode    
    if keyCode == Enum.KeyCode.Joystick then
        return
    end

    local i
    for j = 1, #ActiveTouches do
        if input == ActiveTouches[j] then
            i = j
            break        
        end
    end
    
    local inputState = input.UserInputState -- End
    local inputType = input.UserInputType   -- Touch
    local delta = input.Delta
    local pos = input.Position 

    -- Do Something

    table.remove(ActiveTouches, i)
end
UserInputService.TouchEnded:Connect(OnScreenTouchEnd)

모바일 조이스틱 입력 감지

local UserInputService = game:GetService("UserInputService")

local function OnJoystickStart(input, _gameProcessed)
    local keyCode = input.KeyCode
    if keyCode ~= Enum.KeyCode.Joystick then
        return
    end
    
    local inputState = input.UserInputState -- Begin
    local inputType = input.UserInputType   -- Touch     
    local delta = input.Delta
    local pos = input.Position
    
    -- Do Something
end
UserInputService.TouchStarted:Connect(OnJoystickStart)

local function OnJoystickMove(input, _gameProcessed)   
    local keyCode = input.KeyCode
    if keyCode ~= Enum.KeyCode.Joystick then
        return
    end
    
    local inputState = input.UserInputState -- Change
    local inputType = input.UserInputType   -- Touch 
    local delta = input.Delta
    local pos = input.Position
    
    -- Do Something
end
UserInputService.TouchMoved:Connect(OnJoystickMove)

local function OnJoystickEnd(input, _gameProcessed)   
    local keyCode = input.KeyCode    
    if keyCode ~= Enum.KeyCode.Joystick then
        return
    end
    
    local inputState = input.UserInputState -- Change
    local inputType = input.UserInputType   -- Touch 
    local delta = input.Delta
    local pos = input.Position
    
    -- Do Something
end
UserInputService.TouchEnded:Connect(OnJoystickEnd)
Previous입력 및 조작NextTPS Strafing System

Last updated 2 days ago

📝