feat: Binaries添加到LFS,增加生命值网络同步功能
This commit is contained in:
1
.gitattributes
vendored
1
.gitattributes
vendored
@@ -1 +1,2 @@
|
|||||||
Content/** filter=lfs diff=lfs merge=lfs -text
|
Content/** filter=lfs diff=lfs merge=lfs -text
|
||||||
|
Binaries/** filter=lfs diff=lfs merge=lfs -text
|
||||||
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,4 @@
|
|||||||
Binaries
|
# Binaries
|
||||||
DerivedDataCache
|
DerivedDataCache
|
||||||
Intermediate
|
Intermediate
|
||||||
Saved
|
Saved
|
||||||
@@ -9,9 +9,11 @@ Saved
|
|||||||
*.opendb
|
*.opendb
|
||||||
*.sdf
|
*.sdf
|
||||||
*.sln
|
*.sln
|
||||||
|
*.sln.DotSettings.user
|
||||||
*.suo
|
*.suo
|
||||||
*.xcodeproj
|
*.xcodeproj
|
||||||
*.xcworkspace
|
*.xcworkspace
|
||||||
|
|
||||||
.idea
|
.idea
|
||||||
.vsconfig
|
.vsconfig
|
||||||
|
*.pdb
|
||||||
BIN
Binaries/Win64/FirstPersonDemoEditor.target
LFS
Normal file
BIN
Binaries/Win64/FirstPersonDemoEditor.target
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.dll
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.dll
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_0.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_1.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_2.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_3.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_4.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exe
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exe
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exp
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.exp
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.lib
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor-FirstPersonDemo.patch_5.lib
LFS
Normal file
Binary file not shown.
BIN
Binaries/Win64/UnrealEditor.modules
LFS
Normal file
BIN
Binaries/Win64/UnrealEditor.modules
LFS
Normal file
Binary file not shown.
@@ -1,3 +1,11 @@
|
|||||||
# FirstPersonDemo
|
# FirstPersonDemo
|
||||||
|
|
||||||
Developed with Unreal Engine 5
|
Developed with Unreal Engine 5
|
||||||
|
|
||||||
|
asdfasdf
|
||||||
|
|
||||||
|
sdfsdfdsf
|
||||||
|
|
||||||
|
dsfsdfd
|
||||||
|
sdds
|
||||||
|
Ciallo
|
||||||
|
|||||||
1
Source/FirstPersonDemo/Surviver_FPS/.gitignore
vendored
Normal file
1
Source/FirstPersonDemo/Surviver_FPS/.gitignore
vendored
Normal file
@@ -0,0 +1 @@
|
|||||||
|
html/*
|
||||||
@@ -14,7 +14,7 @@ class UDamageableInterface : public UInterface {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @class IDamageableInterface
|
* @class IDamageableInterface
|
||||||
* @brief 伤害组件
|
* @brief 伤害接口
|
||||||
* @ingroup Battle
|
* @ingroup Battle
|
||||||
*/
|
*/
|
||||||
class FIRSTPERSONDEMO_API IDamageableInterface {
|
class FIRSTPERSONDEMO_API IDamageableInterface {
|
||||||
|
|||||||
@@ -2,28 +2,41 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "Surviver_FPS/Battle/EnemyBase.h"
|
#include "Surviver_FPS/Battle/EnemyBase.h"
|
||||||
|
#include "HealthComponent.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
|
||||||
// Sets default values
|
/**
|
||||||
|
* @brief AEnemyBase的构造函数。
|
||||||
|
*/
|
||||||
AEnemyBase::AEnemyBase() {
|
AEnemyBase::AEnemyBase() {
|
||||||
// Set this pawn to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// 允许该Pawn每帧调用Tick()
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
// 创建并附加生命组件
|
||||||
|
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("HealthComponent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
|
||||||
void AEnemyBase::BeginPlay() {
|
void AEnemyBase::BeginPlay() {
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
|
||||||
void AEnemyBase::Tick(float DeltaTime) {
|
void AEnemyBase::Tick(float DeltaTime) {
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called to bind functionality to input
|
|
||||||
void AEnemyBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
|
void AEnemyBase::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
|
||||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 接收伤害的实现。
|
||||||
|
* @param DamageAmount 伤害量。
|
||||||
|
* @param InstigatorActor 造成伤害的Actor。
|
||||||
|
*/
|
||||||
void AEnemyBase::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
|
void AEnemyBase::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
|
||||||
return;
|
if (HealthComponent)
|
||||||
|
{
|
||||||
|
// 通过生命组件处理伤害
|
||||||
|
HealthComponent->HandleDamage(DamageAmount);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,36 +7,41 @@
|
|||||||
#include "GameFramework/Pawn.h"
|
#include "GameFramework/Pawn.h"
|
||||||
#include "EnemyBase.generated.h"
|
#include "EnemyBase.generated.h"
|
||||||
|
|
||||||
|
class UHealthComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class AEnemyBase
|
* @class AEnemyBase
|
||||||
* @brief 敌人基类
|
* @brief 敌人基类,实现了可受伤害接口。
|
||||||
* @ingroup Battle
|
* @ingroup Battle
|
||||||
* @todo 实现TakeDamage接口,挂HealthComponent组件
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class FIRSTPERSONDEMO_API AEnemyBase : public APawn, public IDamageableInterface {
|
class FIRSTPERSONDEMO_API AEnemyBase : public APawn, public IDamageableInterface {
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this pawn's properties
|
/**
|
||||||
|
* @brief 构造函数,设置Pawn的默认属性。
|
||||||
|
*/
|
||||||
AEnemyBase();
|
AEnemyBase();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
/**
|
||||||
|
* @brief 管理敌人生命值的组件。
|
||||||
|
*/
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
|
||||||
|
UHealthComponent* HealthComponent;
|
||||||
|
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called every frame
|
|
||||||
virtual void Tick(float DeltaTime) override;
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
// Called to bind functionality to input
|
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 敌人受伤函数
|
* @brief 接收伤害的接口实现。
|
||||||
* @param DamageAmount 伤害量
|
* @param DamageAmount 伤害量。
|
||||||
|
* @param InstigatorActor 造成伤害的Actor。
|
||||||
*/
|
*/
|
||||||
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
|
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,36 +2,66 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "HealthComponent.h"
|
#include "HealthComponent.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
#include "Net/UnrealNetwork.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 定义需要网络同步的属性。
|
||||||
|
* @param OutLifetimeProps 存储同步属性的数组。
|
||||||
|
*/
|
||||||
|
void UHealthComponent::GetLifetimeReplicatedProps(TArray<FLifetimeProperty>& OutLifetimeProps) const {
|
||||||
|
Super::GetLifetimeReplicatedProps(OutLifetimeProps);
|
||||||
|
|
||||||
// Sets default values for this component's properties
|
DOREPLIFETIME(UHealthComponent, CurrentHealth);
|
||||||
UHealthComponent::UHealthComponent() {
|
|
||||||
// Set this component to be initialized when the game starts, and to be ticked every frame. You can turn these features
|
|
||||||
// off to improve performance if you don't need them.
|
|
||||||
PrimaryComponentTick.bCanEverTick = true;
|
|
||||||
|
|
||||||
// ...
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief UHealthComponent的构造函数。
|
||||||
|
*/
|
||||||
|
UHealthComponent::UHealthComponent() {
|
||||||
|
// 关闭每帧Tick以提高性能
|
||||||
|
PrimaryComponentTick.bCanEverTick = false;
|
||||||
|
// 默认启用网络复制
|
||||||
|
SetIsReplicatedByDefault(true);
|
||||||
|
}
|
||||||
|
|
||||||
// Called when the game starts
|
/**
|
||||||
|
* @brief 组件开始运行时调用。
|
||||||
|
*/
|
||||||
void UHealthComponent::BeginPlay() {
|
void UHealthComponent::BeginPlay() {
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
// 初始化当前生命值为最大生命值
|
||||||
|
CurrentHealth = MaxHealth;
|
||||||
|
}
|
||||||
|
|
||||||
// ...
|
/**
|
||||||
|
* @brief 当CurrentHealth属性被复制时在客户端上调用。
|
||||||
|
*/
|
||||||
|
void UHealthComponent::OnRep_CurrentHealth() {
|
||||||
|
// 在客户端上,当CurrentHealth被复制时调用
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Called every frame
|
|
||||||
void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType,
|
void UHealthComponent::TickComponent(float DeltaTime, ELevelTick TickType,
|
||||||
FActorComponentTickFunction* ThisTickFunction) {
|
FActorComponentTickFunction* ThisTickFunction) {
|
||||||
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
Super::TickComponent(DeltaTime, TickType, ThisTickFunction);
|
||||||
// ...
|
// ...
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 供外部调用的伤害处理函数。
|
||||||
|
* @param DamageAmount 伤害量。
|
||||||
|
*/
|
||||||
void UHealthComponent::HandleDamage(float DamageAmount) {
|
void UHealthComponent::HandleDamage(float DamageAmount) {
|
||||||
|
if (DamageAmount <= 0.0f) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// 仅在服务器上处理伤害逻辑
|
||||||
|
if (GetOwner()->HasAuthority()) {
|
||||||
|
CurrentHealth = FMath::Clamp(CurrentHealth - DamageAmount, 0.0f, MaxHealth);
|
||||||
|
if (CurrentHealth <= 0.0f) {
|
||||||
|
OnDeath.Broadcast();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,8 +4,14 @@
|
|||||||
|
|
||||||
#include "CoreMinimal.h"
|
#include "CoreMinimal.h"
|
||||||
#include "Components/ActorComponent.h"
|
#include "Components/ActorComponent.h"
|
||||||
|
#include "Net/UnrealNetwork.h"
|
||||||
#include "HealthComponent.generated.h"
|
#include "HealthComponent.generated.h"
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 当生命值降为0时调用的多播委托。
|
||||||
|
*/
|
||||||
|
DECLARE_DYNAMIC_MULTICAST_DELEGATE(FOnDeath);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class UHealthComponent
|
* @class UHealthComponent
|
||||||
* @brief 生命组件
|
* @brief 生命组件
|
||||||
@@ -17,30 +23,46 @@ class FIRSTPERSONDEMO_API UHealthComponent : public UActorComponent {
|
|||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this component's properties
|
|
||||||
UHealthComponent();
|
UHealthComponent();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 死亡时广播的多播委托。可以在蓝图中绑定事件。
|
||||||
|
*/
|
||||||
|
UPROPERTY(BlueprintAssignable, Category = "Health")
|
||||||
|
FOnDeath OnDeath;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// 最大生命值
|
/**
|
||||||
|
* @brief 角色的最大生命值。
|
||||||
|
*/
|
||||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health")
|
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health")
|
||||||
float MaxHealth = 100.0f;
|
float MaxHealth = 100.0f;
|
||||||
|
|
||||||
// 当前生命值
|
/**
|
||||||
UPROPERTY(BlueprintReadOnly, EditAnywhere, Category="Health")
|
* @brief 角色的当前生命值。此属性会从服务器复制到客户端。
|
||||||
|
*/
|
||||||
|
UPROPERTY(BlueprintReadOnly, ReplicatedUsing=OnRep_CurrentHealth, Category="Health")
|
||||||
float CurrentHealth;
|
float CurrentHealth;
|
||||||
|
|
||||||
// Called when the game starts
|
/**
|
||||||
virtual void BeginPlay() override;
|
* @brief 当CurrentHealth属性被复制时在客户端上调用的函数。
|
||||||
|
* @todo 处理客户端上的血条UI更新等逻辑。
|
||||||
|
*/
|
||||||
|
UFUNCTION()
|
||||||
|
void OnRep_CurrentHealth();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 游戏开始时调用,用于初始化组件。
|
||||||
|
*/
|
||||||
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Called every frame
|
|
||||||
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
virtual void TickComponent(float DeltaTime, ELevelTick TickType,
|
||||||
FActorComponentTickFunction* ThisTickFunction) override;
|
FActorComponentTickFunction* ThisTickFunction) override;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief 处理伤害
|
* @brief 外部调用以处理伤害的函数。
|
||||||
* @param DamageAmount 伤害量
|
* @param DamageAmount 伤害量。
|
||||||
* @todo 实现血量计算,处理死亡逻辑
|
|
||||||
*/
|
*/
|
||||||
UFUNCTION(BlueprintCallable, Category="Health")
|
UFUNCTION(BlueprintCallable, Category="Health")
|
||||||
void HandleDamage(float DamageAmount);
|
void HandleDamage(float DamageAmount);
|
||||||
|
|||||||
@@ -2,30 +2,62 @@
|
|||||||
|
|
||||||
|
|
||||||
#include "SuriverPlayer.h"
|
#include "SuriverPlayer.h"
|
||||||
|
#include "HealthComponent.h"
|
||||||
|
#include "GameFramework/Actor.h"
|
||||||
|
|
||||||
|
/**
|
||||||
// Sets default values
|
* @brief ASuriverPlayer的构造函数。
|
||||||
|
*/
|
||||||
ASuriverPlayer::ASuriverPlayer() {
|
ASuriverPlayer::ASuriverPlayer() {
|
||||||
// Set this character to call Tick() every frame. You can turn this off to improve performance if you don't need it.
|
// 允许该角色每帧调用Tick()
|
||||||
PrimaryActorTick.bCanEverTick = true;
|
PrimaryActorTick.bCanEverTick = true;
|
||||||
|
|
||||||
|
// 创建并附加生命组件
|
||||||
|
HealthComponent = CreateDefaultSubobject<UHealthComponent>(TEXT("HealthComponent"));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called when the game starts or when spawned
|
/**
|
||||||
|
* @brief 游戏开始或角色生成时调用。
|
||||||
|
*/
|
||||||
void ASuriverPlayer::BeginPlay() {
|
void ASuriverPlayer::BeginPlay() {
|
||||||
Super::BeginPlay();
|
Super::BeginPlay();
|
||||||
|
if (HealthComponent) {
|
||||||
|
HealthComponent->OnDeath.AddDynamic(this, &ASuriverPlayer::OnPlayerDied);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called every frame
|
/**
|
||||||
|
* @brief 每帧调用。
|
||||||
|
* @param DeltaTime 帧间隔时间。
|
||||||
|
*/
|
||||||
void ASuriverPlayer::Tick(float DeltaTime) {
|
void ASuriverPlayer::Tick(float DeltaTime) {
|
||||||
Super::Tick(DeltaTime);
|
Super::Tick(DeltaTime);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Called to bind functionality to input
|
/**
|
||||||
|
* @brief 绑定输入功能。
|
||||||
|
* @param PlayerInputComponent 用于绑定输入的组件。
|
||||||
|
*/
|
||||||
void ASuriverPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
|
void ASuriverPlayer::SetupPlayerInputComponent(UInputComponent* PlayerInputComponent) {
|
||||||
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
Super::SetupPlayerInputComponent(PlayerInputComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 接收伤害的实现。
|
||||||
|
* @param DamageAmount 伤害量。
|
||||||
|
* @param InstigatorActor 造成伤害的Actor。
|
||||||
|
*/
|
||||||
void ASuriverPlayer::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
|
void ASuriverPlayer::ReceiveDamage(float DamageAmount, AActor* InstigatorActor) {
|
||||||
|
if (HealthComponent) {
|
||||||
|
// 通过生命组件处理伤害
|
||||||
|
HealthComponent->HandleDamage(DamageAmount);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 当玩家死亡时调用,打印日志。
|
||||||
|
* @todo 通知 GameMode 玩家已死亡,处理结算逻辑
|
||||||
|
*/
|
||||||
|
void ASuriverPlayer::OnPlayerDied() {
|
||||||
|
UE_LOG(LogTemp, Warning, TEXT("你死了"));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -7,31 +7,48 @@
|
|||||||
#include "GameFramework/Character.h"
|
#include "GameFramework/Character.h"
|
||||||
#include "SuriverPlayer.generated.h"
|
#include "SuriverPlayer.generated.h"
|
||||||
|
|
||||||
|
class UHealthComponent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @class ASuriverPlayer
|
* @class ASuriverPlayer
|
||||||
* @brief 玩家基类
|
* @brief 玩家角色基类,实现了可受伤害接口。
|
||||||
* @ingroup Battle
|
* @ingroup Battle
|
||||||
* @todo 实现TakeDamage接口,挂HealthComponent组件
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
UCLASS()
|
UCLASS()
|
||||||
class FIRSTPERSONDEMO_API ASuriverPlayer : public ACharacter, public IDamageableInterface {
|
class FIRSTPERSONDEMO_API ASuriverPlayer : public ACharacter, public IDamageableInterface {
|
||||||
GENERATED_BODY()
|
GENERATED_BODY()
|
||||||
|
|
||||||
public:
|
public:
|
||||||
// Sets default values for this character's properties
|
/**
|
||||||
|
* @brief 构造函数,设置角色的默认属性。
|
||||||
|
*/
|
||||||
ASuriverPlayer();
|
ASuriverPlayer();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
/**
|
||||||
|
* @brief 管理角色生命值的组件。
|
||||||
|
*/
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "Components")
|
||||||
|
UHealthComponent* HealthComponent;
|
||||||
|
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|
||||||
public:
|
/**
|
||||||
// Called every frame
|
* @brief 当玩家死亡时调用。
|
||||||
virtual void Tick(float DeltaTime) override;
|
* @todo 添加死亡处理逻辑,如UI弹窗等
|
||||||
|
*/
|
||||||
|
UFUNCTION()
|
||||||
|
void OnPlayerDied();
|
||||||
|
|
||||||
// Called to bind functionality to input
|
public:
|
||||||
|
virtual void Tick(float DeltaTime) override;
|
||||||
|
|
||||||
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
virtual void SetupPlayerInputComponent(class UInputComponent* PlayerInputComponent) override;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @brief 接收伤害的接口实现。
|
||||||
|
* @param DamageAmount 伤害量。
|
||||||
|
* @param InstigatorActor 造成伤害的Actor。
|
||||||
|
*/
|
||||||
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
|
virtual void ReceiveDamage(float DamageAmount, AActor* InstigatorActor) override;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,12 +2,12 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup GameCore 核心玩法系统
|
* @defgroup GameCore 核心玩法系统
|
||||||
* 包含游戏模式、角色和控制器等基础类。
|
* 包含游戏模式、控制器等基础类。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @defgroup Battle 战斗系统
|
* @defgroup Battle 战斗系统
|
||||||
* 包含所有枪械、投射物和拾取物。
|
* 包含玩家角色、敌人、枪械、投射物和拾取物。
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user