Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "FooActor42.h"
- #include "MyFooActor.h"
- AMyFooActor::AMyFooActor(const class FPostConstructInitializeProperties& PCIP)
- : Super(PCIP)
- {
- Box = PCIP.CreateDefaultSubobject<UBoxComponent>(this, TEXT("box"));
- sw = (USoundWave*)StaticConstructObject(USoundWave::StaticClass(), this, TEXT("MyTestSoundWave"));
- ac = PCIP.CreateDefaultSubobject<UAudioComponent>(this, TEXT("audio component"));
- sw->SoundGroup = ESoundGroup::SOUNDGROUP_Music;
- ac->bIsMusic = true;
- ac->bAutoActivate = false;
- loaded = FFileHelper::LoadFileToArray(rawFile, TEXT("D:\\my song.ogg"));
- Box->bGenerateOverlapEvents = true;
- Box->SetRelativeScale3D(FVector(5, 5, 5));
- if (loaded){
- Debug("loaded");
- FByteBulkData* bulkData = &sw->CompressedFormatData.GetFormat(TEXT("OGG"));
- bulkData->Lock(LOCK_READ_WRITE);
- FMemory::Memcpy(bulkData->Realloc(rawFile.Num()), rawFile.GetTypedData(), rawFile.Num());
- bulkData->Unlock();
- Debug("size: " + FString::FromInt(bulkData->GetBulkDataSize()));
- Debug("sw volume: " + FString::SanitizeFloat(sw->Volume) + " duration: " + FString::SanitizeFloat(sw->GetDuration()));
- Debug("sw MaxConcurrentPlayCount: " + FString::FromInt(sw->MaxConcurrentPlayCount) + " numchannels: " + FString::FromInt(sw->NumChannels));
- //volume 1.0 - duration 0.0 - NumChannels 0
- //FIXME need to find a way to set these parameters
- //sw->Duration = 10.0f;
- sw->NumChannels = 2;
- //Debug("sw detailed info: " + sw->GetDetailedInfo());
- ac->SetSound(sw);
- //Debug("ac detailed info: " + ac->GetDetailedInfo());
- }
- RootComponent = Box;
- Box->OnComponentBeginOverlap.AddDynamic(this, &AMyFooActor::TriggerEnter);
- Box->OnComponentEndOverlap.AddDynamic(this, &AMyFooActor::TriggerExit);
- }
- void AMyFooActor::TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
- {
- Debug("trigger enter");
- if (loaded){
- ac->Play();
- }
- }
- void AMyFooActor::TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)
- {
- ac->Stop();
- Debug("trigger exit");
- }
- void AMyFooActor::Debug(FString msg){
- if (GEngine){
- GEngine->AddOnScreenDebugMessage(-1, 1, FColor::Red, msg);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement