void FSlateSoundDevice::PlaySound(const FSlateSound& Sound, int32 UserIndex) const
{
	if( GEngine && Sound.GetResourceObject() != nullptr )
	{
		FAudioDevice* const AudioDevice = GEngine->GetActiveAudioDevice();
		if(AudioDevice)
		{
			UObject* const Object = Sound.GetResourceObject();
			USoundBase* const SoundResource = Cast<USoundBase>(Object);
			if(SoundResource)
			{
				FActiveSound NewActiveSound;
				NewActiveSound.Sound = SoundResource;
				NewActiveSound.bIsUISound = true;
				NewActiveSound.UserIndex = UserIndex;

				AudioDevice->AddNewActiveSound(NewActiveSound);
			}
			else if(Object)
			{
				// An Object but no SoundResource means that the FSlateSound is holding an invalid object; report that as an error
				UE_LOG(LogSlateSoundDevice, Error, TEXT("A sound contains a non-sound resource '%s'"), *Object->GetName());
			}
		}
	}
}
Beispiel #2
0
void UUserWidget::PlaySound(USoundBase* SoundToPlay)
{
	if (SoundToPlay)
	{
		FSlateSound NewSound;
		NewSound.SetResourceObject(SoundToPlay);
		FSlateApplication::Get().PlaySound(NewSound);
	}
}
Beispiel #3
0
FSlateSound FSlateSound::FromName_DEPRECATED( const FName& SoundName )
{
	FSlateSound Sound;

	// Just set the name, the sound will get loaded the first time it's required
	Sound.LegacyResourceName_DEPRECATED = SoundName;

#if WITH_EDITOR
	if (GIsEditor)
	{
		// If we're in the editor, we need to load the sound immediately so that the ResourceObject is valid for editing
		Sound.ResourceObject = Sound.GetResourceObject();
	}
#endif

	return Sound;
}
float FSlateSoundDevice::GetSoundDuration(const FSlateSound& Sound) const
{
	USoundBase* const SoundResource = Cast<USoundBase>(Sound.GetResourceObject());
	return (SoundResource) ? SoundResource->Duration : 0.0f;
}