billboards for sound actor

This commit is contained in:
Brandon Thomas
2021-03-07 06:30:08 -05:00
parent f55152f91f
commit 966fe66ec0
4 changed files with 35 additions and 3 deletions
@@ -2,12 +2,18 @@
#include "UObject/Object.h"
#include "Kismet/GameplayStatics.h"
#include "Components/BillboardComponent.h"
DEFINE_LOG_CATEGORY(SoundSpawnActorLog);
ASoundSpawnActor::ASoundSpawnActor()
ASoundSpawnActor::ASoundSpawnActor(const FObjectInitializer& ObjectInitializer) :
Super(ObjectInitializer),
BillboardComponent(nullptr)
{
UE_LOG(SoundSpawnActorLog, Log, TEXT("CTOR()"));
BillboardComponent = CreateDefaultSubobject<UBillboardComponent>(TEXT("Billboard"));
BillboardComponent->SetupAttachment(RootComponent);
}
ASoundSpawnActor::~ASoundSpawnActor()
@@ -37,3 +43,10 @@ void ASoundSpawnActor::SetSound(USoundBase* sound)
);
}
void ASoundSpawnActor::SetSprite(UTexture2D* sprite)
{
BillboardComponent->SetSprite(sprite);
BillboardComponent->RegisterComponent();
BillboardComponent->bHiddenInGame = false; // NB: This defaults to true! :(
}
@@ -108,7 +108,7 @@ ASoundSpawnActor* ASpawningActor::SpawnSoundActor(USoundBase* sound)
// TODO(bt): Put this in front of the camera, or on the (camera -> player) arc!
float x = FMath::RandRange(-1000.0f, 1000.0f);
float y = FMath::RandRange(-1000.0f, 1000.0f);
float z = FMath::RandRange(1000.0f, 1000.0f);
float z = FMath::RandRange(50.0f, 50.0f);
FVector location(
playerLocation.X + x,
@@ -132,6 +132,13 @@ ASoundSpawnActor* ASpawningActor::SpawnSoundActor(USoundBase* sound)
return actor;
}
ASoundSpawnActor* ASpawningActor::SpawnSoundActorWithText(USoundBase* sound, const FString& text)
{
ASoundSpawnActor* actor = SpawnSoundActor(sound);
return actor;
}
FVector ASpawningActor::LookupPlayerLocation()
{
return GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
@@ -17,13 +17,21 @@ class ACTORSPAWNINGPLUGIN_API ASoundSpawnActor : public AActor
public:
ASoundSpawnActor();
ASoundSpawnActor(const FObjectInitializer& ObjectInitializer);
~ASoundSpawnActor();
/** Access to the optional billboard component */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SoundSpawnActor")
class UBillboardComponent* BillboardComponent;
/** Set the sound. */
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
void SetSound(USoundBase* sound);
/** Set a sprite. */
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
void SetSprite(UTexture2D* sprite);
protected:
// Called when the game starts or when spawned
virtual void BeginPlay() override;
@@ -36,6 +36,10 @@ public:
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
ASoundSpawnActor* SpawnSoundActor(USoundBase* sound);
/** Create sound actor with text. */
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
ASoundSpawnActor* SpawnSoundActorWithText(USoundBase* sound, const FString& text);
/** Mesh to use */
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
class UStaticMeshComponent* BaseMesh;