InputSystem - osy9611/ProjectPT GitHub Wiki

Unity์˜ InputSystem์„ ์‚ฌ์šฉํ•˜๊ณ  ์ ์šฉํ–ˆ๋˜ ์‚ฌ๋ก€๋ฅผ ๊ฐ„๋‹จํžˆ ์ •๋ฆฌํ•˜๊ณ  Unreal์˜ InputSystem์— ๋Œ€ํ•ด์„œ ๋ถ„์„ํ•˜๊ณ  ์ •๋ฆฌํ•œ ๋‚ด์šฉ

Unity Input System

ํ•ด๋‹น ์ž…๋ ฅ ์‹œ์Šคํ…œ์„ ๊ณต๋ถ€ํ•˜๋ฉด์„œ ์ด์ „ ํ”„๋กœ์ ํŠธ์—์„œ ์ ์šฉํ–ˆ๋˜ Unity Input System์˜ ์„ค๊ณ„๊ฐ€ ๋– ์˜ฌ๋ผ์„œ ์ถ”๊ฐ€์ ์ธ ์ •๋ฆฌ๋ฅผ ํ•˜๋ ค๊ณ ํ•œ๋‹ค.

  • Unity์—๋„ ์ƒˆ๋กœ์šด New Input System์ด ๋„์ž…๋˜๋ฉด์„œ UE์˜ Input Mapping Context์™€ ๊ฐ™์ด ์ž…๋ ฅ ์Šคํ‚ค๋งˆ๋ฅผ ์ž‘์„ฑํ•ด์„œ ์ด์šฉํ•˜๋Š” ๋ฐฉ์‹์„ ์‚ฌ์šฉํ–ˆ๋‹ค.

  • ์ด์ „ ํ”„๋กœ์ ํŠธ์— ์ ์šฉํ–ˆ๋˜ Input System์„ ๋งค๋‹ˆ์ €๋กœ ๊ด€๋ฆฌ๋ฅผ ์ง„ํ–‰ํ–ˆ๋‹ค.

  • AddEvent

    • Input ์Šคํ‚ค๋งˆ ์ด๋ฒคํŠธ์— ๋Œ€ํ•œ ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ๋“ฑ๋ก

  • Remove Event

    • ํŠน์ • ์ž…๋ ฅ ์ด๋ฒคํŠธ์—์„œ ์ฝœ๋ฐฑ ํ•จ์ˆ˜ ์ œ๊ฑฐ

Unreal Inputsystem

ํ•ด๋‹น ํ”„๋กœ์ ํŠธ์—์„œ๋Š” ๊ธฐ์กด ์–ธ๋ฆฌ์–ผ ์ž…๋ ฅ ๋ฐฉ์‹์ด ์•„๋‹Œ 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) ์งง๊ฒŒ ๋ˆ„๋ฅด๋ฉด ์•ฝ๊ณต๊ฒฉ, ๊ธธ๊ฒŒ ๋ˆ„๋ฅด๋ฉด ๊ฐ•๊ณต๊ฒฉ๊ณผ ๊ฐ™์€ ๊ธฐ๋Šฅ์„ ์„ค์ •ํ•  ์ˆ˜ ์žˆ์Œ
    • ์˜ˆ์‹œ

Project PT์—๋Š” ์–ด๋–ป๊ฒŒ ์ ์šฉํ–ˆ๋Š”๊ฐ€

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);
        		}
        	}
        }
โš ๏ธ **GitHub.com Fallback** โš ๏ธ