[박치영] Boss UI 이슈 해결

생성을 C++에서 BP로 옮김
main
PCYPC\pcy35 2023-09-04 16:05:07 +09:00
parent be066a599f
commit d749211174
11 changed files with 13 additions and 84 deletions

View File

@ -50,30 +50,12 @@ ABossEnemy::ABossEnemy()
void ABossEnemy::BeginPlay()
{
//Blueprint에서 UMG 생성
Super::BeginPlay();
MainWeaponCollisionComponent->SetCollisionMeshComponent(WeaponMeshComponent);
MainWeaponCollisionComponent->AddActorToIgnore(this);
APlayerController* playerController = UGameplayStatics::GetPlayerController(GetWorld(), 0);
if(!playerController)
return;
UWorld* World = GetWorld();
if (World)
{
APlayerController* Contorller = World->GetFirstPlayerController();
if(!Controller) //TODO : 임시
{
UUI_BossHealth* BossHealthRef = CreateWidget<UUI_BossHealth>(Contorller, UUI_BossHealth::StaticClass());
if (BossHealthRef) //ExposeOnSpawn 대용으로 사용
{
BossHealthWidget = BossHealthRef;
BossHealthRef->AddToViewport();
BossHealthWidget->InitializeWidget(StatsComponent);
}
}
}
}
void ABossEnemy::OnTargetSet(AActor* NewTarget)

View File

@ -49,5 +49,8 @@ private:
FName WeaponHandSocketName;
UPROPERTY(VisibleAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess="true"))
TObjectPtr<class UUI_BossHealth> BossHealthWidget;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(AllowPrivateAccess="true"))
TSubclassOf<class UUI_BossHealth> BossHealthClass;
};

View File

@ -77,7 +77,8 @@ AMasterAI::AMasterAI()
StatsComponent->SetMaxStatValue(EStats::Armor, 100.f);
StatsComponent->SetBaseStatValue(EStats::Damage, 25.f);
StatsComponent->SetMaxStatValue(EStats::Damage, 300.f);
StatsComponent->InitializeStats();
// Setting MainWeaponCollisionComponent
// Setting OnHit Func is Child Class
MainWeaponCollisionComponent = CreateDefaultSubobject<UCollisionComponent>(TEXT("CollisionComponent"));
@ -100,10 +101,12 @@ AMasterAI::AMasterAI()
void AMasterAI::BeginPlay()
{
// Call the base class
Super::BeginPlay();
StatsComponent->InitializeStats();
Super::BeginPlay();
// BP의 BeginPlay가 먼저 호출됨 (ReceiveBeginPlay)
// 따라서 생성자로 올림
//StatsComponent->InitializeStats();
}
float AMasterAI::TakeDamage(float Damage, FDamageEvent const& DamageEvent, AController* EventInstigator, AActor* DamageCauser)

View File

@ -1,32 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#include "UI/UI_BossHealth.h"
#include "UI_HealthBar.h"
#include "Components/StatsComponent.h"
#include "Components/TextBlock.h"
void UUI_BossHealth::NativeConstruct()
{
/*
* TODO :
* Blueprint
* C++ nullptr
*/
Super::NativeConstruct();
HealthBar = Cast<UUI_HealthBar>(GetWidgetFromName(TEXT("HealthBarWidget")));
if(HealthBar)
//HealthBar->InitializeHealthBar(StatsComponent, EStats::Health);
Test1 = Cast<UTextBlock>(GetWidgetFromName(TEXT("Test1Widget")));
Test2 = Cast<UTextBlock>(GetWidgetFromName(TEXT("Test2Widget")));
// ensure(Test1);
// ensure(Test2);
}
void UUI_BossHealth::InitializeWidget(UStatsComponent* InputStatsComponent)
{
if(IsValid(InputStatsComponent))
StatsComponent = InputStatsComponent;
}

View File

@ -1,28 +0,0 @@
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "CoreMinimal.h"
#include "Blueprint/UserWidget.h"
#include "UI_BossHealth.generated.h"
/**
*
*/
UCLASS()
class D1_API UUI_BossHealth : public UUserWidget
{
GENERATED_BODY()
public:
virtual void NativeConstruct() override;
void InitializeWidget(class UStatsComponent* InputStatsComponent);
private:
UPROPERTY()
TObjectPtr<class UUI_HealthBar> HealthBar;
UPROPERTY()
TObjectPtr<class UTextBlock> Test1;
UPROPERTY()
TObjectPtr<class UTextBlock> Test2;
UPROPERTY()
TObjectPtr<class UStatsComponent> StatsComponent;
};

View File

@ -30,6 +30,7 @@ private:
bool bUsePlayerStatsComponent;
public:
UFUNCTION(BlueprintCallable)
void InitializeHealthBar(UStatsComponent* InputStatsComponent, EStats InputStatType);
public: