{"id":123,"date":"2021-03-12T23:24:02","date_gmt":"2021-03-12T14:24:02","guid":{"rendered":"http:\/\/strangechu.com\/?p=123"},"modified":"2021-03-12T23:24:02","modified_gmt":"2021-03-12T14:24:02","slug":"ue4-%e5%bf%ab%e9%80%9f%e7%b9%aa%e8%a3%bd2d-3d-debug%e5%9c%96%e5%bd%a2-c","status":"publish","type":"post","link":"https:\/\/strangechu.com\/?p=123","title":{"rendered":"[UE4] \u5feb\u901f\u7e6a\u88fd2D\/3D Debug\u5716\u5f62 (C++)"},"content":{"rendered":"\n<p>UE4\u7684\u85cd\u5716\u5167\u6709\u5404\u7a2e\u65b9\u4fbf\u7684Debug\u7e6a\u88fd\u529f\u80fd\uff0c\u5728\u6b64\u6574\u7406\u5728C++\u4e2d\u4f7f\u7528\u7684\u5feb\u901f\u7e6a\u88fdDebug\u5716\u5f62\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">2D\u7e6a\u88fd:\u4f7f\u7528UDebugDrawService<\/h2>\n\n\n\n<p> \u6b64\u8655\u4ee5\u67d0\u651d\u5f71\u6a5f\u7684Actor\u70ba\u4f8b\u5b50\u3002  \u5728Class\u5167\u8ffd\u52a0FDelegateHandleCameraDebugDrawHandle\u3002 \u4e4b\u5f8c\u5c07\u5b83\u767b\u9304\u5230UDebugDrawService\u3002\u767b\u9304\u5f8c\u6bcf\u500bFrame\u6703\u547c\u53eb\u6b64\u767b\u9304\u7684\u51fd\u6578\u3002 \u5728\u51fd\u6578\u50b3\u5165\u503c\u7684Canvas\u4e0a\u76f4\u63a5\u7e6a\u88fd\u9700\u8981\u7684\u5716\u5f62\u3002 <\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>(TestCamera.h)\nclass ATestCamera : public AActor\n{\n\tGENERATED_BODY()\n\npublic:\n\tASideScrollTestCamera();\n\n\tvoid DebugDraw(UCanvas* InCanvas, APlayerController* InPC);\n\nprotected:\n\tFDelegateHandle CameraDebugDrawHandle;\n};\n<\/code><\/pre>\n\n\n\n<pre class=\"wp-block-code\"><code>(TestCamera.cpp)\n#include \"TestCamera.h\"\n#include \"Debug\/DebugDrawService.h\"\n\nASideScrollTestCamera::ATestCamera()\n{\n\tFDebugDrawDelegate DrawDebugDelegate = FDebugDrawDelegate::CreateUObject(this, &amp;TestCamera::HandleDebugDraw);\n\n\tCameraDebugDrawHandle = UDebugDrawService::Register(TEXT(\"GameplayDebug\"), DrawDebugDelegate);\n}\n\nvoid ANxPlayerCameraManager::BeginDestroy()\n{\n\tSuper::BeginDestroy();\n\t\/\/ \u7269\u4ef6\u522a\u9664\u6642\u89e3\u9664\u767b\u9304\n\tUDebugDrawService::Unregister(this->DrawDebugDelegateHandle);\n}\n\nvoid ASideScrollTestCamera::HandleDebugDraw(UCanvas* InCanvas, APlayerController* InPC)\n{\n\t\/\/ \u5728\u6b64\u7e6a\u88fdDebug\u5716\u5f62\n\tFCanvasLineItem item(FVector2D(100.f, 100.0f), FVector2D(200.f, 200.0f));\n\titem.LineThickness = 10.f;\n\titem.SetColor(FLinearColor::Red);\n\tInCanvas->DrawItem(item);\n}<\/code><\/pre>\n\n\n\n<h2 class=\"wp-block-heading\">3D\u7e6a\u88fd:\u4f7f\u7528DrawDebugHelpers <\/h2>\n\n\n\n<p>\u8acb\u53c3\u7167\u5f15\u64ce\u539f\u59cb\u78bc\u7684DrawDebugHelpers.h\u7684DrawDebugLine\u7b49\uff0cinclude\u5f8c\u76f4\u63a5\u4f7f\u7528\u5373\u53ef\u3002<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/** Draw a debug line *\/\nENGINE_API void DrawDebugLine(const UWorld* InWorld, FVector const&amp; LineStart, FVector const&amp; LineEnd, FColor const&amp; Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0, float Thickness = 0.f);\n\/** Draw a debug point *\/\nENGINE_API void DrawDebugPoint(const UWorld* InWorld, FVector const&amp; Position, float Size, FColor const&amp; PointColor, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0);\n\/** Draw directional arrow **\/\nENGINE_API void DrawDebugDirectionalArrow(const UWorld* InWorld, FVector const&amp; LineStart, FVector const&amp; LineEnd, float ArrowSize, FColor const&amp; Color, bool bPersistentLines = false, float LifeTime=-1.f, uint8 DepthPriority = 0, float Thickness = 0.f);<\/code><\/pre>\n\n\n\n<p>\u5176\u5be6\u9019\u7bc7\u4e3b\u8981\u662f\u60f3\u63d02D\u7e6a\u88fd\u3002\u4e4b\u524d\u9084\u8981\u7279\u5225\u88fd\u4f5cWidget\u4f86\u7e6a\u88fd\uff0c\u4e4b\u5f8c\u624d\u767c\u73fe\u6709\u9019\u500b\u65b9\u4fbf\u7684\u529f\u80fd\uff0c\u8b93\u7e6a\u88fd\u7684\u6d41\u7a0b\u5feb\u901f\u591a\u4e86\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>UE4\u7684\u85cd\u5716\u5167\u6709\u5404\u7a2e\u65b9\u4fbf\u7684Debug\u7e6a\u88fd\u529f\u80fd\uff0c\u5728\u6b64\u6574\u7406\u5728C++\u4e2d\u4f7f\u7528\u7684\u5feb\u901f\u7e6a\u88fdDebug\u5716\u5f62\u65b9\u6cd5\u3002 2D\u7e6a\u88fd: &hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"enabled":false},"version":2}},"categories":[1],"tags":[],"class_list":["post-123","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paZrII-1Z","_links":{"self":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/123","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=123"}],"version-history":[{"count":1,"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions"}],"predecessor-version":[{"id":124,"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/123\/revisions\/124"}],"wp:attachment":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=123"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=123"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=123"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}