create GE_DeathEffect
This commit is contained in:
@@ -6,6 +6,7 @@
|
||||
#include "Components/WidgetComponent.h"
|
||||
#include "GAS/CAbilitySystemComponent.h"
|
||||
#include "GAS/CAttributeSet.h"
|
||||
#include "GAS/UCAbilitySystemStatics.h"
|
||||
#include "Kismet/GameplayStatics.h"
|
||||
#include "Widgets/OverHeadStatsGauge.h"
|
||||
|
||||
@@ -29,6 +30,8 @@ ACCharacter::ACCharacter()
|
||||
**/
|
||||
OverHeadWidgetComponent = CreateDefaultSubobject<UWidgetComponent>("OverHead Widget Component");
|
||||
OverHeadWidgetComponent->SetupAttachment(GetRootComponent());
|
||||
|
||||
BindGASChangeDelegate();
|
||||
}
|
||||
|
||||
void ACCharacter::ServerSideInit()
|
||||
@@ -67,6 +70,27 @@ UAbilitySystemComponent* ACCharacter::GetAbilitySystemComponent() const
|
||||
return CAbilitySystemComponent;
|
||||
}
|
||||
|
||||
void ACCharacter::DeadTagUpdated(FGameplayTag GameplayTag, int32 NewCount)
|
||||
{
|
||||
if (NewCount != 0)
|
||||
{
|
||||
StartDeathSequence();
|
||||
}
|
||||
else
|
||||
{
|
||||
ReSpawn();
|
||||
}
|
||||
}
|
||||
|
||||
void ACCharacter::BindGASChangeDelegate()
|
||||
{
|
||||
if (CAbilitySystemComponent)
|
||||
{
|
||||
CAbilitySystemComponent->RegisterGameplayTagEvent(UCAbilitySystemStatics::GetDeadStatTag())
|
||||
.AddUObject(this, &ThisClass::DeadTagUpdated);
|
||||
}
|
||||
}
|
||||
|
||||
void ACCharacter::ConfigureOverHeadStatusWidget()
|
||||
{
|
||||
if (!OverHeadWidgetComponent) return;
|
||||
@@ -100,3 +124,13 @@ void ACCharacter::UpdateHeadStatGaugeVisibility()
|
||||
OverHeadWidgetComponent->SetHiddenInGame(DistSquared > HeadStatGaugeVisibilityRangeSquared);
|
||||
}
|
||||
}
|
||||
|
||||
void ACCharacter::StartDeathSequence()
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("----------------------------DEAD"));
|
||||
}
|
||||
|
||||
void ACCharacter::ReSpawn()
|
||||
{
|
||||
UE_LOG(LogTemp, Warning, TEXT("----------------------------Respawn"));
|
||||
}
|
||||
|
||||
@@ -3,6 +3,15 @@
|
||||
|
||||
#include "GAS/CAbilitySystemComponent.h"
|
||||
|
||||
#include "GAS/CAttributeSet.h"
|
||||
|
||||
|
||||
|
||||
UCAbilitySystemComponent::UCAbilitySystemComponent()
|
||||
{
|
||||
GetGameplayAttributeValueChangeDelegate(UCAttributeSet::GetHealthAttribute())
|
||||
.AddUObject(this, &UCAbilitySystemComponent::HealthUpdated);
|
||||
}
|
||||
|
||||
void UCAbilitySystemComponent::ApplyInitialEffects()
|
||||
{
|
||||
@@ -43,3 +52,13 @@ void UCAbilitySystemComponent::GiveInitialAbilities()
|
||||
));
|
||||
}
|
||||
}
|
||||
|
||||
void UCAbilitySystemComponent::HealthUpdated(const FOnAttributeChangeData& ChangeData)
|
||||
{
|
||||
if (!GetOwner() && !GetOwner()->HasAuthority()) return;
|
||||
if (ChangeData.NewValue <= 0 && DeathEffectClass)
|
||||
{
|
||||
const auto GameplayEffectSpecHandle{ MakeOutgoingSpec(DeathEffectClass, 1, MakeEffectContext() )};
|
||||
ApplyGameplayEffectSpecToSelf(*GameplayEffectSpecHandle.Data.Get());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,3 +7,8 @@ FGameplayTag UCAbilitySystemStatics::GetBasicAttackAbilityTag()
|
||||
{
|
||||
return FGameplayTag::RequestGameplayTag("ability.basicattack");
|
||||
}
|
||||
|
||||
FGameplayTag UCAbilitySystemStatics::GetDeadStatTag()
|
||||
{
|
||||
return FGameplayTag::RequestGameplayTag("stats.dead");
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AbilitySystemInterface.h"
|
||||
#include "GameplayTagContainer.h"
|
||||
#include "GameFramework/Character.h"
|
||||
#include "CCharacter.generated.h"
|
||||
|
||||
@@ -34,6 +35,8 @@ public:
|
||||
virtual UAbilitySystemComponent* GetAbilitySystemComponent() const override;
|
||||
|
||||
private:
|
||||
void DeadTagUpdated(FGameplayTag GameplayTag, int32 NewCount);
|
||||
void BindGASChangeDelegate();
|
||||
UPROPERTY(EditDefaultsOnly, Category="Gameplay Ability")
|
||||
TObjectPtr<UCAbilitySystemComponent> CAbilitySystemComponent;
|
||||
UPROPERTY()
|
||||
@@ -54,4 +57,10 @@ private:
|
||||
|
||||
FTimerHandle HeadStatGaugeVisibilityUpdateTimerHandle;
|
||||
void UpdateHeadStatGaugeVisibility();
|
||||
|
||||
/********************************************************************************************/
|
||||
/* Death & Respawning */
|
||||
/********************************************************************************************/
|
||||
void StartDeathSequence();
|
||||
void ReSpawn();
|
||||
};
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
#include "CoreMinimal.h"
|
||||
#include "AbilitySystemComponent.h"
|
||||
#include "GameplayEffectTypes.h"
|
||||
|
||||
#include "CAbilitySystemComponent.generated.h"
|
||||
|
||||
@@ -15,13 +16,18 @@ class CRUNCH_API UCAbilitySystemComponent : public UAbilitySystemComponent
|
||||
GENERATED_BODY()
|
||||
|
||||
public:
|
||||
UCAbilitySystemComponent();
|
||||
void ApplyInitialEffects();
|
||||
void GiveInitialAbilities();
|
||||
void HealthUpdated(const FOnAttributeChangeData& ChangeData);
|
||||
|
||||
private:
|
||||
UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects")
|
||||
TArray<TSubclassOf<UGameplayEffect>> InitialEffects;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category="Gameplay Effects")
|
||||
TSubclassOf<UGameplayEffect> DeathEffectClass;
|
||||
|
||||
UPROPERTY(EditDefaultsOnly, Category="Gameplay Ability")
|
||||
TMap<ECAbilityInputID, TSubclassOf<UGameplayAbility>> Abilities;
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ class UCAbilitySystemStatics: public UObject
|
||||
GENERATED_BODY()
|
||||
public:
|
||||
static FGameplayTag GetBasicAttackAbilityTag();
|
||||
static FGameplayTag GetDeadStatTag();
|
||||
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user