diff --git a/Source/ActorSpawningPlugin/Private/SoundSpawnActor.cpp b/Source/ActorSpawningPlugin/Private/SoundSpawnActor.cpp index 46e66cb..b5a43e7 100644 --- a/Source/ActorSpawningPlugin/Private/SoundSpawnActor.cpp +++ b/Source/ActorSpawningPlugin/Private/SoundSpawnActor.cpp @@ -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(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! :( +} + diff --git a/Source/ActorSpawningPlugin/Private/SpawningActor.cpp b/Source/ActorSpawningPlugin/Private/SpawningActor.cpp index e3a8a2c..9ea2778 100644 --- a/Source/ActorSpawningPlugin/Private/SpawningActor.cpp +++ b/Source/ActorSpawningPlugin/Private/SpawningActor.cpp @@ -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(); diff --git a/Source/ActorSpawningPlugin/Public/SoundSpawnActor.h b/Source/ActorSpawningPlugin/Public/SoundSpawnActor.h index 154c242..6073257 100644 --- a/Source/ActorSpawningPlugin/Public/SoundSpawnActor.h +++ b/Source/ActorSpawningPlugin/Public/SoundSpawnActor.h @@ -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; diff --git a/Source/ActorSpawningPlugin/Public/SpawningActor.h b/Source/ActorSpawningPlugin/Public/SpawningActor.h index 8de51a2..919b277 100644 --- a/Source/ActorSpawningPlugin/Public/SpawningActor.h +++ b/Source/ActorSpawningPlugin/Public/SpawningActor.h @@ -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;