Re: BaseAudioTrigger.cpp

From Kieran McEvaddy, 2 Months ago, written in C++, viewed 91 times. This paste is a reply to BaseAudioTrigger.cpp from Kieran McEvaddy - go back
URL http://codebin.org/view/213c521b/diff Embed
Viewing differences between BaseAudioTrigger.cpp and Re: BaseAudioTrigger.cpp
// Fill out your copyright notice in the Description page of Project Settings.

#include "BaseAudioTrigger.h"
#include "Components/AudioComponent.h"
#include "Components/SphereComponent.h"
#include "ConstructorHelpers.h"
#include "Kismet/GameplayStatics.h"
#include "Sound/SoundCue.h"

// Sets default values
ABaseAudioTrigger::ABaseAudioTrigger()
{
         // Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
        //PrimaryActorTick.bCanEverTick = true;

        /*Sphere Trigger*/
        SphereTrigger = CreateDefaultSubobject<USphereComponent>(TEXT("Sphere Trigger"));
        if( SphereTrigger )
        {
                SphereTrigger->InitSphereRadius(50.0f);
                SphereTrigger->SetCollisionProfileName(FName("STCol"));
                SphereTrigger->OnComponentBeginOverlap.AddDynamic(this, &ABaseAudioTrigger::OnOverlapBegin);
                SphereTrigger->SetMobility(EComponentMobility::Static);
        
                RootComponent = SphereTrigger;
        }
        
        /*Audio*/        
        //The cue to play
        CollectedCue = ConstructorHelpers::FObjectFinder<USoundCue>
        (TEXT("SoundCue'/Game/Sounds/Test/Rock_Cue.Rock_Cue'")).Object;
        
        //The container of the cue's logic
        CollectableAudioComponent = CreateDefaultSubobject<UAudioComponent>(TEXT("CollectableAudioComp"));
        if( CollectableAudioComponent )
        {
                CollectableAudioComponent->bAutoActivate = false;
                CollectableAudioComponent->SetupAttachment(RootComponent);
                CollectableAudioComponent->OnAudioFinished.AddDynamic(this, &ABaseAudioTrigger::OnAudioFinished);
        }


}

void ABaseAudioTrigger::PostInitializeComponents()
{
        Super::PostInitializeComponents();

        CollectableAudioComponent->SetSound(CollectedCue);
}

void ABaseAudioTrigger::OnOverlapBegin(UPrimitiveComponent * OverlappedComp, AActor * OtherActor, UPrimitiveComponent * OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult & SweepResult)
{
        if( ( OtherActor != nullptr ) && ( OtherActor != this ) && ( OtherComp != nullptr ) )
        {
                if( !bFinished )
                {
                        bFinished = true;
                        CollectableAudioComponent->Play();
                        
                        UGameplayStatics::SpawnEmitterAttached(
                                ParticleEffect, 
                                RootComponent        
                        );
                }
        }
}

void ABaseAudioTrigger::OnAudioFinished()
{
        Destroy();
}

Replies to Re: BaseAudioTrigger.cpp rss

Title Name Language When
BaseAudioTrigger.cpp Kieran McEvaddy cpp 2 Months ago.

Reply to "Re: BaseAudioTrigger.cpp"

Here you can reply to the paste above