mirror of
https://github.com/storytold/ActorSpawningPlugin.git
synced 2026-10-09 00:09:44 +00:00
billboards for sound actor
This commit is contained in:
@@ -2,12 +2,18 @@
|
|||||||
|
|
||||||
#include "UObject/Object.h"
|
#include "UObject/Object.h"
|
||||||
#include "Kismet/GameplayStatics.h"
|
#include "Kismet/GameplayStatics.h"
|
||||||
|
#include "Components/BillboardComponent.h"
|
||||||
|
|
||||||
DEFINE_LOG_CATEGORY(SoundSpawnActorLog);
|
DEFINE_LOG_CATEGORY(SoundSpawnActorLog);
|
||||||
|
|
||||||
ASoundSpawnActor::ASoundSpawnActor()
|
ASoundSpawnActor::ASoundSpawnActor(const FObjectInitializer& ObjectInitializer) :
|
||||||
|
Super(ObjectInitializer),
|
||||||
|
BillboardComponent(nullptr)
|
||||||
{
|
{
|
||||||
UE_LOG(SoundSpawnActorLog, Log, TEXT("CTOR()"));
|
UE_LOG(SoundSpawnActorLog, Log, TEXT("CTOR()"));
|
||||||
|
|
||||||
|
BillboardComponent = CreateDefaultSubobject<UBillboardComponent>(TEXT("Billboard"));
|
||||||
|
BillboardComponent->SetupAttachment(RootComponent);
|
||||||
}
|
}
|
||||||
|
|
||||||
ASoundSpawnActor::~ASoundSpawnActor()
|
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!
|
// TODO(bt): Put this in front of the camera, or on the (camera -> player) arc!
|
||||||
float x = FMath::RandRange(-1000.0f, 1000.0f);
|
float x = FMath::RandRange(-1000.0f, 1000.0f);
|
||||||
float y = 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(
|
FVector location(
|
||||||
playerLocation.X + x,
|
playerLocation.X + x,
|
||||||
@@ -132,6 +132,13 @@ ASoundSpawnActor* ASpawningActor::SpawnSoundActor(USoundBase* sound)
|
|||||||
return actor;
|
return actor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ASoundSpawnActor* ASpawningActor::SpawnSoundActorWithText(USoundBase* sound, const FString& text)
|
||||||
|
{
|
||||||
|
ASoundSpawnActor* actor = SpawnSoundActor(sound);
|
||||||
|
|
||||||
|
return actor;
|
||||||
|
}
|
||||||
|
|
||||||
FVector ASpawningActor::LookupPlayerLocation()
|
FVector ASpawningActor::LookupPlayerLocation()
|
||||||
{
|
{
|
||||||
return GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
|
return GetWorld()->GetFirstPlayerController()->GetPawn()->GetActorLocation();
|
||||||
|
|||||||
@@ -17,13 +17,21 @@ class ACTORSPAWNINGPLUGIN_API ASoundSpawnActor : public AActor
|
|||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
ASoundSpawnActor();
|
ASoundSpawnActor(const FObjectInitializer& ObjectInitializer);
|
||||||
~ASoundSpawnActor();
|
~ASoundSpawnActor();
|
||||||
|
|
||||||
|
/** Access to the optional billboard component */
|
||||||
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SoundSpawnActor")
|
||||||
|
class UBillboardComponent* BillboardComponent;
|
||||||
|
|
||||||
/** Set the sound. */
|
/** Set the sound. */
|
||||||
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
|
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
|
||||||
void SetSound(USoundBase* sound);
|
void SetSound(USoundBase* sound);
|
||||||
|
|
||||||
|
/** Set a sprite. */
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "SoundSpawnActor")
|
||||||
|
void SetSprite(UTexture2D* sprite);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
// Called when the game starts or when spawned
|
// Called when the game starts or when spawned
|
||||||
virtual void BeginPlay() override;
|
virtual void BeginPlay() override;
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ public:
|
|||||||
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||||
ASoundSpawnActor* SpawnSoundActor(USoundBase* sound);
|
ASoundSpawnActor* SpawnSoundActor(USoundBase* sound);
|
||||||
|
|
||||||
|
/** Create sound actor with text. */
|
||||||
|
UFUNCTION(BlueprintCallable, Category = "SpawningActor")
|
||||||
|
ASoundSpawnActor* SpawnSoundActorWithText(USoundBase* sound, const FString& text);
|
||||||
|
|
||||||
/** Mesh to use */
|
/** Mesh to use */
|
||||||
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
|
UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category = "SpawningActor", meta = (AllowPrivateAccess = "true"))
|
||||||
class UStaticMeshComponent* BaseMesh;
|
class UStaticMeshComponent* BaseMesh;
|
||||||
|
|||||||
Reference in New Issue
Block a user