1.创建AnimNotifyState C++类,命名为AnimNotifyState_ComboCheck
?2.打开AnimNotifyState_ComboCheck.h
#pragma once
#include "CoreMinimal.h"
#include "Animation/AnimNotifies/AnimNotifyState.h"
#include "AnimNotifyState_ComboCheck.generated.h"
/**
*
*/
UCLASS()
class SIMPLECOMBAT_API UAnimNotifyState_ComboCheck : public UAnimNotifyState
{
GENERATED_BODY()
public:
//AnimNotifyState基础三件套
virtual void NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration);
virtual void NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime);
virtual void NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation);
//技能名,需要在蓝图中配置
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AnimNotifyState_CheckCombo")
FName CombatKey;
};
进行实现
#include "AnimNotifyState/AnimNotifyState_ComboCheck.h"
#include "SimpleCombatType.h"
#include "CombatInterface/CombatInterface.h"
void UAnimNotifyState_ComboCheck::NotifyBegin(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float TotalDuration)
{
Super::NotifyBegin(MeshComp, Animation, TotalDuration);
if (ICombatInterface* InCharacter = Cast<ICombatInterface>(MeshComp->GetOuter()))
{
InCharacter->GetSimpleCombatInfo()->bShortPress = false;
InCharacter->GetSimpleCombatInfo()->UpdateCombatIndex();
}
}
void UAnimNotifyState_ComboCheck::NotifyTick(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation, float FrameDeltaTime)
{
Super::NotifyTick(MeshComp, Animation, FrameDeltaTime);
}
void UAnimNotifyState_ComboCheck::NotifyEnd(USkeletalMeshComponent* MeshComp, UAnimSequenceBase* Animation)
{
Super::NotifyEnd(MeshComp, Animation);
if (ICombatInterface* InCharacter = Cast<ICombatInterface>(MeshComp->GetOuter()))
{
//长按或短按,任一为true即可
if ((InCharacter->GetSimpleCombatInfo()->bLongPress || InCharacter->GetSimpleCombatInfo()->bShortPress))
{
InCharacter->CombatAttack(CombatKey);
}
}
}
3.配置动画通知
打开UE引擎,打开角色连击动画Montage,在动画通知轨道添加ComboCheck动画通知
在动画通知combatKey?中填写技能名
?
|