打开UE引擎,创建空白C++文件 命名为SimpleCombatTypt
打开SimpleCombatTypt.h
// Fill out your copyright notice in the Description page of Project Settings. #pragma once #include "CoreMinimal.h" #include "SimpleCombatType.generated.h" USTRUCT(BlueprintType) struct SIMPLECOMBAT_API FSimpleCombatCheck { GENERATED_USTRUCT_BODY() FSimpleCombatCheck(); UPROPERTY(EditDefaultsOnly, Category = ComboAttack) int32 CombatIndex;//连击数 UPROPERTY(EditDefaultsOnly, Category = ComboAttack) bool bLongPress;//长按 UPROPERTY(EditDefaultsOnly, Category = ComboAttack) bool bShortPress;//短按 class ICombatInterface* Character;//CombatInterface UPROPERTY() int32 MaxIndex;//最大连击数 UPROPERTY() FName CombatKey;//技能名 void UpdateCombatIndex(); void Press(); void Released(); void Reset(); };
进行实现
#include "SimpleCombatType.h" #include "CombatInterface/CombatInterface.h" FSimpleCombatCheck::FSimpleCombatCheck() :CombatIndex(INDEX_NONE) , bLongPress(false) , bShortPress(false) , MaxIndex(0) , Character(NULL) { } void FSimpleCombatCheck::UpdateCombatIndex() { //检测最大连击数是否大于0 check(MaxIndex > 0) CombatIndex++; if (CombatIndex> MaxIndex) { //如果当前连击数大于最大连击数,则将连击数置为1 CombatIndex = 1; } } void FSimpleCombatCheck::Press() { if (CombatIndex==INDEX_NONE) { CombatIndex++; //当按下攻击时传入技能名,调用接口内的方法CombatAttack Character->CombatAttack(CombatKey); } bShortPress = true; bLongPress = true; } void FSimpleCombatCheck::Released() { bLongPress = false; } void FSimpleCombatCheck::Reset() { CombatIndex = INDEX_NONE; }
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)