RealtimeStyleTransferRuntime/Source/LyraGame/GameFeatures/GameFeatureAction_WorldActi...

48 lines
1.5 KiB
C++
Raw Normal View History

2022-05-23 18:41:30 +00:00
// Copyright Epic Games, Inc. All Rights Reserved.
#include "GameFeatureAction_WorldActionBase.h"
2022-09-13 07:18:28 +00:00
#include "Containers/Array.h"
#include "Containers/IndirectArray.h"
#include "Delegates/Delegate.h"
2022-05-23 18:41:30 +00:00
#include "Engine/Engine.h"
2022-09-13 07:18:28 +00:00
#include "Engine/GameInstance.h"
#include "Engine/World.h"
#include "GameFeaturesSubsystem.h"
2022-05-23 18:41:30 +00:00
void UGameFeatureAction_WorldActionBase::OnGameFeatureActivating(FGameFeatureActivatingContext& Context)
{
GameInstanceStartHandles.FindOrAdd(Context) = FWorldDelegates::OnStartGameInstance.AddUObject(this,
&UGameFeatureAction_WorldActionBase::HandleGameInstanceStart, FGameFeatureStateChangeContext(Context));
// Add to any worlds with associated game instances that have already been initialized
for (const FWorldContext& WorldContext : GEngine->GetWorldContexts())
{
if (Context.ShouldApplyToWorldContext(WorldContext))
{
AddToWorld(WorldContext, Context);
}
}
}
void UGameFeatureAction_WorldActionBase::OnGameFeatureDeactivating(FGameFeatureDeactivatingContext& Context)
{
FDelegateHandle* FoundHandle = GameInstanceStartHandles.Find(Context);
if (ensure(FoundHandle))
{
FWorldDelegates::OnStartGameInstance.Remove(*FoundHandle);
}
}
void UGameFeatureAction_WorldActionBase::HandleGameInstanceStart(UGameInstance* GameInstance, FGameFeatureStateChangeContext ChangeContext)
{
if (FWorldContext* WorldContext = GameInstance->GetWorldContext())
{
if (ChangeContext.ShouldApplyToWorldContext(*WorldContext))
{
AddToWorld(*WorldContext, ChangeContext);
}
}
}