Implement asset editor interface so SNGStateMachine object can be created and edited
This commit is contained in:
parent
0eaaa562be
commit
b71b54537c
BIN
SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset
(Stored with Git LFS)
Normal file
BIN
SwordNGun/Content/Characters/Protagonist/States/ProtagStateMachine.uasset
(Stored with Git LFS)
Normal file
Binary file not shown.
@ -3,6 +3,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include "Modules/ModuleManager.h"
|
#include "Modules/ModuleManager.h"
|
||||||
|
#include "Styling/SlateStyle.h"
|
||||||
|
|
||||||
class ISNGModuleListenerInterface
|
class ISNGModuleListenerInterface
|
||||||
{
|
{
|
||||||
@ -14,10 +15,14 @@ public:
|
|||||||
class ISNGModuleInterface : public IModuleInterface
|
class ISNGModuleInterface : public IModuleInterface
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
/** IModuleInterface */
|
||||||
virtual void StartupModule() override;
|
virtual void StartupModule() override;
|
||||||
virtual void ShutdownModule() override;
|
virtual void ShutdownModule() override;
|
||||||
|
|
||||||
virtual void AddModuleListeners() {};
|
virtual void AddModuleListeners() {};
|
||||||
|
|
||||||
|
TSharedPtr<FSlateStyleSet> StyleSet;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
TArray<TSharedRef<ISNGModuleListenerInterface>> ModuleListeners;
|
TArray<TSharedRef<ISNGModuleListenerInterface>> ModuleListeners;
|
||||||
};
|
};
|
||||||
|
@ -0,0 +1 @@
|
|||||||
|
#include "States/IStateMachineEditor.h"
|
@ -0,0 +1,68 @@
|
|||||||
|
#include "States/SNGStateMachineEditor.h"
|
||||||
|
|
||||||
|
#define LOCTEXT_NAMESPACE "SNGStateMachineEditor"
|
||||||
|
|
||||||
|
const FName SNGStateMachineEditorAppName = FName(TEXT("SNGStateMachineEditorAppName"));
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::RegisterTabSpawners(const TSharedRef<FTabManager>& InTabManager)
|
||||||
|
{
|
||||||
|
/*
|
||||||
|
WorkspaceMenuCategory = TabManager->AddLocalWorkspaceMenuCategory(LOCTEXT("WorkspaceMenu_SNGStateMachineEditor", "SNG State Machine Editor"));
|
||||||
|
TSharedRef<FWorkspaceItem> WorkspaceMenuCatRef = WorkspaceMenuCategory.ToSharedRef();
|
||||||
|
FAssetEditorToolkit::RegisterTabSpawners(TabManager);
|
||||||
|
TabManager->RegisterTabSpawner(GraphCanvasTabId, )
|
||||||
|
.SetDisplayName(LOCTEXT("GraphCanvasTab", "Graph"))
|
||||||
|
.SetGroup(WorkspaceMenuCategoryRef)
|
||||||
|
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "GraphEditor.EventGraph_16x"));
|
||||||
|
|
||||||
|
TabManager->RegisterTabSpawner(PropertiesTabId, FOnSpawnTab::CreateSP(this, &FSoundSubmixEditor::SpawnTab_Properties))
|
||||||
|
.SetDisplayName(LOCTEXT("PropertiesTab", "Details"))
|
||||||
|
.SetGroup(WorkspaceMenuCategoryRef)
|
||||||
|
.SetIcon(FSlateIcon(FEditorStyle::GetStyleSetName(), "LevelEditor.Tabs.Details"));\
|
||||||
|
*/
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::UnregisterTabSpawners(const TSharedRef<FTabManager>& InTabManager)
|
||||||
|
{
|
||||||
|
IStateMachineEditor::UnregisterTabSpawners(InTabManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
FText FSNGStateMachineEditor::GetBaseToolkitName() const
|
||||||
|
{
|
||||||
|
return LOCTEXT("SNGStateMachineEditorAppLabel", "SNG State Machine Editor");
|
||||||
|
}
|
||||||
|
|
||||||
|
FText FSNGStateMachineEditor::GetToolkitName() const
|
||||||
|
{
|
||||||
|
const bool bDirtyState = StateMachineEdited->GetOutermost()->IsDirty();
|
||||||
|
|
||||||
|
FFormatNamedArguments Args;
|
||||||
|
Args.Add(TEXT("StateMachineName", FText::FromString(StateMachineEdited->GetName())));
|
||||||
|
Args.Add((TEXT("DirtyState")), bDirtyState ? FText::FromString("*") : FText::GetEmpty());
|
||||||
|
return FText::Format(LOCTEXT("SNGStateMachineEditorToolkitName", "{StateMachineName}{DirtyState}"), Args);
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::SaveAsset_Execute()
|
||||||
|
{
|
||||||
|
FAssetEditorToolkit::SaveAsset_Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::SaveAssetAs_Execute()
|
||||||
|
{
|
||||||
|
IStateMachineEditor::SaveAssetAs_Execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::FocusWindow(UObject* ObjectToFocusOn)
|
||||||
|
{
|
||||||
|
BringToolkitToFront();
|
||||||
|
//JumpToObject
|
||||||
|
}
|
||||||
|
|
||||||
|
void FSNGStateMachineEditor::InitStateMachineEditor(const EToolkitMode::Type Mode,
|
||||||
|
const TSharedPtr<IToolkitHost>& InitToolkitHost, USNGStateMachine* StateMachine)
|
||||||
|
{
|
||||||
|
StateMachineEdited = StateMachine;
|
||||||
|
FAssetEditorToolkit::InitAssetEditor(Mode, InitToolkitHost, SNGStateMachineEditorAppName, , true, true, StateMachine);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
@ -0,0 +1,7 @@
|
|||||||
|
#pragma once
|
||||||
|
|
||||||
|
class IStateMachineEditor : public FAssetEditorToolkit
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
|
||||||
|
};
|
@ -0,0 +1,43 @@
|
|||||||
|
// Project Sword & Gun Copyright © 2021 Kevin Poretti
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include "CoreMinimal.h"
|
||||||
|
#include "IStateMachineEditor.h"
|
||||||
|
#include "States/SNGStateMachine.h"
|
||||||
|
#include "Toolkits/SimpleAssetEditor.h"
|
||||||
|
|
||||||
|
class FSNGStateMachineEditor : public IStateMachineEditor
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
/** IToolkit Interface */
|
||||||
|
virtual void RegisterTabSpawners(const TSharedRef<FTabManager>& InTabManager) override;
|
||||||
|
virtual void UnregisterTabSpawners(const TSharedRef<FTabManager>& InTabManager) override;
|
||||||
|
virtual FText GetBaseToolkitName() const override;
|
||||||
|
virtual FText GetToolkitName() const override;
|
||||||
|
virtual FName GetToolkitFName() const override { return FName(TEXT("SNGStateMachineEditor")); }
|
||||||
|
virtual FText GetToolkitToolTipText() const override;
|
||||||
|
virtual FLinearColor GetWorldCentricTabColorScale() const override;
|
||||||
|
virtual FString GetWorldCentricTabPrefix() const override;
|
||||||
|
|
||||||
|
/** FAssetEditorToolkit interface */
|
||||||
|
virtual FString GetDocumentationLink() const override;
|
||||||
|
virtual bool CanSaveAsset() const override { return true; }
|
||||||
|
virtual bool CanSaveAssetAs() const override { return true; }
|
||||||
|
virtual void SaveAsset_Execute() override;
|
||||||
|
virtual void SaveAssetAs_Execute() override;
|
||||||
|
|
||||||
|
/** IAssetEditorInstance interface */
|
||||||
|
virtual void FocusWindow(UObject* ObjectToFocusOn = nullptr) override;
|
||||||
|
|
||||||
|
void InitStateMachineEditor(const EToolkitMode::Type Mode, const TSharedPtr<IToolkitHost>& InitToolkitHost, USNGStateMachine* StateMachine);
|
||||||
|
|
||||||
|
private:
|
||||||
|
/** State machien being edited */
|
||||||
|
USNGStateMachine* StateMachineEdited;
|
||||||
|
|
||||||
|
/** Graph Editor */
|
||||||
|
TSharedPtr<SGraphEditor> GraphEditorView;
|
||||||
|
|
||||||
|
|
||||||
|
};
|
Binary file not shown.
Binary file not shown.
@ -1,14 +1,39 @@
|
|||||||
#include "SwordNGunEditor.h"
|
#include "SwordNGunEditor.h"
|
||||||
|
|
||||||
|
#include "AssetToolsModule.h"
|
||||||
|
#include "States/SNGStateMachineTypeActions.h"
|
||||||
|
|
||||||
IMPLEMENT_GAME_MODULE(FSwordNGunEditor, SwordNGunEditor)
|
IMPLEMENT_GAME_MODULE(FSwordNGunEditor, SwordNGunEditor)
|
||||||
|
|
||||||
void FSwordNGunEditor::StartupModule()
|
void FSwordNGunEditor::StartupModule()
|
||||||
{
|
{
|
||||||
|
// register custom types
|
||||||
|
// add custom category
|
||||||
|
IAssetTools& AssetTools = FModuleManager::LoadModuleChecked<FAssetToolsModule>("AssetTools").Get();
|
||||||
|
// register custom asset with SwordNGun category
|
||||||
|
EAssetTypeCategories::Type SNGCategory =
|
||||||
|
AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("SwordNGun")), FText::FromString("Sword N Gun"));
|
||||||
|
TSharedPtr<IAssetTypeActions> Action = MakeShareable(new FSNGStateMachineTypeActions(SNGCategory));
|
||||||
|
AssetTools.RegisterAssetTypeActions(Action.ToSharedRef());
|
||||||
|
// save for later so it can be unregistered on shutdown
|
||||||
|
CreatedAssetTypeActions.Add(Action);
|
||||||
|
|
||||||
ISNGModuleInterface::StartupModule();
|
ISNGModuleInterface::StartupModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
void FSwordNGunEditor::ShutdownModule()
|
void FSwordNGunEditor::ShutdownModule()
|
||||||
{
|
{
|
||||||
|
// unregister all asset types created by this module
|
||||||
|
if(FModuleManager::Get().IsModuleLoaded("AssetTools"))
|
||||||
|
{
|
||||||
|
IAssetTools& AssetTools = FModuleManager::GetModuleChecked<FAssetToolsModule>("AssetTools").Get();
|
||||||
|
for(int32 i = 0; i < CreatedAssetTypeActions.Num(); i++)
|
||||||
|
{
|
||||||
|
AssetTools.UnregisterAssetTypeActions(CreatedAssetTypeActions[i].ToSharedRef());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
CreatedAssetTypeActions.Empty();
|
||||||
|
|
||||||
ISNGModuleInterface::ShutdownModule();
|
ISNGModuleInterface::ShutdownModule();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include "IAssetTypeActions.h"
|
||||||
#include "ISNGModuleInterface.h"
|
#include "ISNGModuleInterface.h"
|
||||||
|
|
||||||
class FSwordNGunEditor : public ISNGModuleInterface
|
class FSwordNGunEditor : public ISNGModuleInterface
|
||||||
@ -19,4 +20,7 @@ public:
|
|||||||
{
|
{
|
||||||
return FModuleManager::Get().IsModuleLoaded("SwordNGunEditor");
|
return FModuleManager::Get().IsModuleLoaded("SwordNGunEditor");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TArray<TSharedPtr<IAssetTypeActions>> CreatedAssetTypeActions;
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user