From 445f21fe7b5b79ebb8ca755fb841eb4e5fd9b7a4 Mon Sep 17 00:00:00 2001 From: 997146918 <997146918@qq.com> Date: Sat, 30 Aug 2025 13:43:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84BagShape=20Editor?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../AssetActions/BagShapeAssetTypeAction.cpp | 12 ++- .../AssetEditor/BagShapeAssetEditor.cpp | 74 +++++++++++++++++++ .../Private/Widgets/BagShapeEditorWidget.cpp | 10 +++ .../AssetActions/BagShapeAssetTypeAction.h | 3 +- .../Public/AssetEditor/BagShapeAssetEditor.h | 33 +++++++++ .../Public/Widgets/BagShapeEditorWidget.h | 21 ++++++ 6 files changed, 151 insertions(+), 2 deletions(-) create mode 100644 ProjectFish/Source/ProjectFishEditor/Private/AssetEditor/BagShapeAssetEditor.cpp create mode 100644 ProjectFish/Source/ProjectFishEditor/Private/Widgets/BagShapeEditorWidget.cpp create mode 100644 ProjectFish/Source/ProjectFishEditor/Public/AssetEditor/BagShapeAssetEditor.h create mode 100644 ProjectFish/Source/ProjectFishEditor/Public/Widgets/BagShapeEditorWidget.h diff --git a/ProjectFish/Source/ProjectFishEditor/Private/AssetActions/BagShapeAssetTypeAction.cpp b/ProjectFish/Source/ProjectFishEditor/Private/AssetActions/BagShapeAssetTypeAction.cpp index 4182010..0b5a15c 100644 --- a/ProjectFish/Source/ProjectFishEditor/Private/AssetActions/BagShapeAssetTypeAction.cpp +++ b/ProjectFish/Source/ProjectFishEditor/Private/AssetActions/BagShapeAssetTypeAction.cpp @@ -3,6 +3,7 @@ #include "AssetActions/BagShapeAssetTypeAction.h" +#include "AssetEditor/BagShapeAssetEditor.h" #include "ProjectFish/DataAsset/BagShapeAsset.h" @@ -14,7 +15,16 @@ UClass* FBagShapeAssetTypeAction::GetSupportedClass() const void FBagShapeAssetTypeAction::OpenAssetEditor(const TArray& InObjects, TSharedPtr EditWithinLevelEditor) { - FAssetTypeActions_Base::OpenAssetEditor(InObjects, EditWithinLevelEditor); + EToolkitMode::Type Mode = EditWithinLevelEditor.IsValid() ? EToolkitMode::WorldCentric : EToolkitMode::Standalone; + + for (auto ObjIt = InObjects.CreateConstIterator(); ObjIt; ++ObjIt) + { + if (UBagShapeAsset* BagShapeAsset = Cast(*ObjIt)) + { + TSharedRef EditorToolkit = MakeShareable(new FBagShapeAssetEditor()); + EditorToolkit->Initialize(Mode, EditWithinLevelEditor, BagShapeAsset); + } + } } diff --git a/ProjectFish/Source/ProjectFishEditor/Private/AssetEditor/BagShapeAssetEditor.cpp b/ProjectFish/Source/ProjectFishEditor/Private/AssetEditor/BagShapeAssetEditor.cpp new file mode 100644 index 0000000..3110ef5 --- /dev/null +++ b/ProjectFish/Source/ProjectFishEditor/Private/AssetEditor/BagShapeAssetEditor.cpp @@ -0,0 +1,74 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "AssetEditor/BagShapeAssetEditor.h" +#include "ProjectFish/DataAsset/BagShapeAsset.h" +#include "Widgets/BagShapeEditorWidget.h" + +const FName FBagShapeAssetEditor::BagShapeEditorTabId(TEXT("BagShapeEditor")); + +void FBagShapeAssetEditor::Initialize(const EToolkitMode::Type Mode, + const TSharedPtr& InitToolkitHost, UBagShapeAsset* InBagShapeAsset) +{ + BagShapeAsset = InBagShapeAsset; + + const TSharedRef StandaloneDefaultLayout = FTabManager::NewLayout("Standalone_BagShapeAssetEditor_Layout_v1") + ->AddArea + ( + FTabManager::NewPrimaryArea()->SetOrientation(Orient_Vertical) + ->Split + ( + FTabManager::NewStack() + ->SetSizeCoefficient(1.0f) + ->AddTab(BagShapeEditorTabId, ETabState::OpenedTab) + ) + ); + + FAssetEditorToolkit::InitAssetEditor(Mode, InitToolkitHost, TEXT("BagShapeAssetEditorApp"), StandaloneDefaultLayout, true, true, InBagShapeAsset); + +} + +FName FBagShapeAssetEditor::GetToolkitFName() const +{ + return FName("BagShapeEditor"); +} + +FText FBagShapeAssetEditor::GetBaseToolkitName() const +{ + return FText::FromString("Base BagShapeEditor"); +} + +FString FBagShapeAssetEditor::GetWorldCentricTabPrefix() const +{ + return TEXT("ShapeTab"); +} + +FLinearColor FBagShapeAssetEditor::GetWorldCentricTabColorScale() const +{ + //return FLinearColor::White; + return FLinearColor(1.f, 0.8f, 0.45f, 0.5f); +} + +void FBagShapeAssetEditor::RegisterTabSpawners(const TSharedRef& tabManager) +{ + WorkspaceMenuCategory = tabManager->AddLocalWorkspaceMenuCategory( FText::FromString("BagShape")); + + tabManager->RegisterTabSpawner(BagShapeEditorTabId, FOnSpawnTab::CreateSP(this, &FBagShapeAssetEditor::SpawnBagShapeEditorTab)) + .SetDisplayName( FText::FromString("BagShapeEditor")) + .SetGroup(WorkspaceMenuCategory.ToSharedRef()); +} + +void FBagShapeAssetEditor::UnregisterTabSpawners(const TSharedRef& tabManager) +{ + tabManager->UnregisterTabSpawner(BagShapeEditorTabId); +} + +TSharedRef FBagShapeAssetEditor::SpawnBagShapeEditorTab(const FSpawnTabArgs& Args) +{ + return SNew(SDockTab) + .TabRole(ETabRole::PanelTab) + [ + SNew(SBagShapeEditorWidget) + .BagShapeAsset(BagShapeAsset) + ]; +} \ No newline at end of file diff --git a/ProjectFish/Source/ProjectFishEditor/Private/Widgets/BagShapeEditorWidget.cpp b/ProjectFish/Source/ProjectFishEditor/Private/Widgets/BagShapeEditorWidget.cpp new file mode 100644 index 0000000..2cd00ab --- /dev/null +++ b/ProjectFish/Source/ProjectFishEditor/Private/Widgets/BagShapeEditorWidget.cpp @@ -0,0 +1,10 @@ +// Fill out your copyright notice in the Description page of Project Settings. + + +#include "Widgets/BagShapeEditorWidget.h" + + +void SBagShapeEditorWidget::Construct(const FArguments& InArgs) +{ + BagShapeAsset = InArgs._BagShapeAsset; +} diff --git a/ProjectFish/Source/ProjectFishEditor/Public/AssetActions/BagShapeAssetTypeAction.h b/ProjectFish/Source/ProjectFishEditor/Public/AssetActions/BagShapeAssetTypeAction.h index 3379c16..0a809a1 100644 --- a/ProjectFish/Source/ProjectFishEditor/Public/AssetActions/BagShapeAssetTypeAction.h +++ b/ProjectFish/Source/ProjectFishEditor/Public/AssetActions/BagShapeAssetTypeAction.h @@ -19,7 +19,8 @@ public: virtual FColor GetTypeColor() const override { return FColor(129, 196, 115); } virtual UClass* GetSupportedClass() const override; virtual void OpenAssetEditor(const TArray& InObjects, TSharedPtr EditWithinLevelEditor = TSharedPtr()) override; - virtual bool HasActions(const TArray& InObjects) const override {return true;} + //是否使用自定义的Action菜单 + virtual bool HasActions(const TArray& InObjects) const override {return false;} virtual uint32 GetCategories() override; ; virtual void GetActions(const TArray& InObjects, struct FToolMenuSection& Section) override; virtual bool CanFilter() override {return true;} diff --git a/ProjectFish/Source/ProjectFishEditor/Public/AssetEditor/BagShapeAssetEditor.h b/ProjectFish/Source/ProjectFishEditor/Public/AssetEditor/BagShapeAssetEditor.h new file mode 100644 index 0000000..5e12baf --- /dev/null +++ b/ProjectFish/Source/ProjectFishEditor/Public/AssetEditor/BagShapeAssetEditor.h @@ -0,0 +1,33 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "Toolkits/AssetEditorToolkit.h" +/** + * + */ +class PROJECTFISHEDITOR_API FBagShapeAssetEditor: public FAssetEditorToolkit +{ +public: + void Initialize(const EToolkitMode::Type Mode, const TSharedPtr& InitToolkitHost, class UBagShapeAsset* InBagShapeAsset); + + // IAssetEditorInstance interface + virtual FName GetToolkitFName() const override; + virtual FText GetBaseToolkitName() const override; + virtual FString GetWorldCentricTabPrefix() const override; + virtual FLinearColor GetWorldCentricTabColorScale() const override; + + // FAssetEditorToolkit interface + virtual void RegisterTabSpawners(const TSharedRef& TabManager) override; + virtual void UnregisterTabSpawners(const TSharedRef& TabManager) override; + +private: + TSharedRef SpawnBagShapeEditorTab(const FSpawnTabArgs& Args); + + class UBagShapeAsset* BagShapeAsset; + /** Tab IDs */ + static const FName BagShapeEditorTabId; +}; + + diff --git a/ProjectFish/Source/ProjectFishEditor/Public/Widgets/BagShapeEditorWidget.h b/ProjectFish/Source/ProjectFishEditor/Public/Widgets/BagShapeEditorWidget.h new file mode 100644 index 0000000..934dafc --- /dev/null +++ b/ProjectFish/Source/ProjectFishEditor/Public/Widgets/BagShapeEditorWidget.h @@ -0,0 +1,21 @@ +// Fill out your copyright notice in the Description page of Project Settings. + +#pragma once + +#include "CoreMinimal.h" +#include "ProjectFish/DataAsset/BagShapeAsset.h" + +/** + * + */ +class PROJECTFISHEDITOR_API SBagShapeEditorWidget: public SCompoundWidget +{ +public: + SLATE_BEGIN_ARGS(SBagShapeEditorWidget) {} + SLATE_ARGUMENT(UBagShapeAsset*, BagShapeAsset) + SLATE_END_ARGS() + void Construct(const FArguments& InArgs); + +private: + TWeakObjectPtr BagShapeAsset; +};