Blueprint로 만들었던 애님 노티파이와 노티파이 스테이트들을 전부 C++로 바꾸었다.
그 과정에서 리팩토링도 진행하였다.
AnimNotify_AttackFinished를 C++로 옮기고 보니 MontageComponent에서 State를 바꾸고 EquippedWeapon을 Get으로 참조해서 함수를 호출하고 중구난방이였다.
그래서 MontageComponent에는 AttackMontageFinished 함수를 만들어 몽타주 관련한것만 처리하고, StateComponent에서는 AttackStateFinished 함수를 만들어 State만 관리하고 WeaponBase에도 AttackFinished함수를 생성해서 관리하도록 만든 뒤
APlayerBase에서 AttackFinished함수를 만들고 이 함수에서 위의 함수들을 호출하도록 바꾸었다.이전 코드
void UAnimNotify_Attack_Finished::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { APlayerBase* playerBaseRef = Cast<APlayerBase>(MeshComp->GetOwner()); if (playerBaseRef) { UMontageComponent* montageComponentRef = playerBaseRef->GetMontageComponent(); AWeaponBase* weaponBaseRef = playerBaseRef->GetEquippedWeapon(); if (montageComponentRef && weaponBaseRef) { montageComponentRef->AttackMontageFinished(); weaponBaseRef->SetStrengthNormal(); } } } //MontageComponent::AttackMontageFinished() void UMontageComponent::AttackMontageFinished() { if (!CheckRef()) return; bNextCombo = false; bEnableCombo = false; if (StateComponentRef->GetActionState() < EActionState::EAS_Hitted) { StateComponentRef->SetActionState(EActionState::EAS_Idle); } StateComponentRef->MovementStateChanged(); AnimInstanceRef->Montage_Stop(0.5f); }수정된 코드
// MontageComponent void UMontageComponent::AttackMontageFinished() { if (!CheckRef()) return; bNextCombo = false; bEnableCombo = false; AnimInstanceRef->Montage_Stop(0.5f); } //StateComponent는 AttackStateFinished, AWeaponBase는 AttackFinished추가 //PlayerBase void APlayerBase::AttackFinished() { if (MontageComponent) { MontageComponent->AttackMontageFinished(); } if (StateComponent) { StateComponent->AttackStateFinished(); } if (EquippedWeapon) { EquippedWeapon->AttackFinished(); } } //AnimNotify_AttackFinished void UAnimNotify_Attack_Finished::Notify(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, const FAnimNotifyEventReference& EventReference) { APlayerBase* playerBaseRef = Cast<APlayerBase>(MeshComp->GetOwner()); if (playerBaseRef) { playerBaseRef->AttackFinished(); } }디자인 패턴 중 단일 책임 원칙을 적용시켜서 리팩토링 하였다.
확실히 깔끔해졌고, 내용을 추가함에 있어서도 편리해졌다.그외로 전반적으로 내용을 구분하고 설명하는 주석들도 전부 추가하였다.