{"id":64,"date":"2020-03-02T15:23:26","date_gmt":"2020-03-02T06:23:26","guid":{"rendered":"http:\/\/strangechu.com\/?p=64"},"modified":"2020-03-02T15:26:49","modified_gmt":"2020-03-02T06:26:49","slug":"ue4%e5%be%9ec%e5%91%bc%e5%8f%abblueprint%e5%af%a6%e8%a3%9d%e7%9a%84interface%e5%87%bd%e5%bc%8f","status":"publish","type":"post","link":"https:\/\/strangechu.com\/?p=64","title":{"rendered":"[UE4]\u5f9eC++\u547c\u53ebBlueprint\u5be6\u88dd\u7684interface\u51fd\u5f0f"},"content":{"rendered":"\n<h2 class=\"wp-block-heading\">\u72c0\u6cc1<\/h2>\n\n\n\n<p>\u5e73\u5e38\u5728C++\u4f7f\u7528Interface\u529f\u80fd\u6642\u7fd2\u6163\u7528Cast\u4f86\u8f49\u63db\u4f7f\u7528\u3002\u7136\u800c\u5728UE4\u60f3\u88fd\u4f5c\u5728Blueprint\u5be6\u88dd\u7684Interface\u529f\u80fd\u6642\uff0c\u537b\u767c\u73fe\u5728C++\u4e0d\u80fd\u6b63\u5e38Cast\u3002\u4ee5\u4e0b\u8aaa\u660e\u6b64\u72c0\u6cc1\u7684\u5c0d\u61c9\u65b9\u6cd5\u3002<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"> \u8aaa\u660e <\/h2>\n\n\n\n<p>\u5728C++\u5be6\u88dd\u7684Interface\uff0c\u6211\u5011\u53ef\u4ee5\u7528<strong>Cast<\/strong>\u4f86\u9032\u884c\u8f49\u63db\u4f7f\u7528\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>IMyInterface MyInterface = Cast&lt;IMyInterface>(ActorInstance);\nif (MyInterface)\n{\n  \/\/ Other code\n}<\/code><\/pre>\n\n\n\n<p>\u7136\u800c\uff0c\u5982\u679c\u8a72Actor\u7684Interface\u5be6\u88dd\u65b9\u6cd5\u4e0d\u662f\u5728C++\uff0c\u800c\u662f\u5728Blueprint\u5b9a\u7fa9\u7684\u8a71\uff0cCast\u5c07\u6703\u5931\u6557\uff0c\u7531\u65bcC++\u5c64\u4e2d\u8a72Actor\u4e26\u6c92\u6709\u5be6\u88dd\u8a72Interface\u3002\u5728\u9019\u88e1\u8981\u4f7f\u7528<strong>ImplementsInterface<\/strong>\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (ActorInstance->GetClass()->\n  ImplementsInterface(UMyInterface::StaticClass()))\n{\n  \/\/ Other code\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u6b64\u6211\u5011\u6210\u529f\u5224\u65b7\u4e86\u8a72Actor\u662f\u5426\u5be6\u88dd\u4e86\u8a72Interface\u3002\u4f46\u662f\u6211\u5011\u4f9d\u7136\u4e0d\u80fdCast\uff01\u90a3\u8a72\u5982\u4f55\u547c\u53ebInterface\u7684\u51fd\u5f0f\u5462\uff1f\u5047\u8a2d\u6211\u5011\u7684IMyInterface.h\u5b9a\u7fa9\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>#include \"UObject\/Interface.h\"\n#include \"IMyInterface.generated.h\"\n\nUINTERFACE()\nclass THIRDPERSON_API UMyInterface : public UInterface\n{\n\tGENERATED_BODY()\n};\n\n\nclass THIRDPERSON_API IMyInterface\n{\n\tGENERATED_BODY()\n\npublic:\n\tUFUNCTION(BlueprintCallable, BlueprintNativeEvent)\n\tvoid DoSomething();\n};<\/code><\/pre>\n\n\n\n<p>DoSomething() \u70ba\u6211\u5011\u60f3\u547c\u53eb\u7684\u51fd\u5f0f\u3002\u7531\u65bc\u6211\u5011\u5e0c\u671b\u5be6\u88dd\u5728Blueprint\uff0c\u6240\u4ee5\u5ba3\u544a\u70baBlueprintNativeEvent\u3002\u5982\u679c\u5728C++\u8981\u547c\u53eb\u6b64\u51fd\u5f0f\uff0c\u5fc5\u9808\u4f7f\u7528Static\u7248\u672c\u7684\u51fd\u5f0f\uff0c\u547c\u53eb\u4f8b\u5b50\u5982\u4e0b\uff1a<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>if (ActorInstance->GetClass()->\n  ImplementsInterface(UMyInterface::StaticClass()))\n{\n  IMyInterface::Execute_MyInterfaceFunction(ActorInstance);\n}<\/code><\/pre>\n\n\n\n<p>\u5982\u6b64\u5c31\u80fd\u6210\u529f\u547c\u53eb\u5728Blueprint\u5be6\u88dd\u7684Interface\u51fd\u5f0f\u4e86\uff01<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">\u53c3\u8003\u8cc7\u6599<\/h2>\n\n\n\n<p><a href=\"https:\/\/wiki.unrealengine.com\/Interfaces_And_Blueprints\">https:\/\/wiki.unrealengine.com\/Interfaces_And_Blueprints<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u72c0\u6cc1 \u5e73\u5e38\u5728C++\u4f7f\u7528Interface\u529f\u80fd\u6642\u7fd2\u6163\u7528Cast\u4f86\u8f49\u63db\u4f7f\u7528\u3002\u7136\u800c\u5728UE4\u60f3\u88fd\u4f5c\u5728Blueprint &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":[4,2],"tags":[],"class_list":["post-64","post","type-post","status-publish","format-standard","hentry","category-ue4","category-2"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/paZrII-12","_links":{"self":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/64","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=64"}],"version-history":[{"count":1,"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions"}],"predecessor-version":[{"id":65,"href":"https:\/\/strangechu.com\/index.php?rest_route=\/wp\/v2\/posts\/64\/revisions\/65"}],"wp:attachment":[{"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=64"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=64"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/strangechu.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=64"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}