Skip to content
Snippets Groups Projects
Commit 6b484073 authored by Sebastian Pape's avatar Sebastian Pape
Browse files

Added dynamic spawning behavior of overlay, which can be adjusted in the settings of the project

parent 6418ac3a
Branches
No related tags found
2 merge requests!13Develop,!12Feature/dynamic spawning of overlay
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
#include "CAVEOverlay.h"
#include "CAVEOverlaySettings.h"
#include "CAVEOverlayController.h"
#include "Kismet/GameplayStatics.h"
#define LOCTEXT_NAMESPACE "FCAVEOverlayModule"
void FCAVEOverlayModule::StartupModule()
{
// This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
On_Post_World_Initialization_Delegate.BindRaw(this, &FCAVEOverlayModule::OnSessionStart);
FWorldDelegates::OnPostWorldInitialization.Add(On_Post_World_Initialization_Delegate);
}
void FCAVEOverlayModule::OnSessionStart(UWorld* World, const UWorld::InitializationValues)
{
if (!World->IsGameWorld())
return;
const UCAVEOverlaySettings* Settings = GetDefault<UCAVEOverlaySettings>();
//Test if already in
TArray<AActor*> Actors;
UGameplayStatics::GetAllActorsOfClass(World, ACAVEOverlayController::StaticClass(), Actors);
if((Settings->DefaultActivationType == DefaultActivationType_ON
^ Settings->excludedMaps.ContainsByPredicate(
[World](const FSoftObjectPath& Map) {return Map.GetAssetName() == World->GetName();}
)) && Actors.Num() == 0){
World->SpawnActor(ACAVEOverlayController::StaticClass());
}
}
void FCAVEOverlayModule::ShutdownModule()
{
// This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
......@@ -17,4 +43,4 @@ void FCAVEOverlayModule::ShutdownModule()
#undef LOCTEXT_NAMESPACE
IMPLEMENT_MODULE(FCAVEOverlayModule, CAVEOverlay)
\ No newline at end of file
IMPLEMENT_MODULE(FCAVEOverlayModule, CAVEOverlay)
......@@ -4,6 +4,7 @@
#include "CoreMinimal.h"
#include "Modules/ModuleManager.h"
#include "Engine/World.h"
class FCAVEOverlayModule : public IModuleInterface
{
......@@ -12,4 +13,7 @@ public:
/** IModuleInterface implementation */
virtual void StartupModule() override;
virtual void ShutdownModule() override;
private:
TBaseDelegate<void, UWorld*, const UWorld::InitializationValues> On_Post_World_Initialization_Delegate;
void OnSessionStart(UWorld* World, UWorld::InitializationValues);
};
#pragma once
#include "CoreMinimal.h"
#include "Engine/EngineTypes.h"
#include "Engine/DeveloperSettings.h"
#include "CAVEOverlaySettings.generated.h"
UENUM(BlueprintType)
enum DefaultActivationType
{
DefaultActivationType_OFF UMETA(DisplayName = "Off by default"),
DefaultActivationType_ON UMETA(DisplayName = "On by default")
};
UCLASS(config=Game, defaultconfig, meta=(DisplayName="CAVE Overlay"))
class UCAVEOverlaySettings : public UDeveloperSettings
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, config, Category = "General", meta = (DisplayName = "Default Activation Type"))
TEnumAsByte<DefaultActivationType> DefaultActivationType = DefaultActivationType_ON;
UPROPERTY(EditAnywhere, config, Category = Maps, meta=(AllowedClasses="World"))
TArray<FSoftObjectPath> excludedMaps;
};
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment