You've already forked UnrealEngineUWP
mirror of
https://github.com/izzy2lost/UnrealEngineUWP.git
synced 2026-03-26 18:15:20 -07:00
99 lines
2.4 KiB
C++
99 lines
2.4 KiB
C++
// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
|
|
|
|
#include "EditorUtilitySubsystem.h"
|
|
#include "EditorUtilityCommon.h"
|
|
#include "Interfaces/IMainFrameModule.h"
|
|
#include "Engine/Blueprint.h"
|
|
#include "ScopedTransaction.h"
|
|
|
|
UEditorUtilitySubsystem::UEditorUtilitySubsystem() :
|
|
UEditorSubsystem()
|
|
{
|
|
|
|
}
|
|
|
|
void UEditorUtilitySubsystem::Initialize(FSubsystemCollectionBase& Collection)
|
|
{
|
|
IMainFrameModule& MainFrameModule = IMainFrameModule::Get();
|
|
if (MainFrameModule.IsWindowInitialized())
|
|
{
|
|
HandleStartup();
|
|
}
|
|
else
|
|
{
|
|
MainFrameModule.OnMainFrameCreationFinished().AddUObject(this, &UEditorUtilitySubsystem::MainFrameCreationFinished);
|
|
}
|
|
}
|
|
|
|
void UEditorUtilitySubsystem::Deinitialize()
|
|
{
|
|
if (FModuleManager::Get().IsModuleLoaded("MainFrame"))
|
|
{
|
|
IMainFrameModule::Get().OnMainFrameCreationFinished().RemoveAll(this);
|
|
}
|
|
}
|
|
|
|
void UEditorUtilitySubsystem::MainFrameCreationFinished(TSharedPtr<SWindow> InRootWindow, bool bIsNewProjectWindow)
|
|
{
|
|
HandleStartup();
|
|
}
|
|
|
|
void UEditorUtilitySubsystem::HandleStartup()
|
|
{
|
|
for (const FSoftObjectPath& ObjectPath : StartupObjects)
|
|
{
|
|
UObject* Object = ObjectPath.TryLoad();
|
|
if (!Object || Object->IsPendingKillOrUnreachable())
|
|
{
|
|
UE_LOG(LogEditorUtilityBlueprint, Warning, TEXT("Could not load: %s"), *ObjectPath.ToString());
|
|
continue;
|
|
}
|
|
|
|
TryRun(ObjectPath.TryLoad());
|
|
}
|
|
}
|
|
|
|
bool UEditorUtilitySubsystem::TryRun(UObject* Asset)
|
|
{
|
|
if (!Asset || Asset->IsPendingKillOrUnreachable())
|
|
{
|
|
UE_LOG(LogEditorUtilityBlueprint, Warning, TEXT("Could not run: %s"), Asset ? *Asset->GetPathName() : TEXT("None"));
|
|
return false;
|
|
}
|
|
|
|
UClass* ObjectClass = Asset->GetClass();
|
|
if (UBlueprint* Blueprint = Cast<UBlueprint>(Asset))
|
|
{
|
|
ObjectClass = Blueprint->GeneratedClass;
|
|
}
|
|
|
|
if (!ObjectClass)
|
|
{
|
|
UE_LOG(LogEditorUtilityBlueprint, Warning, TEXT("Missing class: %s"), *Asset->GetPathName());
|
|
return false;
|
|
}
|
|
|
|
static const FName RunFunctionName("Run");
|
|
UFunction* RunFunction = ObjectClass->FindFunctionByName(RunFunctionName);
|
|
if (RunFunction)
|
|
{
|
|
UObject* Instance = NewObject<UObject>(this, ObjectClass);
|
|
ObjectInstances.Add(Asset, Instance);
|
|
|
|
FEditorScriptExecutionGuard ScriptGuard;
|
|
Instance->ProcessEvent(RunFunction, nullptr);
|
|
return true;
|
|
}
|
|
else
|
|
{
|
|
UE_LOG(LogEditorUtilityBlueprint, Warning, TEXT("Missing function named 'Run': %s"), *Asset->GetPathName());
|
|
}
|
|
|
|
return false;
|
|
}
|
|
|
|
void UEditorUtilitySubsystem::ReleaseInstanceOfAsset(UObject* Asset)
|
|
{
|
|
ObjectInstances.Remove(Asset);
|
|
}
|