본문 바로가기
개발/Unity

Unity)Input System( Player Input Compoent - Actions 사용 하기 )

by 테샤르 2023. 11. 6.

Input System ( Player Input Compoent - Actions 사용 하기 )

 

Unity 에서 지원하는  Input System 를 간략하게 사용하는 포스팅을 진행한다.

Input System을 사용하면 조이스틱(JoyStick) / 키보드 (KeyBord) / 마우스 (Mouse) / 터치스크린(TouchScreen) 등 여러가지 상황에서 Input 에 대한 처리가 굉장히 편리하다.

 

Legacy 방식으로는 코드에서 플랫폼 전처리와 각 상황에 맞춰서 코딩을 해줘야하는데 Input System으로는 간편하게 추가 삭제 및 관리가 유용하다.

 

< Input System 설치 UPM>

Unity Registry - Input System 검색 (Install)

 

UPM 설치 이후에는ㅇ Input Action을 생성해야한다.

<Input Action 생성하기>

Projects -> Input Action 

 

<Input System 설정>

Input System 사용하기 위해서는 Project 설정을 변경해줘야 한다.

[Project Setting]-[Player]-[Active Input Handing]- [Input Sydstem Package(New) 혹은 Both]

 

반응형

 

<Input Action Scheme 생성>

Input Action에 대한 정의를 해줘야한다.

생성된 Input Action [Edit Asset] 을 선택하면 창이 나온다. 여기에서 Add Control Scheme를 선택해서 생성하자.

 

간략하게 2가지 플랫폼에 대해서 Scheme를 생성하면 다음과 같다.

Scheme 선택 Mobile PC

 

 

<Action 정의하기 >

실제 사용하는 Action에 대한 정의는 다음과 같다.

Escape - Backkey 를 기준으로 등록한다.

 

<Player Input Component 추가 하기>

Player Input Component로 해당 Input 을 처리하는 객체에 추가해서 Events를 등록한다.

여러가지 형식으로 이벤트 등록이 가능하다.

SendMessages

 

Play  Mode를 통해서 해당 Key를 입력하면 정상적으로 동작하는것을 알 수 있다.

 

< 사전 정의된 인터렉션(Predefined Interactions) >

 

<Button 이벤트를 처리하는 경우 Callback Event >

public void ExcuteKeyEscape(InputAction.CallbackContext context)
{
    if (!context.performed) 
        return;
        ...
}

 

<Player Input Manager>

여러 이벤트에 대한 동작을 처리하려면 Input Manager를 사용하면 된다.

이벤트 설명
Player Joined Event 플레이어가 포함될 때 이벤트
Player Left Event 플레이어가 떠날 때 이벤트

 

 

 

<Input Debug>

 

 

<UI 요소의 이벤트가 동작하기 않는경우>

Input System UI Input Module 이 DefaultInputActions으로 되어야 UI 동작이 된다.

 

기본값으로 셋팅하려면 기존의 Component 제거 > Event System -> Add Default Input Modules 버튼 클릭

Replace width IputSystemUIInputModule 버튼 클릭

 

Unity Blog 새로운 입력 시스템 소개 : [링크]

 

새로운 입력 시스템 소개 | Unity Blog

이번 입력 시스템은 처음부터 사용 편의성, 플랫폼 간 일관성 및 유연성을 염두에 두고 만들었습니다. 향후 Unity 2020.1버전과 함께 릴리스될 예정이며 미리 사용해 보시고 의견을 공유해주시기

blog.unity.com

Input System : [링크]

 

Input System | Input System | 1.7.0

Input System The Input System allows your users to control your game or app using a device, touch, or gestures. Introduction Unity supports input through two separate systems, one older, and one newer. The older system, which is built-in to the editor, is

docs.unity3d.com

Workflow - PlayerInput Component : [링크]

 

Workflow Overview - Using an Actions Asset and PlayerInput Component | Input System | 1.6.3

Workflow Overview - Using an Actions Asset and PlayerInput Component The highest level of abstraction provided by the Input System is when you use the Actions Asset and the Player Input component together. The Player Input component takes a reference to an

docs.unity3d.com

 

★☆☆☆☆

 

반응형

댓글