From 492023e86ef8d6171331032c6a76c598f3082f33 Mon Sep 17 00:00:00 2001 From: Gerke Max Preussner Date: Mon, 14 Dec 2015 01:32:36 -0500 Subject: [PATCH] Added support for drag & drop of text files. --- .../Private/Factories/TextAssetFactory.cpp | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp b/Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp index 6655d5d..f7fa130 100644 --- a/Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp +++ b/Source/TextAssetEditor/Private/Factories/TextAssetFactory.cpp @@ -10,6 +10,7 @@ UTextAssetFactory::UTextAssetFactory( const FObjectInitializer& ObjectInitializer ) : Super(ObjectInitializer) { + Formats.Add(FString(TEXT("txt;")) + NSLOCTEXT("UTextAssetFactory", "FormatTxt", "Text File").ToString()); SupportedClass = UTextAsset::StaticClass(); bCreateNew = false; bEditorImport = true; @@ -21,5 +22,16 @@ UTextAssetFactory::UTextAssetFactory( const FObjectInitializer& ObjectInitialize UObject* UTextAssetFactory::FactoryCreateBinary(UClass* Class, UObject* InParent, FName Name, EObjectFlags Flags, UObject* Context, const TCHAR* Type, const uint8*& Buffer, const uint8* BufferEnd, FFeedbackContext* Warn) { - return NewObject(InParent, Class, Name, Flags); + UTextAsset* TextAsset = nullptr; + FString TextString; + + FEditorDelegates::OnAssetPreImport.Broadcast(this, Class, InParent, Name, Type); + + if (FFileHelper::LoadFileToString(TextString, *CurrentFilename)) + { + TextAsset = NewObject(InParent, Class, Name, Flags); + TextAsset->Text = FText::FromString(TextString); + } + + return TextAsset; }