// Copyright Epic Games, Inc. All Rights Reserved. #include "Integration.h" #include "Common.h" #include "Modules/ModuleManager.h" #include "Interfaces/IPluginManager.h" #include "Misc/Paths.h" #include "ShaderCore.h" #if WITH_EDITOR #include "Engine/Blueprint.h" #include "UObject/SavePackage.h" #include "UObject/ObjectSaveContext.h" #include "EdGraph/EdGraph.h" #include "BlueprintExporter.h" #include "Misc/FileHelper.h" #include "Exporters/Exporter.h" #include "UnrealExporter.h" #endif IMPLEMENT_PRIMARY_GAME_MODULE(FlxIntegrationModuleImpl, Integration, "Integration"); void FlxIntegrationModuleImpl::StartupModule() { FString ShaderDir = FPaths::Combine(FPaths::ProjectDir(), TEXT("Shaders")); AddShaderSourceDirectoryMapping(TEXT("/Project/Integration"), ShaderDir); #if WITH_EDITOR OnAssetSavedHandle = UPackage::PackageSavedWithContextEvent.AddRaw( this, &FlxIntegrationModuleImpl::OnAssetSaved); #endif } void FlxIntegrationModuleImpl::ShutdownModule() { #if WITH_EDITOR UPackage::PackageSavedWithContextEvent.Remove(OnAssetSavedHandle); #endif } #if WITH_EDITOR void FlxIntegrationModuleImpl::OnAssetSaved(const FString& PackageFilename, UPackage* Package, FObjectPostSaveContext Context) { if (!Package) return; FString PkDir = FPaths::ProjectDir() / TEXT("Saved") / TEXT("BlueprintExports") / FPaths::GetBaseFilename(PackageFilename); IFileManager::Get().DeleteDirectory(*PkDir, false, true); // Export the whole package in both formats for comparison. { FStringOutputDevice Archive; const FExportObjectInnerContext InnerContext; UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("copy"), 0); FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("COPY_DUMP.txt"))); } { FStringOutputDevice Archive; const FExportObjectInnerContext InnerContext; UExporter::ExportToOutputDevice(&InnerContext, Package, nullptr, Archive, TEXT("t3d"), 0); FFileHelper::SaveStringToFile(Archive, *(PkDir / TEXT("T3D_DUMP.txt"))); } TArray AllObjects; GetObjectsWithPackage(Package, AllObjects); for (UObject *Obj : AllObjects) { if (UBlueprint *BP = Cast(Obj)) { FString BPDir = PkDir / BP->GetName(); TArray AllGraphs; BP->GetAllGraphs(AllGraphs); for (UEdGraph* Graph : AllGraphs) { FlxBlueprintExporter Exporter(Graph); FString FilePath = BPDir / Graph->GetName() + TEXT(".txt"); FString DetailsPath = BPDir / TEXT("DETAILS") / Graph->GetName() + TEXT(".txt"); FFileHelper::SaveStringToFile(Exporter.GetOutput(), *FilePath); FFileHelper::SaveStringToFile(Exporter.GetDetails(), *DetailsPath); UE_LOG(LogLuprexIntegration, Warning, TEXT("Blueprint export: %s"), *FilePath); } } } } #endif