InputSystem - osy9611/ProjectPT GitHub Wiki
Unity์ InputSystem์ ์ฌ์ฉํ๊ณ ์ ์ฉํ๋ ์ฌ๋ก๋ฅผ ๊ฐ๋จํ ์ ๋ฆฌํ๊ณ Unreal์ InputSystem์ ๋ํด์ ๋ถ์ํ๊ณ ์ ๋ฆฌํ ๋ด์ฉ
ํด๋น ์ ๋ ฅ ์์คํ ์ ๊ณต๋ถํ๋ฉด์ ์ด์ ํ๋ก์ ํธ์์ ์ ์ฉํ๋ Unity Input System์ ์ค๊ณ๊ฐ ๋ ์ฌ๋ผ์ ์ถ๊ฐ์ ์ธ ์ ๋ฆฌ๋ฅผ ํ๋ ค๊ณ ํ๋ค.
-
Unity์๋ ์๋ก์ด New Input System์ด ๋์ ๋๋ฉด์ UE์ Input Mapping Context์ ๊ฐ์ด ์ ๋ ฅ ์คํค๋ง๋ฅผ ์์ฑํด์ ์ด์ฉํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค.
-
์ด์ ํ๋ก์ ํธ์ ์ ์ฉํ๋ Input System์ ๋งค๋์ ๋ก ๊ด๋ฆฌ๋ฅผ ์งํํ๋ค.
-
AddEvent
- Input ์คํค๋ง ์ด๋ฒคํธ์ ๋ํ ์ฝ๋ฐฑ ํจ์ ๋ฑ๋ก

- Input ์คํค๋ง ์ด๋ฒคํธ์ ๋ํ ์ฝ๋ฐฑ ํจ์ ๋ฑ๋ก
-
Remove Event
- ํน์ ์
๋ ฅ ์ด๋ฒคํธ์์ ์ฝ๋ฐฑ ํจ์ ์ ๊ฑฐ

- ํน์ ์
๋ ฅ ์ด๋ฒคํธ์์ ์ฝ๋ฐฑ ํจ์ ์ ๊ฑฐ
ํด๋น ํ๋ก์ ํธ์์๋ ๊ธฐ์กด ์ธ๋ฆฌ์ผ ์ ๋ ฅ ๋ฐฉ์์ด ์๋ UE 5 ๋ฒ์ ์ Enhance Input์ ์ ์ฉํ๋ค. ๊ณ ๋ก ์ด์ ์ ์ธ๋ฆฌ์ผ ์ ๋ ฅ ๋ฐฉ์์ ๊ฐ๋จํ๊ฒ ์ ๋ฆฌ๋ฅผ ํ๊ณ UE5 ๋ฒ์ ์ EnhaceInput์์ฃผ๋ก ์ ๋ฆฌ๋ฅผ ํ๋ ค๊ณ ํ๋ค.
-
๊ธฐ์กด ์ธ๋ฆฌ์ผ ์ ๋ ฅ ์์คํ ์ ํ๋ก์ ํธ ์ธํ ์์ ํค๋ฅผ ๋ฑ๋กํ๊ณ Bindํด์ ์ฌ์ฉํ๋ค.

-
์ธ๋ฆฌ์ผ 5 ๋ฒ์ ์ผ๋ก ๋์ด์ค๋ฉด์ Enhanced Input ์์คํ ์ด ์ ์์ผ๋ก ๋์ ๋๋ฉด์ ํ๋ก์ ํธ ์ธํ ์ด ์๋ Input Mapping Context์ ์์ฑํด์ ์ ๋ ฅ ๋งคํ์ ํ๊ฒ๋์๋ค.
-
Input Action
- ํน์ ํค๋ ์กฐ์์ ํตํด ๋ฐ์ํ๋ ์ก์ ์ ์ ์ํ๋ค.
- bool, float, Vector2D, Vector3D ๋ฑ์ ์ง์ํจ
-
Input Mapping Contexts
- ํน์ ์ปจํ ์คํธ์์ ์ ๋ ฅ ์ก์ ์ ๋ฐ์ธ๋ฉํ๋ ์ญํ ์ ํ๋ค.
- Input Modifilers
- ์ ๋ ฅ ๊ฐ์ ๋ณํํ๋ ์ญํ ์ ํ๋ค.
- ex) ํน์ ์ถ์ ์์๋ฅผ ๋ณ๊ฒฝํ๊ฑฐ๋ ์ ๋ ฅ ๊ฐ์ ๋ฐ๋๋ก ๋ง๋ค ์ ์์
- Input Triggers
- ์ ๋ ฅ ์ก์ ์ ํน์ ์กฐ๊ฑด์ ์ค์ ํ๋ ์ญํ ์ ํ๋ค.
- ex) ์งง๊ฒ ๋๋ฅด๋ฉด ์ฝ๊ณต๊ฒฉ, ๊ธธ๊ฒ ๋๋ฅด๋ฉด ๊ฐ๊ณต๊ฒฉ๊ณผ ๊ฐ์ ๊ธฐ๋ฅ์ ์ค์ ํ ์ ์์
- ์์

Unity์ InputSystem๊ณผ ๋น์ทํ๊ฒ ์์ ์ ์งํํ๋ค. ์ถํ ๋ผ์ด๋ผ ์ฝ๋๋ฅผ ๋ถ์ํด ๋ถ์กฑํ ๋ถ๋ถ์ ์ถ๊ฐํ๋ค.
-
InputConfig
- GameplayTag๋ฅผ ์ด์ฉํด ๊ฐ IA ๊ด๋ฆฌ๋ฅผ ์งํ
-
PTInputComponent
-
BindNativeActions
-
C++์ฝ๋์์ ์์ฑํ ํจ์๋ฅผ BindAction์ผ๋ก ๋ฑ๋กํ๋๋ก ๊ตฌํ
-
์ฃผ์ ์ฝ๋
template <class UserClass, typename FuncType> void UPTInputComponent::BindNativeAction(const UPTInputConfig* InputConfig, const FGameplayTag& InputTag, ETriggerEvent TriggerEvent, UserClass* Object, FuncType Func, bool bLogIfNotFound) { check(InputConfig); if (const UInputAction* IA = InputConfig->FindNativeInputActionForTag(InputTag, bLogIfNotFound)) BindAction(IA, TriggerEvent, Object, Func); }
-
-
BindAbilityActions
-
GAS ์ด๋ฒคํธ๋ฅผ BindAction์ผ๋ก ๋ฑ๋ก ํ๋๋ก ๊ตฌํ
-
์ด๊ธฐ์๋ ํด๋น ๋ถ๋ถ๋ BindNativeActions๊ณผ ํตํฉํด์ ์ฌ์ฉํ์ง๋ง ์ถํ ๋ผ์ด๋ผ ๋ถ์์ ํตํด์ ๋ค์๊ณผ ๊ฐ์ด ๋ถ๋ฆฌ๋ฅผ ์งํํ๋ค.
-
์ฃผ์ ์ฝ๋
template <class UserClass, typename PressedFuncType, typename ReleasedFuncType> void UPTInputComponent::BindAbilityActions(const UPTInputConfig* InputConfig, UserClass* Object, PressedFuncType PressedFunc, ReleasedFuncType ReleasedFunc, TArray<uint32>& BindHandles) { check(InputConfig); //AbilityAction์ ๋ํด์๋ ๊ทธ๋ฅ ๋ชจ๋ InputAction์ ๋ค ๋ฐ์ธ๋ฉ ์ํจ๋ค for (const FPTInputAction& Action : InputConfig->AbilityInputActions) { if (Action.InputAction && Action.InputTag.IsValid()) { if (PressedFunc) BindHandles.Add(BindAction(Action.InputAction, ETriggerEvent::Triggered, Object, PressedFunc, Action.InputTag).GetHandle()); if (ReleasedFunc) BindHandles.Add(BindAction(Action.InputAction, ETriggerEvent::Completed, Object, ReleasedFunc, Action.InputTag).GetHandle()); } } }
-
-
-
GAS Input ์ฒ๋ฆฌ
์ฒ์ GAS๋ฅผ ์ฒ๋ฆฌํ ๋ ๊ฐ ์ ๋ ฅ ์ด๋ฒคํธ๋ฅผ ๊ฐ๊ฐ ์ฒ๋ฆฌํด์ Bind๋ฅผ ์งํํ๋ค. ๋ผ์ด๋ผ ๋ถ์ ํ AbilitySystemComponent์ ํธ๋ค์ ๋ฑ๋กํด์ ์ฌ์ฉํ๋ ๋ฐฉ์์ ์ฌ์ฉํ๋ค.
-
InputPress ๋๋ InputReleased ์ด๋ฒคํธ๊ฐ ๋ค์ด์ค๋ฉด ํ์ํ ํธ๋ค์ ๋ฑ๋ก
-
์ฃผ์ ์ฝ๋
oid UPTAbilitySystemComponent::AbilityInputTagPressed(const FGameplayTag& InputTag) { if (InputTag.IsValid()) { for (const FGameplayAbilitySpec& AbilitySpec : ActivatableAbilities.Items) { if (AbilitySpec.Ability && (AbilitySpec.DynamicAbilityTags.HasTagExact(InputTag))) { InputPressedSpecHandles.AddUnique(AbilitySpec.Handle); InputHeldSpecHandles.AddUnique(AbilitySpec.Handle); } } } }
-
-
ํธ๋ค์ ๋ฑ๋ก๋ ์ด๋ฒคํธ๋ฅผ ๊ฒ์ํด ๋ฑ๋ก๋ ํธ๋ค์ด ์๋ค๋ฉด GAS๋ฅผ ์คํ
-
์ฃผ์ ์ฝ๋
for (const FGameplayAbilitySpecHandle& Handle : InputHeldSpecHandles) { if (const FGameplayAbilitySpec* AbilitySpec = FindAbilitySpecFromHandle(Handle)) { if (AbilitySpec->Ability && !AbilitySpec->IsActive()) { const UPTGameplayAbility* AbilityCDO = CastChecked<UPTGameplayAbility>(AbilitySpec->Ability); if (AbilityCDO->ActivationPolicy == EPTAbilityActivationPolicy::WhileInputActive) ExecuteHandles.AddUnique(AbilitySpec->Handle); } } }
-
-