29 lines
697 B
C++
29 lines
697 B
C++
// Fill out your copyright notice in the Description page of Project Settings.
|
|
|
|
|
|
#include "UI/UI_StatBar.h"
|
|
#include "Components/ProgressBar.h"
|
|
|
|
void UUI_StatBar::NativeConstruct()
|
|
{
|
|
APawn* pplayer = GetOwningPlayerPawn();
|
|
if (pplayer)
|
|
{
|
|
StatsComponent = pplayer->GetComponentByClass<UStatsComponent>();
|
|
if (IsValid(StatsComponent))
|
|
StatsComponent->OnCurrentStatValueUpdated.AddUObject(this, &UUI_StatBar::StatBarStatValueUpdated);
|
|
}
|
|
}
|
|
|
|
void UUI_StatBar::StatBarStatValueUpdated(EStats stat, float value)
|
|
{
|
|
if (StatType != stat)
|
|
return;
|
|
|
|
if (!IsValid(StatsComponent))
|
|
return;
|
|
|
|
float fPercent = value / StatsComponent->GetMaxStatValue(StatType);
|
|
StatBar->SetPercent(fPercent);
|
|
}
|