根据网上的实例修改
添加插件Editor Toolbar Button 命名:EditorTools
2. 在文件EditorTools.cpp编辑代码
//当点击工具栏上的按钮是就会在场景中创建一个圆锥体void FEditorToolsModule::PluginButtonClicked() {#if 0// Put your "OnButtonClicked" stuff hereFText DialogText = FText::Format(LOCTEXT("PluginButtonDialogText", "Add code to {0} in {1} to override this button's actions"),FText::FromString(TEXT("FEditorToolsModule::PluginButtonClicked()")),FText::FromString(TEXT("EditorTools.cpp")));FMessageDialog::Open(EAppMsgType::Ok, DialogText);#else//通过当前编辑视图实例获取当前WorldUWorld* World = GCurrentLevelEditingViewportClient->GetWorld();if (World) {//在视图中放置StaticMeshActorAStaticMeshActor* Actor = World->SpawnActor<AStaticMeshActor>(FVector(0, 0, 100), FRotator::ZeroRotator);//加载引擎Asset资源UStaticMesh* ConeMesh = LoadObject<UStaticMesh>(NULL, TEXT("/Engine/BasicShapes/Cone.Cone"), NULL, LOAD_None, NULL);UMaterial* Mat = LoadObject<UMaterial>(NULL, TEXT("/Engine/BasicShapes/BasicShapeMaterial.BasicShapeMaterial"), NULL, LOAD_None, NULL);if (ConeMesh) {//设置Mesh材质ConeMesh->SetMaterial(0, Mat);//设置MeshComponent的MeshActor->GetStaticMeshComponent()->SetStaticMesh(ConeMesh);}//刷新编辑中的视图,如果不加这行,则需要鼠标触发一下视图,视图才会刷新GEditor->RedrawLevelEditingViewports(true);}#endif}
编译以后工具栏上就会出现一个EditorTools按钮
点击这个按钮,在场景中就会出现一个圆锥体
aaa
如果觉得《UE4插件 - 编辑器工具栏按钮》对你有帮助,请点赞、收藏,并留下你的观点哦!