mirror of
https://github.com/EsotericSoftware/spine-runtimes.git
synced 2026-02-06 07:14:55 +08:00
[ue] Fixes #2368, use the InName provided to FactoryCreateFile for the asset object name.
This commit is contained in:
parent
b8eda5e27b
commit
f31f12d57e
@ -28,11 +28,9 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineAtlasImportFactory.h"
|
||||
#include "AssetRegistryModule.h"
|
||||
#include "AssetToolsModule.h"
|
||||
#include "Developer/AssetTools/Public/IAssetTools.h"
|
||||
#include "PackageTools.h"
|
||||
#include "SpineAtlasAsset.h"
|
||||
#include "Editor.h"
|
||||
|
||||
#define LOCTEXT_NAMESPACE "Spine"
|
||||
|
||||
@ -56,6 +54,9 @@ bool USpineAtlasAssetFactory::FactoryCanImport(const FString &Filename) {
|
||||
}
|
||||
|
||||
UObject *USpineAtlasAssetFactory::FactoryCreateFile(UClass *InClass, UObject *InParent, FName InName, EObjectFlags Flags, const FString &Filename, const TCHAR *Parms, FFeedbackContext *Warn, bool &bOutOperationCanceled) {
|
||||
FString FileExtension = FPaths::GetExtension(Filename);
|
||||
GEditor->GetEditorSubsystem<UImportSubsystem>()->BroadcastAssetPreImport(this, InClass, InParent, InName, *FileExtension);
|
||||
|
||||
FString rawString;
|
||||
if (!FFileHelper::LoadFileToString(rawString, *Filename)) {
|
||||
return nullptr;
|
||||
@ -64,13 +65,12 @@ UObject *USpineAtlasAssetFactory::FactoryCreateFile(UClass *InClass, UObject *In
|
||||
FString currentSourcePath, filenameNoExtension, unusedExtension;
|
||||
const FString longPackagePath = FPackageName::GetLongPackagePath(InParent->GetOutermost()->GetPathName());
|
||||
FPaths::Split(UFactory::GetCurrentFilename(), currentSourcePath, filenameNoExtension, unusedExtension);
|
||||
FString name(InName.ToString());
|
||||
name.Append("-atlas");
|
||||
|
||||
USpineAtlasAsset *asset = NewObject<USpineAtlasAsset>(InParent, InClass, FName(*name), Flags);
|
||||
USpineAtlasAsset *asset = NewObject<USpineAtlasAsset>(InParent, InClass, InName, Flags);
|
||||
asset->SetRawData(rawString);
|
||||
asset->SetAtlasFileName(FName(*Filename));
|
||||
LoadAtlas(asset, currentSourcePath, longPackagePath);
|
||||
GEditor->GetEditorSubsystem<UImportSubsystem>()->BroadcastAssetPostImport(this, asset);
|
||||
return asset;
|
||||
}
|
||||
|
||||
@ -109,6 +109,7 @@ EReimportResult::Type USpineAtlasAssetFactory::Reimport(UObject *Obj) {
|
||||
else
|
||||
Obj->MarkPackageDirty();
|
||||
|
||||
GEditor->GetEditorSubsystem<UImportSubsystem>()->BroadcastAssetReimport(asset);
|
||||
return EReimportResult::Succeeded;
|
||||
}
|
||||
|
||||
|
||||
@ -28,16 +28,46 @@
|
||||
*****************************************************************************/
|
||||
|
||||
#include "SpineEditorPlugin.h"
|
||||
#include "AssetTypeActions_Base.h"
|
||||
#include "SpineAtlasAsset.h"
|
||||
#include "SpineSkeletonDataAsset.h"
|
||||
|
||||
class FSpineAtlasAssetTypeActions : public FAssetTypeActions_Base
|
||||
{
|
||||
public:
|
||||
UClass* GetSupportedClass() const override { return USpineAtlasAsset::StaticClass(); };
|
||||
FText GetName() const override { return INVTEXT("Spine atlas asset"); };
|
||||
FColor GetTypeColor() const override { return FColor::Red; };
|
||||
uint32 GetCategories() override { return EAssetTypeCategories::Misc; };
|
||||
};
|
||||
|
||||
class FSpineSkeletonDataAssetTypeActions : public FAssetTypeActions_Base
|
||||
{
|
||||
public:
|
||||
UClass* GetSupportedClass() const override { return USpineSkeletonDataAsset::StaticClass(); };
|
||||
FText GetName() const override { return INVTEXT("Spine data asset"); };
|
||||
FColor GetTypeColor() const override { return FColor::Red; };
|
||||
uint32 GetCategories() override { return EAssetTypeCategories::Misc; };
|
||||
};
|
||||
|
||||
class FSpineEditorPlugin : public ISpineEditorPlugin {
|
||||
virtual void StartupModule() override;
|
||||
virtual void ShutdownModule() override;
|
||||
TSharedPtr<FSpineAtlasAssetTypeActions> SpineAtlasAssetTypeActions;
|
||||
TSharedPtr<FSpineSkeletonDataAssetTypeActions> SpineSkeletonDataAssetTypeActions;
|
||||
};
|
||||
|
||||
IMPLEMENT_MODULE(FSpineEditorPlugin, SpineEditorPlugin)
|
||||
|
||||
void FSpineEditorPlugin::StartupModule() {
|
||||
SpineAtlasAssetTypeActions = MakeShared<FSpineAtlasAssetTypeActions>();
|
||||
FAssetToolsModule::GetModule().Get().RegisterAssetTypeActions(SpineAtlasAssetTypeActions.ToSharedRef());
|
||||
SpineSkeletonDataAssetTypeActions = MakeShared<FSpineSkeletonDataAssetTypeActions>();
|
||||
FAssetToolsModule::GetModule().Get().RegisterAssetTypeActions(SpineSkeletonDataAssetTypeActions.ToSharedRef());
|
||||
}
|
||||
|
||||
void FSpineEditorPlugin::ShutdownModule() {
|
||||
if (!FModuleManager::Get().IsModuleLoaded("AssetTools")) return;
|
||||
FAssetToolsModule::GetModule().Get().UnregisterAssetTypeActions(SpineAtlasAssetTypeActions.ToSharedRef());
|
||||
FAssetToolsModule::GetModule().Get().UnregisterAssetTypeActions(SpineSkeletonDataAssetTypeActions.ToSharedRef());
|
||||
}
|
||||
|
||||
@ -76,10 +76,7 @@ void LoadAtlas(const FString &Filename, const FString &TargetPath) {
|
||||
}
|
||||
|
||||
UObject *USpineSkeletonAssetFactory::FactoryCreateFile(UClass *InClass, UObject *InParent, FName InName, EObjectFlags Flags, const FString &Filename, const TCHAR *Parms, FFeedbackContext *Warn, bool &bOutOperationCanceled) {
|
||||
FString name(InName.ToString());
|
||||
name.Append("-data");
|
||||
|
||||
USpineSkeletonDataAsset *asset = NewObject<USpineSkeletonDataAsset>(InParent, InClass, FName(*name), Flags);
|
||||
USpineSkeletonDataAsset *asset = NewObject<USpineSkeletonDataAsset>(InParent, InClass, InName, Flags);
|
||||
TArray<uint8> rawData;
|
||||
if (!FFileHelper::LoadFileToArray(rawData, *Filename, 0)) {
|
||||
return nullptr;
|
||||
|
||||
@ -53,10 +53,6 @@ void USpineAtlasAsset::PostInitProperties() {
|
||||
}
|
||||
|
||||
void USpineAtlasAsset::GetAssetRegistryTags(TArray<FAssetRegistryTag> &OutTags) const {
|
||||
if (importData) {
|
||||
OutTags.Add(FAssetRegistryTag(SourceFileTagName(), importData->GetSourceData().ToJson(), FAssetRegistryTag::TT_Hidden));
|
||||
}
|
||||
|
||||
Super::GetAssetRegistryTags(OutTags);
|
||||
}
|
||||
|
||||
|
||||
@ -111,7 +111,7 @@ public:
|
||||
|
||||
protected:
|
||||
UPROPERTY(VisibleAnywhere, Instanced, Category = ImportSettings)
|
||||
class UAssetImportData *importData;
|
||||
class UAssetImportData *importData = nullptr;
|
||||
|
||||
virtual void PostInitProperties() override;
|
||||
virtual void GetAssetRegistryTags(TArray<FAssetRegistryTag> &OutTags) const override;
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
{
|
||||
"FileVersion": 3,
|
||||
"EngineAssociation": "5.2",
|
||||
"EngineAssociation": "5.3",
|
||||
"Category": "",
|
||||
"Description": "",
|
||||
"Modules": [
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user