48 lines
1.5 KiB
C++
48 lines
1.5 KiB
C++
// Copyright Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "GameFeatureAction_WorldActionBase.h"
|
|
|
|
#include "Containers/Array.h"
|
|
#include "Containers/IndirectArray.h"
|
|
#include "Delegates/Delegate.h"
|
|
#include "Engine/Engine.h"
|
|
#include "Engine/GameInstance.h"
|
|
#include "Engine/World.h"
|
|
#include "GameFeaturesSubsystem.h"
|
|
|
|
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);
|
|
}
|
|
}
|
|
}
|