// Copyright 2016 Mookie. All Rights Reserved. #include "EasyBallisticsEditor.h" #include "AssetToolsModule.h" #include "PropertyEditorModule.h" #include "EditorModeRegistry.h" #include "ComponentVisualizer.h" #include "UnrealEdGlobals.h" #include "Editor/UnrealEdEngine.h" // Asset Factories #include "EBMaterialResponseMapFactory.h" #include "EBBulletPropertiesFactory.h" #include "EBBulletActorFactory.h" #include "EBMathematicalBallisticsFactory.h" #include "EBWeaponConfigurationFactory.h" #include "EBGunActorFactory.h" // Component Visualizers #include "EBBarrelComponentFactory.h" #include "EBMagazineComponentFactory.h" // Customizations #include "EBPhysicalMaterialCustomization.h" #include "EBJsonImportExportTool.h" // Component Classes #include "EBBarrel.h" #include "EBMagazine.h" #include "PhysicalMaterials/PhysicalMaterial.h" #include "Editor.h" #define LOCTEXT_NAMESPACE "FEasyBallisticsEditorModule" EAssetTypeCategories::Type FEasyBallisticsEditorModule::BallisticsAssetCategory; void FEasyBallisticsEditorModule::StartupModule() { // Register asset factories IAssetTools& AssetTools = FModuleManager::LoadModuleChecked("AssetTools").Get(); // Register the Ballistics category BallisticsAssetCategory = AssetTools.RegisterAdvancedAssetCategory(FName(TEXT("Ballistics")), LOCTEXT("BallisticsCategory", "Ballistics")); // Store references to our asset type actions for cleanup RegisteredAssetTypeActions.Empty(); // Register Material Response Map factory { TSharedRef MaterialResponseMapActions = MakeShareable(new FEBMaterialResponseMapFactory()); AssetTools.RegisterAssetTypeActions(MaterialResponseMapActions); RegisteredAssetTypeActions.Add(MaterialResponseMapActions); } // Register Bullet Properties Asset factory { TSharedRef BulletPropertiesActions = MakeShareable(new FEBBulletPropertiesAssetFactory()); AssetTools.RegisterAssetTypeActions(BulletPropertiesActions); RegisteredAssetTypeActions.Add(BulletPropertiesActions); } // Register Material Properties Asset factory { TSharedRef MaterialPropertiesActions = MakeShareable(new FEBMaterialPropertiesAssetFactory()); AssetTools.RegisterAssetTypeActions(MaterialPropertiesActions); RegisteredAssetTypeActions.Add(MaterialPropertiesActions); } // Register Mathematical Ballistics Asset factory { TSharedRef MathematicalBallisticsActions = MakeShareable(new FEBMathematicalBallisticsFactory()); AssetTools.RegisterAssetTypeActions(MathematicalBallisticsActions); RegisteredAssetTypeActions.Add(MathematicalBallisticsActions); } // Register Weapon Configuration Asset factory { TSharedRef WeaponConfigurationActions = MakeShareable(new FEBWeaponConfigurationFactory()); AssetTools.RegisterAssetTypeActions(WeaponConfigurationActions); RegisteredAssetTypeActions.Add(WeaponConfigurationActions); } // Register UFactory objects (these handle the "Add" menu in Content Browser) // These need to be manually registered to appear in the Add menu // Register Material Response Map UFactory if (!GetDefault()) { NewObject(); } // Register Bullet Properties UFactory if (!GetDefault()) { NewObject(); } // Register Material Properties UFactory if (!GetDefault()) { NewObject(); } // Register Mathematical Ballistics UFactory if (!GetDefault()) { NewObject(); } // Register Weapon Configuration UFactory if (!GetDefault()) { NewObject(); } // Register UObject-based factories for actors if (GEditor) { // Register Weapon Configuration factory UEBWeaponConfigurationFactory* WeaponConfigFactory = NewObject(); // UFactory objects are automatically discovered by the editor // Register Gun Actor factory UEBGunActorFactory* GunActorFactory = NewObject(); GEditor->ActorFactories.Add(GunActorFactory); // Register Bullet Actor factory UEBBulletActorFactory* BulletActorFactory = NewObject(); GEditor->ActorFactories.Add(BulletActorFactory); } // Register Component Visualizers if (GUnrealEd) { // Register Barrel Component Visualizer TSharedPtr BarrelVisualizer = MakeShareable(new FEBBarrelComponentVisualizer()); GUnrealEd->RegisterComponentVisualizer(UEBBarrel::StaticClass()->GetFName(), BarrelVisualizer); RegisteredComponentClassNames.Add(UEBBarrel::StaticClass()->GetFName()); // Register Magazine Component Visualizer TSharedPtr MagazineVisualizer = MakeShareable(new FEBMagazineComponentVisualizer()); GUnrealEd->RegisterComponentVisualizer(UEBMagazine::StaticClass()->GetFName(), MagazineVisualizer); RegisteredComponentClassNames.Add(UEBMagazine::StaticClass()->GetFName()); } // Register Physical Material customization FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked("PropertyEditor"); PropertyModule.RegisterCustomClassLayout( UPhysicalMaterial::StaticClass()->GetFName(), FOnGetDetailCustomizationInstance::CreateStatic(&FEBPhysicalMaterialCustomization::MakeInstance) ); // Register JSON Import/Export tool - delay this until after editor is fully loaded FCoreDelegates::OnFEngineLoopInitComplete.AddLambda([]() { FEBJsonImportExportTool::RegisterMenus(); }); } void FEasyBallisticsEditorModule::ShutdownModule() { // Unregister JSON Import/Export tool FEBJsonImportExportTool::UnregisterMenus(); // Unregister Component Visualizers if (GUnrealEd) { for (const FName& ClassName : RegisteredComponentClassNames) { GUnrealEd->UnregisterComponentVisualizer(ClassName); } } RegisteredComponentClassNames.Empty(); // Unregister Physical Material customization if (FModuleManager::Get().IsModuleLoaded("PropertyEditor")) { FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked("PropertyEditor"); PropertyModule.UnregisterCustomClassLayout(UPhysicalMaterial::StaticClass()->GetFName()); } // Unregister asset type actions if (FModuleManager::Get().IsModuleLoaded("AssetTools")) { IAssetTools& AssetTools = FModuleManager::GetModuleChecked("AssetTools").Get(); for (auto& AssetTypeAction : RegisteredAssetTypeActions) { if (AssetTypeAction.IsValid()) { AssetTools.UnregisterAssetTypeActions(AssetTypeAction.ToSharedRef()); } } } RegisteredAssetTypeActions.Empty(); } #undef LOCTEXT_NAMESPACE IMPLEMENT_MODULE(FEasyBallisticsEditorModule, EasyBallisticsEditor)