|
- <font size="6">// Copyright 1998-2019 Epic Games, Inc. All Rights Reserved.
- #include "testmyplugin.h"
- //--#include "FWindowTestStyle.h"
- #include "FWindowTestCommands.h"
- #include "LevelEditor.h"
- #include "Editor.h"
- //#include "Kismet2/KismetEditorUtilities.h"
- <span style="background-color: yellow;">#include "Kismet2/KismetEditorUtilities.h"</span>
- #include "LevelEditorViewport.h"
- #include "Engine/SkeletalMesh.h"
- //#include "Editor/EditorEngine.h"
- #include "Engine/Selection.h"
- #include "ContentBrowserModule.h"
- #include "IContentBrowserSingleton.h"
- #include "Engine/StaticMeshActor.h"
- #include "Animation/SkeletalMeshActor.h"
- #include "Components/SkeletalMeshComponent.h"
- #define LOCTEXT_NAMESPACE "FtestmypluginModule"
- #define PIE 3.1415926
- void FtestmypluginModule::StartupModule()
- {
- // This code will execute after your module is loaded into memory; the exact timing is specified in the .uplugin file per-module
- // 注册编辑器插件风格
- //-- FWindowTestStyle::Initialize();
- //-- FWindowTestStyle::ReloadTextures();
- // 注册编辑器插件命令
- FWindowTestCommands::Register();
- //FtestmypluginModule::TestAction();
- PluginCommands = MakeShareable(new FUICommandList);
- PluginCommands->MapAction(
- FWindowTestCommands::Get().OpenPluginWindow,
- FExecuteAction::CreateRaw(this, &FtestmypluginModule::GetSeltion)
- );
- FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
- {
- TSharedPtr<FExtender> NewToolbarExtender = MakeShareable(new FExtender);
- /**
- * Extends a tool bar at the specified extension point
- *
- * @param ExtensionHook Part of the menu to extend. You can extend the same point multiple times, and extensions will be applied in the order they were registered.
- * @param HookPosition Where to apply hooks in relation to the extension hook
- * @param CommandList The UI command list responsible for handling actions for the toolbar items you'll be extending the menu with
- * @param ToolbarExtensionDelegate Called to populate the part of the toolbar you're extending
- *
- * @return Pointer to the new extension object. You can use this later to remove the extension.
- */
- NewToolbarExtender->AddToolBarExtension("Content",
- EExtensionHook::Before,
- PluginCommands,
- FToolBarExtensionDelegate::CreateRaw(this, &FtestmypluginModule::AddToolbarButton));
- LevelEditorModule.GetToolBarExtensibilityManager()->AddExtender(NewToolbarExtender);
- }
- //FExecuteAction::CreateRaw(this, &FtestmypluginModule::TestAction);
- }
- /*void FtestmypluginModule::AddToolbarButton(FToolBarBuilder& Builder)
- {
- Builder.AddToolBarButton(FWindowTestCommands::Get().OpenPluginWindow);
- }*/
- void FtestmypluginModule::AddToolbarButton(FToolBarBuilder& Builder)
- {
- Builder.AddToolBarButton(FWindowTestCommands::Get().OpenPluginWindow);
- }
- void FtestmypluginModule::ShutdownModule()
- {
- // This function may be called during shutdown to clean up your module. For modules that support dynamic reloading,
- // we call this function before unloading the module.
- FWindowTestCommands::Unregister();
- }
- void FtestmypluginModule::TestAction()
- {
- UE_LOG(LogTemp, Warning, TEXT("It Works!!!xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"));
- }
- FVector huayuan(int shu,float r)
- {
- FVector newpos(0,0,0);
- //int y = sin(i * PIE / 180) * r + posy; // sin、cos用的是弧度,需要转换
- newpos.Y = sin(shu * PIE / 180) * r;
- newpos.X = cos(shu * PIE / 180) * r;
- return newpos;
- // putpixel(x, y, 0xFFFFFF); // 画点
- // Sleep(10);
-
- }
- void FtestmypluginModule::GetSeltion()
- {
- TArray<FAssetData> AssetDatas; //选择列表容器
- FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
- IContentBrowserSingleton& ContentBrowserSingleton = ContentBrowserModule.Get();
- ContentBrowserSingleton.GetSelectedAssets(AssetDatas); //获取选择列表
- //ContentBrowserSingleton.GetSelectedAssets(AssetDatas);
- //UWorld * currentWorld = GEditor->LevelViewportClients[0]->GetWorld();
- UClass * staticMeshClass = AActor::StaticClass();
- UWorld * currentWorld = GCurrentLevelEditingViewportClient->GetWorld();
- ULevel * currentLevel = currentWorld->GetLevel(0);
- FVector objectPosition(0, 0, 0);
- FRotator objectRotation(0, 0, 0); //in degrees
- FVector objectScale(1, 1, 1);
- FTransform objectTrasform(objectRotation, objectPosition, objectScale);
- cishu += 1;
- for (int kk = 0; kk < AssetDatas.Num(); kk++)
- {
-
- if(AssetDatas[kk].AssetClass == FName("Blueprint"))
- {
- UBlueprint* Object;
-
- Object = Cast<UBlueprint>(AssetDatas[kk].GetAsset());
- FKismetEditorUtilities::CompileBlueprint(Object);
- AActor* NewBlock = currentWorld->SpawnActor(Object->GeneratedClass);
- NewBlock->SetActorLabel(TEXT("BP_" + Object->GetName()));
- // UE_LOG(LogTemp, Warning, TEXT("content is %s"), *AssetDatas[kk].AssetClass.ToString());
- }
- else if (AssetDatas[kk].AssetClass == FName("StaticMesh"))
- {
- UStaticMesh* Object;
- Object = Cast<UStaticMesh>(AssetDatas[kk].GetAsset());
- int jiaodu = cishu * 10;
- if(jiaodu > (360* shengchang))
- {
- shengchang += 1;
- }
- AStaticMeshActor* NewBlock = currentWorld->SpawnActor<AStaticMeshActor>(huayuan(jiaodu,500+100* shengchang), FRotator(0, jiaodu, 0));
- TArray<UStaticMeshComponent*> Comps;
- NewBlock->GetComponents(Comps);
- if (Comps.Num() > 0)
- {
- UStaticMeshComponent* FoundComp = Comps[0];
- FoundComp->SetStaticMesh(Object);
- }
- NewBlock->SetActorLabel(TEXT("SM_" + Object->GetName()));
- //ConstructorHelpers::FObjectFinder<UStaticMesh> pCube = Object;
- // pCube.Object
- //00currentWorld->SpawnActor(Object->GetClass());
- //UE_LOG(LogTemp, Warning, TEXT("content is %s"), *AssetDatas[kk].AssetClass.ToString());
- }
- else if (AssetDatas[kk].AssetClass == FName("SkeletalMesh"))
- {
- USkeletalMesh* Object;
- Object = Cast<USkeletalMesh>(AssetDatas[kk].GetAsset());
- //00 currentWorld->SpawnActor(Object->GetClass());
- ASkeletalMeshActor* NewBlock = currentWorld->SpawnActor<ASkeletalMeshActor>(FVector(300, -200, 0), FRotator(0, 0, 0));
- TArray<USkeletalMeshComponent*> Comps;
- NewBlock->GetComponents(Comps);
- if (Comps.Num() > 0)
- {
-
- USkeletalMeshComponent* FoundComp = Comps[0];
- FoundComp->SetSkeletalMesh(Object);
- }
- NewBlock->SetActorLabel(TEXT("SK_"+Object->GetName()));
- //UE_LOG(LogTemp, Warning, TEXT("content is %s"), *AssetDatas[kk].AssetClass.ToString());
- }
- //00 Object = Cast<UBlueprint>(AssetDatas[kk].GetAsset());
- //UClass *CC = AssetDatas[kk].GetClass();
- //AssetDatas[kk].GetClass()
- //currentWorld->SpawnActor(Object->class);
- //UBlueprint* gen = Cast<UBlueprint>(Object);
- //00 currentWorld->SpawnActor(Object->GeneratedClass);
- //AActor * newActorCreated = GEditor->AddActor(currentLevel, UObject::StaticClass(), objectTrasform, true, RF_Public | RF_Standalone | RF_Transactional);
- UE_LOG(LogTemp, Warning, TEXT("content is %s"),*AssetDatas[kk].AssetClass.ToString());
- }
- USelection* SelectedActors = GEditor->GetSelectedActors();
- int cout = 0;
-
- if (SelectedActors)
- {
- TArray<UObject*> SelectedActorsArr;
- SelectedActors->GetSelectedObjects(AActor::StaticClass(), SelectedActorsArr);
-
- /*if (SelectedActorsArr.Num() != 1)
- {
- UE_LOG(LogTemp, Error, TEXT("SelectedActorNum != 1"));
- return;
- }*/
- for (int jj = 0; jj < SelectedActorsArr.Num(); jj++)
- {
- FTransform SelectedActorTransform;
- UObject* curObj = SelectedActorsArr[jj];
- AActor* Actor = Cast<AActor>(curObj);
- if (Actor)
- {
- SelectedActorTransform = Actor->GetTransform();
- //UStaticMeshComponent* Mesh;
- //Mesh->GetStaticMesh()->GetNumVertices
- //UStaticMeshComponent* Mesh;
- TArray<UStaticMeshComponent*> Comps;
- Actor->GetComponents(Comps);
-
- /*if (Comps.Num() > 0)
- {
- SelMesh = Comps[0];
- cout = SelMesh->GetStaticMesh()->GetNumVertices(0);
- }*/
- for (int i = 0; i < Comps.Num(); i++)
- {
- //UStaticMeshComponent* SelMesh;
- //SelMesh = Comps[i];
- cout += Comps[i]->GetStaticMesh()->RenderData.Get()->LODResources[0].GetNumTriangles();
- }
- // UActorComponent *a = Actor->GetComponentByClass(UStaticMeshComponent::StaticClass());
- // Mesh = Cast<UStaticMeshComponent>(Actor->GetComponentByClass(UStaticMeshComponent::StaticClass()));
- //UE_LOG(LogTemp, Warning, TEXT("SelectedActor Transform:%s"), *SelectedActorTransform.ToString());
- UE_LOG(LogTemp, Warning, TEXT("Triangles Number : %i"), cout);
- }
- else
- {
- return;
- }
- }
- }
- }
- #undef LOCTEXT_NAMESPACE
-
- IMPLEMENT_MODULE(FtestmypluginModule, testmyplugin)</font>
复制代码
|
|