RealtimeStyleTransferRuntime/Plugins/CommonGame/Source/Private/GameUIManagerSubsystem.cpp

80 lines
1.9 KiB
C++
Raw Permalink Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "GameUIManagerSubsystem.h"
2022-09-13 07:18:28 +00:00
#include "Containers/Array.h"
#include "Engine/GameInstance.h"
2022-05-23 18:41:30 +00:00
#include "GameUIPolicy.h"
2022-09-13 07:18:28 +00:00
#include "Misc/AssertionMacros.h"
#include "Templates/Casts.h"
#include "Templates/SubclassOf.h"
#include "UObject/Object.h"
2022-05-23 18:41:30 +00:00
#include "UObject/UObjectHash.h"
2022-09-13 07:18:28 +00:00
class FSubsystemCollectionBase;
class UClass;
2022-05-23 18:41:30 +00:00
void UGameUIManagerSubsystem::Initialize(FSubsystemCollectionBase& Collection)
{
Super::Initialize(Collection);
if (!CurrentPolicy && !DefaultUIPolicyClass.IsNull())
{
TSubclassOf<UGameUIPolicy> PolicyClass = DefaultUIPolicyClass.LoadSynchronous();
SwitchToPolicy(NewObject<UGameUIPolicy>(this, PolicyClass));
}
}
void UGameUIManagerSubsystem::Deinitialize()
{
Super::Deinitialize();
SwitchToPolicy(nullptr);
}
bool UGameUIManagerSubsystem::ShouldCreateSubsystem(UObject* Outer) const
{
if (!CastChecked<UGameInstance>(Outer)->IsDedicatedServerInstance())
{
TArray<UClass*> ChildClasses;
GetDerivedClasses(GetClass(), ChildClasses, false);
// Only create an instance if there is no override implementation defined elsewhere
return ChildClasses.Num() == 0;
}
return false;
}
void UGameUIManagerSubsystem::NotifyPlayerAdded(UCommonLocalPlayer* LocalPlayer)
{
if (ensure(LocalPlayer) && CurrentPolicy)
{
CurrentPolicy->NotifyPlayerAdded(LocalPlayer);
}
}
void UGameUIManagerSubsystem::NotifyPlayerRemoved(UCommonLocalPlayer* LocalPlayer)
{
if (LocalPlayer && CurrentPolicy)
{
CurrentPolicy->NotifyPlayerRemoved(LocalPlayer);
}
}
void UGameUIManagerSubsystem::NotifyPlayerDestroyed(UCommonLocalPlayer* LocalPlayer)
{
if (LocalPlayer && CurrentPolicy)
{
CurrentPolicy->NotifyPlayerDestroyed(LocalPlayer);
}
}
void UGameUIManagerSubsystem::SwitchToPolicy(UGameUIPolicy* InPolicy)
{
if (CurrentPolicy != InPolicy)
{
CurrentPolicy = InPolicy;
}
}