Files
ProjectEleri/Source/ProjectEleri/Components/EleriPaperSpriteComponent.cpp
2026-09-17 20:59:12 +02:00

45 lines
1.3 KiB
C++

// Fill out your copyright notice in the Description page of Project Settings.
#include "EleriPaperSpriteComponent.h"
#include "Components/DecalComponent.h"
void UEleriPaperSpriteComponent::BeginPlay()
{
Super::BeginPlay();
DecalComponent = NewObject<UDecalComponent>(GetOwner(), UDecalComponent::StaticClass(), TEXT("Shadow Decal"));
DecalComponent->DecalSize = DecalSize;
DecalComponent->SetFadeScreenSize(0.f);
DecalComponent->SetupAttachment(GetOwner()->GetRootComponent());
DecalComponent->RegisterComponent();
UpdateRelativeLocation(FVector::ZeroVector);
DecalComponent->SetUsingAbsoluteRotation(true);
DecalComponent->SetRelativeRotation(FRotator(-90.f, 0.f, 0.f));
SetCastShadow(false);
if (DecalMaterial.IsValid())
{
DecalComponent->SetDecalMaterial(DecalMaterial.Get());
}
else
{
DecalMaterial.LoadAsync(FLoadSoftObjectPathAsyncDelegate::CreateWeakLambda(this, [this](const FSoftObjectPath& Path, UObject* MaterialObj)
{
if (UMaterialInterface* Interface = Cast<UMaterialInterface>(MaterialObj))
{
DecalComponent->SetDecalMaterial(Interface);
}
}));
}
}
void UEleriPaperSpriteComponent::UpdateRelativeLocation(const FVector& NewLoc) const
{
DecalComponent->SetRelativeLocation(NewLoc + (DecalOffset - FVector(0.f, 0.f, DecalSize.Z)));
}