|
|
|
|
| #include "LyraSystemStatics.h"
|
| #include "Engine/AssetManagerTypes.h"
|
| #include "Engine/Engine.h"
|
| #include "Engine/World.h"
|
| #include "Engine/AssetManager.h"
|
| #include "LyraLogChannels.h"
|
| #include "Components/MeshComponent.h"
|
| #include "GameModes/LyraUserFacingExperienceDefinition.h"
|
|
|
| #include UE_INLINE_GENERATED_CPP_BY_NAME(LyraSystemStatics)
|
|
|
| TSoftObjectPtr<UObject> ULyraSystemStatics::GetTypedSoftObjectReferenceFromPrimaryAssetId(FPrimaryAssetId PrimaryAssetId, TSubclassOf<UObject> ExpectedAssetType)
|
| {
|
| if (UAssetManager* Manager = UAssetManager::GetIfInitialized())
|
| {
|
| FPrimaryAssetTypeInfo Info;
|
| if (Manager->GetPrimaryAssetTypeInfo(PrimaryAssetId.PrimaryAssetType, Info) && !Info.bHasBlueprintClasses)
|
| {
|
| if (UClass* AssetClass = Info.AssetBaseClassLoaded)
|
| {
|
| if ((ExpectedAssetType == nullptr) || !AssetClass->IsChildOf(ExpectedAssetType))
|
| {
|
| return nullptr;
|
| }
|
| }
|
| else
|
| {
|
| UE_LOG(LogLyra, Warning, TEXT("GetTypedSoftObjectReferenceFromPrimaryAssetId(%s, %s) - AssetBaseClassLoaded was unset so we couldn't validate it, returning null"),
|
| *PrimaryAssetId.ToString(),
|
| *GetPathNameSafe(*ExpectedAssetType));
|
| }
|
|
|
| return TSoftObjectPtr<UObject>(Manager->GetPrimaryAssetPath(PrimaryAssetId));
|
| }
|
| }
|
| return nullptr;
|
| }
|
|
|
| FPrimaryAssetId ULyraSystemStatics::GetPrimaryAssetIdFromUserFacingExperienceName(const FString& AdvertisedExperienceID)
|
| {
|
| const FPrimaryAssetType Type(ULyraUserFacingExperienceDefinition::StaticClass()->GetFName());
|
| return FPrimaryAssetId(Type, FName(*AdvertisedExperienceID));
|
| }
|
|
|
| void ULyraSystemStatics::PlayNextGame(const UObject* WorldContextObject)
|
| {
|
| UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull);
|
| if (World == nullptr)
|
| {
|
| return;
|
| }
|
|
|
| const FWorldContext& WorldContext = GEngine->GetWorldContextFromWorldChecked(World);
|
| FURL LastURL = WorldContext.LastURL;
|
|
|
| #if WITH_EDITOR
|
|
|
| LastURL.Map = UWorld::StripPIEPrefixFromPackageName(LastURL.Map, WorldContext.World()->StreamingLevelsPrefix);
|
| #endif
|
|
|
|
|
| LastURL.AddOption(TEXT("SeamlessTravel"));
|
|
|
| FString URL = LastURL.ToString();
|
|
|
| URL.RemoveFromStart(LastURL.GetHostPortString());
|
|
|
| const bool bAbsolute = false;
|
| const bool bShouldSkipGameNotify = false;
|
| World->ServerTravel(URL, bAbsolute, bShouldSkipGameNotify);
|
| }
|
|
|
| void ULyraSystemStatics::SetScalarParameterValueOnAllMeshComponents(AActor* TargetActor, const FName ParameterName, const float ParameterValue, bool bIncludeChildActors)
|
| {
|
| if (TargetActor != nullptr)
|
| {
|
| TargetActor->ForEachComponent<UMeshComponent>(bIncludeChildActors, [=](UMeshComponent* InComponent)
|
| {
|
| InComponent->SetScalarParameterValueOnMaterials(ParameterName, ParameterValue);
|
| });
|
| }
|
| }
|
|
|
| void ULyraSystemStatics::SetVectorParameterValueOnAllMeshComponents(AActor* TargetActor, const FName ParameterName, const FVector ParameterValue, bool bIncludeChildActors)
|
| {
|
| if (TargetActor != nullptr)
|
| {
|
| TargetActor->ForEachComponent<UMeshComponent>(bIncludeChildActors, [=](UMeshComponent* InComponent)
|
| {
|
| InComponent->SetVectorParameterValueOnMaterials(ParameterName, ParameterValue);
|
| });
|
| }
|
| }
|
|
|
| void ULyraSystemStatics::SetColorParameterValueOnAllMeshComponents(AActor* TargetActor, const FName ParameterName, const FLinearColor ParameterValue, bool bIncludeChildActors)
|
| {
|
| SetVectorParameterValueOnAllMeshComponents(TargetActor, ParameterName, FVector(ParameterValue), bIncludeChildActors);
|
| }
|
|
|
| TArray<UActorComponent*> ULyraSystemStatics::FindComponentsByClass(AActor* TargetActor, TSubclassOf<UActorComponent> ComponentClass, bool bIncludeChildActors)
|
| {
|
| TArray<UActorComponent*> Components;
|
| if (TargetActor != nullptr)
|
| {
|
| TargetActor->GetComponents(ComponentClass, Components, bIncludeChildActors);
|
|
|
| }
|
| return MoveTemp(Components);
|
| }
|
|
|
|
|