FString sound_path = data.Sound;
FSoftObjectPath path;
path.SetPath(sound_path);
TSoftObjectPtr<USoundCue> sound;
if (path.IsValid())
sound = Cast<USoundCue>(path.ResolveObject());
TArray<FSoftObjectPath> Assets;
Assets.AddUnique(path);
ACharacter* host = UFLCharacterHelp::GetHostCharacter(GetWorld());
URAsyncLoader::GetInstancePtr()->LoadAsyncResource(Assets, FStreamableDelegate::CreateLambda([=] {
UGameplayStatics::PlaySoundAtLocation(host, sound.Get(), host->GetCapsuleComponent()->GetComponentLocation());
}));
void URAsyncLoader::LoadAsyncResource(TArray<FSoftObjectPath> Assets, FStreamableDelegate Callback)
{
TArray<FSoftObjectPath> AsyncAsset;
AsyncAsset.Reset(Assets.Num());
for (FSoftObjectPath& objectPath : Assets)
{
if (!mAssets.Contains(objectPath) && !objectPath.IsNull() && !objectPath.IsSubobject())
{
AsyncAsset.AddUnique(objectPath);
mAssets.AddUnique(objectPath);
}
}
if (AsyncAsset.Num() > 0)
{
GetInstancePtr()->_StreamableManager.RequestAsyncLoad(AsyncAsset, Callback);
}
else
{
Callback.ExecuteIfBound();
}
}
还没有评论,来说两句吧...