// Copyright Epic Games, Inc. All Rights Reserved. #include "LyraTeamStatics.h" #include "Containers/Map.h" #include "Containers/UnrealString.h" #include "CoreTypes.h" #include "Engine/Engine.h" #include "Engine/World.h" #include "Logging/LogCategory.h" #include "Logging/LogMacros.h" #include "LyraLogChannels.h" #include "Teams/LyraTeamDisplayAsset.h" #include "Teams/LyraTeamSubsystem.h" #include "Trace/Detail/Channel.h" #include "UObject/Object.h" #include "UObject/ObjectPtr.h" #include "UObject/UObjectBaseUtility.h" class UTexture; ////////////////////////////////////////////////////////////////////// void ULyraTeamStatics::FindTeamFromObject(const UObject* Agent, bool& bIsPartOfTeam, int32& TeamId, ULyraTeamDisplayAsset*& DisplayAsset, bool bLogIfNotSet) { bIsPartOfTeam = false; TeamId = INDEX_NONE; DisplayAsset = nullptr; if (UWorld* World = GEngine->GetWorldFromContextObject(Agent, EGetWorldErrorMode::LogAndReturnNull)) { if (ULyraTeamSubsystem* TeamSubsystem = World->GetSubsystem()) { TeamId = TeamSubsystem->FindTeamFromObject(Agent); if (TeamId != INDEX_NONE) { bIsPartOfTeam = true; DisplayAsset = TeamSubsystem->GetTeamDisplayAsset(TeamId, INDEX_NONE); if ((DisplayAsset == nullptr) && bLogIfNotSet) { UE_LOG(LogLyraTeams, Log, TEXT("FindTeamFromObject(%s) called too early (found team %d but no display asset set yet"), *GetPathNameSafe(Agent), TeamId); } } } else { UE_LOG(LogLyraTeams, Error, TEXT("FindTeamFromObject(%s) failed: Team subsystem does not exist yet"), *GetPathNameSafe(Agent)); } } } ULyraTeamDisplayAsset* ULyraTeamStatics::GetTeamDisplayAsset(const UObject* WorldContextObject, int32 TeamId) { ULyraTeamDisplayAsset* Result = nullptr; if (UWorld* World = GEngine->GetWorldFromContextObject(WorldContextObject, EGetWorldErrorMode::LogAndReturnNull)) { if (ULyraTeamSubsystem* TeamSubsystem = World->GetSubsystem()) { return TeamSubsystem->GetTeamDisplayAsset(TeamId, INDEX_NONE); } } return Result; } float ULyraTeamStatics::GetTeamScalarWithFallback(ULyraTeamDisplayAsset* DisplayAsset, FName ParameterName, float DefaultValue) { if (DisplayAsset) { if (float* pValue = DisplayAsset->ScalarParameters.Find(ParameterName)) { return *pValue; } } return DefaultValue; } FLinearColor ULyraTeamStatics::GetTeamColorWithFallback(ULyraTeamDisplayAsset* DisplayAsset, FName ParameterName, FLinearColor DefaultValue) { if (DisplayAsset) { if (FLinearColor* pColor = DisplayAsset->ColorParameters.Find(ParameterName)) { return *pColor; } } return DefaultValue; } UTexture* ULyraTeamStatics::GetTeamTextureWithFallback(ULyraTeamDisplayAsset* DisplayAsset, FName ParameterName, UTexture* DefaultValue) { if (DisplayAsset) { if (TObjectPtr* pTexture = DisplayAsset->TextureParameters.Find(ParameterName)) { return *pTexture; } } return DefaultValue; }