{"title":"Unreal引擎:关卡编辑器窗口自动跳转到指定坐标","description":"本文介绍如何在Unreal引擎中,通过代码实现给定一个坐标,关卡编辑器窗口自动跳转到该坐标的功能。示例代码展示了如何使用C++代码获取编辑器引擎、关卡编辑器实例以及视口,并设置摄像机的位置和旋转,最终实现坐标跳转。","keywords":"Unreal引擎, 关卡编辑器, 坐标跳转, C++, 代码示例, 视口, 摄像机","content":""// 导入需要的头文件\n#include "Editor/EditorEngine.h"\n#include "Editor/LevelEditor/Public/LevelEditor.h"\n#include "Editor/UnrealEdEngine.h"\n#include "Editor/UnrealEd/Public/Editor.h"\n\n// 定义一个函数来实现坐标跳转\nvoid JumpToLocation(FVector Location)\n{\n // 获取当前编辑器的引擎\n UEditorEngine* EditorEngine = Cast(GEngine);\n\n // 获取关卡编辑器的实例\n FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked("LevelEditor");\n TSharedPtr LevelEditor = LevelEditorModule.GetFirstLevelEditor();\n\n // 设置编辑器的摄像机位置和旋转\n if (EditorEngine && LevelEditor.IsValid())\n {\n // 获取当前编辑器的视口\n TSharedPtr LevelViewport = LevelEditor->GetLevelViewport();\n\n // 设置视口的位置和旋转\n if (LevelViewport.IsValid())\n {\n // 获取当前编辑器的世界\n UWorld* World = EditorEngine->GetEditorWorldContext().World();\n\n // 设置摄像机位置和旋转\n FLevelEditorViewportClient& ViewportClient = LevelViewport->GetLevelViewportClient();\n ViewportClient.SetViewLocation(Location);\n ViewportClient.SetViewRotation(FRotator::ZeroRotator);\n\n // 刷新视口\n LevelViewport->Invalidate();\n }\n }\n}\n\n// 调用JumpToLocation函数,传入要跳转的坐标\nJumpToLocation(FVector(0, 0, 0));\n\n以上代码将会把关卡编辑器窗口自动跳转到坐标(0, 0, 0)的位置。你可以根据需要修改坐标的数值。"}


原文地址: https://www.cveoy.top/t/topic/pvsd 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录