{"id":412,"date":"2018-03-27T22:31:27","date_gmt":"2018-03-27T14:31:27","guid":{"rendered":"http:\/\/sirokuma.cc\/?p=412"},"modified":"2018-03-27T22:54:42","modified_gmt":"2018-03-27T14:54:42","slug":"ue4-%e5%ad%a6%e4%b9%a0%e7%ac%94%e8%ae%b0%e4%b9%8b%e4%b8%80","status":"publish","type":"post","link":"https:\/\/sirokuma.cc\/?p=412","title":{"rendered":"UE4 &#8211; \u5b66\u4e60\u7b14\u8bb0\u4e4b\u4e00"},"content":{"rendered":"<p>\u5148\u8d34\u4e0a\u539f\u6587\uff1a<a href=\"http:\/\/api.unrealengine.com\/CHN\/Gameplay\/ClassCreation\/CodeOnly\/index.html\">\u4f7f\u7528\u00a0C++\u7c7b\u5411\u5bfc\u00a0\u521b\u5efa\u00a0<strong>LightSwitchCodeOnly<\/strong>\u00a0\u7c7b<\/a><\/p>\n<p>\u5b66\u4e60\u4f7f\u7528\u4e2d\u5b8c\u5168\u6709\u95ee\u9898\uff1a\u539f\u56e0\u53ef\u80fd\u662f\u6587\u6863\u592a\u65e7\uff0c\u66f4\u65b0\u9891\u7e41\u4e5f\u53ef\u80fdUE4\u5b98\u65b9\u5e76\u4e0d\u91cd\u89c6C++<\/p>\n<p>\u4e0d\u8fc7\u84dd\u56fe\u7684\u786e\u65b9\u4fbf\uff0c\u4f46\u6bd5\u7adfC++\u624d\u662f\u672c\u8d28\uff0c\u8fd8\u662f\u6709\u5fc5\u8981\u4e86\u89e3\u7684<\/p>\n<p>\u4e0d\u591a\u8bf4\u5e9f\u8bdd\u4e86&#8230;\u4e0b\u9762\u662f\u6211\u9047\u5230\u7684\u95ee\u9898\u4ee5\u53ca\u76f8\u5bf9\u7684\u89e3\u51b3\u65b9\u6cd5\u3010\u6211\u4f7f\u7528\u7684\u662f4.18.3\u3011<\/p>\n<p>\u9996\u5148\uff0c\u5f53\u6211\u5df2\u7ecf\u5b8c\u6210\u4e86\u4ec5\u4f7f\u7528\u84dd\u56fe\u5b8c\u6210\u8fd9\u4e2a\u53ef\u5f00\u5173\u706f\u7684\u7c7b\u65f6\uff0c\u5df2\u7ecf\u8feb\u4e0d\u53ca\u5f85\u60f3\u8981\u5c1d\u8bd5\u4f7f\u7528C++\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1<\/p>\n<p>\u7b2c\u4e00\u6b21\u4f7f\u7528\u53d1\u73b0\u8fd9\u4e2a\u7f16\u7801\u7684\u786e\u4e0e\u4f17\u4e0d\u540c\uff08\u4e0eUnity3D\u76f8\u6bd4\uff09<\/p>\n<p>\u6bd4\u5982<\/p>\n<pre class=\"prettyprint prettyprinted\"><code><span class=\"pln\">UCLASS<\/span><span class=\"pun\">()<\/span><\/code><\/pre>\n<p>\u8fd9\u6837\u7684\u5b8f&#8230;\u7b49\u7b49\uff0c\u8fd9\u88ab\u79f0\u4e3a\u53cd\u5c04\u673a\u5236\uff0c\u4e0e\u4e4b\u76f8\u5173\u7684\u66f4\u591a\u7684\u8d44\u6599\u8bf7\u53c2\u8003\u6b64\u6587\u7ae0\u7ed3\u5c3e\u7684\u53c2\u8003<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-413\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_1-300x197.jpg\" alt=\"\" width=\"1120\" height=\"734\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_1-300x197.jpg 300w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_1-768x504.jpg 768w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_1-1024x671.jpg 1024w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_1.jpg 1336w\" sizes=\"(max-width: 1120px) 100vw, 1120px\" \/><\/p>\n<p>\u4ee5\u4e0a\u5373\u4e3a\u5b98\u65b9\u6587\u6863\u4e2d\u7684\u8bf4\u660e\u3002\u3010\u6ce8\u610f\uff1a\u5728\u4e00\u5207\u95ee\u9898\u7684\u5f00\u59cb\u4e00\u5b9a\u8981\u5148\u68c0\u67e5\u62fc\u5199\u9519\u8bef&#8230;\u8840\u7684\u6559\u8bad\u3011<\/p>\n<p>\u4e5f\u8bb8\u4f60\u7684Visual Studio\u5e76\u4e0d\u80fd\u597d\u597d\u5730\u5de5\u4f5c\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u7684\u5efa\u8bae\uff1a <a href=\"http:\/\/api.unrealengine.com\/CHN\/Programming\/Development\/VisualStudioSetup\/index.html\">\u4e3a\u865a\u5e7b 4 \u8bbe\u7f6e Visual Studio<\/a><\/p>\n<p>\u5f53\u7136\uff0c\u4e5f\u6709XCode\u7684\u76f8\u5173\u914d\u7f6e\u6307\u5bfc\u3002 \u4f46\u662f\u5373\u4f7f\u6211\u8ddf\u7740\u6307\u5bfc\u5b8c\u6210\u4e86\u8bbe\u7f6e\uff0c\u4f3c\u4e4e\u5e76\u6ca1\u6709\u6211\u60f3\u8c61\u4e2d\u7684\u90a3\u6837\u5b8c\u7f8e.<\/p>\n<h2>\u95ee\u9898\u4e00\uff1a<\/h2>\n<p><code>#include \"Components\/PointLightComponent.h\"<\/code><\/p>\n<p><code>#include \"Components\/SphereComponent.h\"<\/code><\/p>\n<p>\u6ca1\u9519\uff0c\u6211\u65e9\u8be5\u60f3\u5230\u7684\uff1a\u4e5f\u8bb8\u662f\u8fd9\u4e2a\u539f\u56e0\uff0c\u8fd9\u4e2a\u7ec4\u4ef6\u6ca1\u6709\u88abinclude \u8fd9\u5c31\u662f\u4e0e\u5b83\u4eec\u76f8\u5173\u7684\u79cd\u79cd\u9519\u8bef\u7684\u6839\u6e90<\/p>\n<p><code>class UPointLightComponent* PointLight1;<\/code><\/p>\n<p><code> class USphereComponent* Sphere1;<\/code><\/p>\n<p>\u8bf7\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230LightSwitchCodeOnly.h\u4e2d<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-414 size-full\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_2.jpg\" alt=\"\" width=\"793\" height=\"429\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_2.jpg 793w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_2-300x162.jpg 300w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_2-768x415.jpg 768w\" sizes=\"(max-width: 793px) 100vw, 793px\" \/><\/p>\n<h2>\u95ee\u9898\u4e8c\uff1a<\/h2>\n<p>LightSwitchCodeOnly.h\u4e2d\uff1a<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-417\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_5-300x30.jpg\" alt=\"\" width=\"1120\" height=\"111\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_5-300x30.jpg 300w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_5-768x76.jpg 768w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_5-1024x102.jpg 1024w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_5.jpg 1391w\" sizes=\"(max-width: 1120px) 100vw, 1120px\" \/><\/p>\n<p><code>UFUNCTION()<\/code><br \/>\n<code> \/\/void OnOverlapBegin(class AActor* otherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool BFromSweep, const FHitResult&amp; SweepResult);<\/code><br \/>\n<code> void OnOverlapBegin(class UPrimitiveComponent* HitComp,class AActor* otherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool BFromSweep, const FHitResult&amp; SweepResult);<\/code><\/p>\n<p><code>UFUNCTION()<\/code><br \/>\n<code> \/\/void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);<\/code><br \/>\n<code> void OnOverlapEnd(class UPrimitiveComponent* HitComp,class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);<\/code><\/p>\n<p>LightSwitchCodeOnly.cpp\u4e2d\uff1a<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-418 size-full\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_6.jpg\" alt=\"\" width=\"803\" height=\"86\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_6.jpg 803w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_6-300x32.jpg 300w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_6-768x82.jpg 768w\" sizes=\"(max-width: 803px) 100vw, 803px\" \/><\/p>\n<p><code> Sphere1-&gt;OnComponentBeginOverlap.AddDynamic(this, &amp;ALightSwitchCodeOnly::OnOverlapBegin);<\/code><br \/>\n<code> Sphere1-&gt;OnComponentEndOverlap.AddDynamic(this, &amp;ALightSwitchCodeOnly::OnOverlapEnd);<\/code><\/p>\n<p>&nbsp;<\/p>\n<p>\u5982\u679c\u5b8c\u5168\u6309\u7167\u6587\u6863\u4e2d\u6240\u8bf4\u7684\u90a3\u6837\u4e00\u5b9a\u4f1a\u7f16\u8bd1\u9519\u8bef\uff1a\u5f53\u524dAddDynamic\uff08\uff09\u53c2\u6570\u53d1\u751f\u4e86\u53d8\u5316\uff0c\u6b63\u5982\u4e0b\u9762\u7f16\u8bd1\u5668\u63d0\u793a\u7684\u9519\u8bef\u5185\u5bb9\u7684\u90a3\u6837<\/p>\n<p><code>1&gt;C:\\Users\\admin\\Documents\\Unreal Projects\\first\\Source\\first\\LightSwitchCodeOnly.cpp(24): error C2664: \u201cvoid TBaseDynamicMulticastDelegate&lt;FWeakObjectPtr,void,UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &amp;&gt;::__Internal_AddDynamic&lt;ALightSwitchCodeOnly&gt;(UserClass *,void (__cdecl ALightSwitchCodeOnly::* )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &amp;),FName)\u201d: \u65e0\u6cd5\u5c06\u53c2\u6570 2 \u4ece\u201cvoid (__cdecl ALightSwitchCodeOnly::* )(AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &amp;)\u201d\u8f6c\u6362\u4e3a\u201cvoid (__cdecl ALightSwitchCodeOnly::* )(UPrimitiveComponent *,AActor *,UPrimitiveComponent *,int32,bool,const FHitResult &amp;)\u201d<\/code><br \/>\n<code>1&gt; with<\/code><br \/>\n<code>1&gt; [<\/code><br \/>\n<code>1&gt; UserClass=ALightSwitchCodeOnly<\/code><br \/>\n<code>1&gt; ]<\/code><br \/>\n<code>1&gt; C:\\Users\\admin\\Documents\\Unreal Projects\\first\\Source\\first\\LightSwitchCodeOnly.cpp(24): note: \u4e0e\u6307\u5411\u7684\u7c7b\u578b\u65e0\u5173\uff1b\u8f6c\u6362\u8981\u6c42 reinterpret_cast\u3001C \u6837\u5f0f\u8f6c\u6362\u6216\u51fd\u6570\u6837\u5f0f\u8f6c\u6362<\/code><\/p>\n<pre class=\"prettyprint prettyprinted\">\u95ee\u9898\u7684\u89e3\u51b3\u5e94\u5728LightSwitchCodeOnly.h\u4e2d<\/pre>\n<p>\u5728<code>OnOverlapBegin<\/code>\u548c<code>OnOverlapEnd<\/code>\u7684\u58f0\u660e\u4e2d\u6dfb\u52a0\u4e00\u4e2a\u65b0\u7684\u53c2\u6570<\/p>\n<p><code>class UPrimitiveComponent* HitComp<\/code>\u867d\u7136\u6211\u5e76\u4e0d\u77e5\u9053\u8fd9\u4e2a\u53c2\u6570\u662f\u5e72\u5565\u7684&#8230;<\/p>\n<p>\u4e0d\u8fc7\u73b0\u5728AddDynamic\u5c31\u6ca1\u95ee\u9898\u4e86<\/p>\n<h2>\u95ee\u9898\u4e09\uff1a<\/h2>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-415 size-full\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_3.jpg\" alt=\"\" width=\"767\" height=\"86\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_3.jpg 767w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_3-300x34.jpg 300w\" sizes=\"(max-width: 767px) 100vw, 767px\" \/><br \/>\n\u88ab\u6211\u6ce8\u91ca\u7684\u662f\u539f\u672c\u9519\u8bef\u7684\u8bed\u6cd5 \u56e0\u4e3a\u5b83\u4f1a\u5f97\u5230\u4ee5\u4e0b\u7f16\u8bd1\u7ed3\u679c\uff1a<\/p>\n<p><img loading=\"lazy\" class=\"alignnone wp-image-416\" src=\"http:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_4.jpg\" alt=\"\" width=\"1120\" height=\"30\" srcset=\"https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_4.jpg 1160w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_4-300x8.jpg 300w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_4-768x21.jpg 768w, https:\/\/sirokuma.cc\/wp-content\/uploads\/2018\/03\/ue4_1_4-1024x27.jpg 1024w\" sizes=\"(max-width: 1120px) 100vw, 1120px\" \/><br \/>\n\u8fd9\u4f3c\u4e4e\u53c8\u662f\u4e00\u4e2a\u66f4\u65b0\uff0c\u4e0d\u8fc7\u6211\u627e\u5230\u4e86\u53ef\u4ee5\u4ee3\u66ff\u7684\u5b9e\u73b0\uff1a<br \/>\n<code>Sphere1-&gt;AttachTo(RootComponent);<\/code><br \/>\n\u770b\u6765\u4ee5\u524dUE4\u4e2dAttachParent\u76f4\u63a5\u662f\u66b4\u9732\u7684&#8230;<\/p>\n<p>\u4ee5\u4e0a\u5927\u6982\u5df2\u7ecf\u53ef\u4ee5\u5305\u542b\u8fd9\u4e2a\u6587\u6863\u4e2d\u4e0e\u5f53\u524due4\u7248\u672c\u6240\u6709\u7684\u51b2\u7a81\u4e86 \u6700\u540e\u8d34\u4e0a\u6240\u6709\u7684\u4ee3\u7801\uff1a<\/p>\n<p>&nbsp;<\/p>\n<hr \/>\n<p><strong>LightSwitchCodeOnly.h:<br \/>\n<\/strong><br \/>\n<code>\/\/ Fill out your copyright notice in the Description page of Project Settings.<\/code><br \/>\n<code>#pragma once<\/code><\/p>\n<p><code>#include \"CoreMinimal.h\"<\/code><br \/>\n<code>#include \"GameFramework\/Actor.h\"<\/code><br \/>\n<code>#include \"Components\/PointLightComponent.h\"<\/code><br \/>\n<code>#include \"Components\/SphereComponent.h\"<\/code><br \/>\n<code>#include \"LightSwitchCodeOnly.generated.h\"<\/code><\/p>\n<p><code>UCLASS()<\/code><br \/>\n<code>\/\/\u4f7f\u7528UCLASS\u5b8f\u8fdb\u884c\u5904\u7406\uff0c\u4f7f\u5f97\u5f15\u64ce\u610f\u8bc6\u5230\u6b64\u7c7b\u7684\u5b58\u5728<\/code><br \/>\n<code>\/\/\u7c7b\u4f3c\u7684\u5b8f\u6709UPROPERTY()UPFUNCTION()\u8fdb\u884c\u5904\u7406\u53d8\u91cf\u548c\u5c5e\u6027<\/code><br \/>\n<code>class FIRST_API ALightSwitchCodeOnly : public AActor<\/code><br \/>\n<code>{<\/code><br \/>\n<code> GENERATED_BODY()<\/code><\/p>\n<p><code>public: <\/code><\/p>\n<p><code> \/\/class UPointLightComponent* PointLight1;<\/code><br \/>\n<code> \/\/class USphereComponent* Sphere1;<\/code><\/p>\n<p><code>\/\/ Sets default values for this actor's properties<\/code><br \/>\n<code> ALightSwitchCodeOnly(const FObjectInitializer&amp; ObjectInitializer);<\/code><br \/>\n<code> UPROPERTY(VisibleAnyWhere, Category = \"Switch Components\")<\/code><br \/>\n<code> class UPointLightComponent* PointLight1;<\/code><\/p>\n<p><code>UPROPERTY(VisibleAnyWhere, Category = \"Switch Components\")<\/code><br \/>\n<code> class USphereComponent* Sphere1;<\/code><\/p>\n<p><code>UFUNCTION()<\/code><br \/>\n<code> \/\/void OnOverlapBegin(class AActor* otherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool BFromSweep, const FHitResult&amp; SweepResult);<\/code><br \/>\n<code> void OnOverlapBegin(class UPrimitiveComponent* HitComp,class AActor* otherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool BFromSweep, const FHitResult&amp; SweepResult);<\/code><\/p>\n<p><code>UFUNCTION()<\/code><br \/>\n<code> \/\/void OnOverlapEnd(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);<\/code><br \/>\n<code> void OnOverlapEnd(class UPrimitiveComponent* HitComp,class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);<\/code><\/p>\n<p><code>UFUNCTION()<\/code><br \/>\n<code> void ToggleLight();<\/code><\/p>\n<p><code>UPROPERTY(VisibleAnywhere, Category = \"Switch Variables\")<\/code><br \/>\n<code> float DesiredIntensity;<\/code><br \/>\n<code>protected:<\/code><br \/>\n<code> \/\/ Called when the game starts or when spawned<\/code><br \/>\n<code> virtual void BeginPlay() override;<\/code><\/p>\n<p><code>public: <\/code><br \/>\n<code> \/\/ Called every frame<\/code><br \/>\n<code> virtual void Tick(float DeltaTime) override;<\/code><\/p>\n<p><code>};<\/code><\/p>\n<hr \/>\n<pre class=\"prettyprint prettyprinted\"><strong>LightSwitchCodeOnly.cpp:<\/strong>\r\n<\/pre>\n<p><code>#include \"LightSwitchCodeOnly.h\"<\/code><br \/>\n<code>\/\/ Sets default values<\/code><br \/>\n<code>ALightSwitchCodeOnly::ALightSwitchCodeOnly(const FObjectInitializer&amp; ObjectInitializer)<\/code><br \/>\n<code> :Super(ObjectInitializer)<\/code><br \/>\n<code>{<\/code><br \/>\n<code> \/\/ Set this actor to call Tick() every frame. You can turn this off to improve performance if you don't need it.<\/code><br \/>\n<code> PrimaryActorTick.bCanEverTick = true;<\/code><br \/>\n<code> DesiredIntensity = 3000.0f;<\/code><\/p>\n<p><code>PointLight1 = ObjectInitializer.CreateDefaultSubobject&lt;UPointLightComponent&gt;(this, \"PointLight1\");<\/code><br \/>\n<code> PointLight1-&gt;Intensity = DesiredIntensity;<\/code><br \/>\n<code> PointLight1-&gt;bVisible = true;<\/code><br \/>\n<code> RootComponent = PointLight1;<\/code><\/p>\n<p><code>Sphere1 = ObjectInitializer.CreateDefaultSubobject&lt;USphereComponent&gt;(this, TEXT(\"Sphere1\"));<\/code><br \/>\n<code> Sphere1-&gt;InitSphereRadius(250.0f);<\/code><br \/>\n<code> \/\/Sphere1-&gt;AttachParent = RootComponent;<\/code><br \/>\n<code> Sphere1-&gt;AttachTo(RootComponent);<\/code><\/p>\n<p><code>\/\/\u76f8\u5f53\u4e8e\u6ce8\u518c\u56de\u8c03\u51fd\u6570\uff0c\u6587\u6863\u4e2d\u8bf4\u660e\u4e3a\u8bbe\u7f6e\u901a\u77e5\uff0c\u4f7f\u7528\u4ee3\u7406\u51fd\u6570 <\/code><br \/>\n<code> Sphere1-&gt;OnComponentBeginOverlap.AddDynamic(this, &amp;ALightSwitchCodeOnly::OnOverlapBegin);<\/code><br \/>\n<code> Sphere1-&gt;OnComponentEndOverlap.AddDynamic(this, &amp;ALightSwitchCodeOnly::OnOverlapEnd);<\/code><br \/>\n<code>}<\/code><\/p>\n<p><code>void ALightSwitchCodeOnly::OnOverlapBegin(class UPrimitiveComponent* HitComp,class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult&amp; SweepResult)<\/code><br \/>\n<code>{<\/code><br \/>\n<code> if (OtherActor &amp;&amp; (OtherActor != this) &amp;&amp; OtherComp)<\/code><br \/>\n<code> {<\/code><br \/>\n<code> ToggleLight();<\/code><br \/>\n<code> }<\/code><br \/>\n<code>}<\/code><\/p>\n<p><code>void ALightSwitchCodeOnly::OnOverlapEnd(class UPrimitiveComponent* HitComp,class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex)<\/code><br \/>\n<code>{<\/code><br \/>\n<code> if (OtherActor &amp;&amp; (OtherActor != this) &amp;&amp; OtherComp)<\/code><br \/>\n<code> {<\/code><br \/>\n<code> ToggleLight();<\/code><br \/>\n<code> }<\/code><br \/>\n<code>}<\/code><\/p>\n<p><code>void ALightSwitchCodeOnly::ToggleLight()<\/code><br \/>\n<code>{<\/code><br \/>\n<code> PointLight1-&gt;ToggleVisibility();<\/code><br \/>\n<code>}<\/code><br \/>\n<code>\/\/ Called when the game starts or when spawned<\/code><br \/>\n<code>void ALightSwitchCodeOnly::BeginPlay()<\/code><br \/>\n<code>{<\/code><br \/>\n<code> Super::BeginPlay();<\/code><\/p>\n<p><code>}<\/code><\/p>\n<p><code>\/\/ Called every frame<\/code><br \/>\n<code>void ALightSwitchCodeOnly::Tick(float DeltaTime)<\/code><br \/>\n<code>{<\/code><br \/>\n<code> Super::Tick(DeltaTime);<\/code><\/p>\n<p><code>}<\/code><\/p>\n<pre class=\"prettyprint prettyprinted\">\u53c2\u8003\uff1a<\/pre>\n<pre class=\"csdn_top\"><a href=\"https:\/\/blog.csdn.net\/u012999985\/article\/details\/52902065\">UE4\u53cd\u5c04\u7cfb\u7edf\u7b80\u6790\uff08\u542b\u5b9e\u4f8b\u8fc7\u7a0b\u5206\u6790\uff09<\/a><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>\u5148\u8d34\u4e0a\u539f\u6587\uff1a\u4f7f\u7528\u00a0C++\u7c7b\u5411\u5bfc\u00a0\u521b\u5efa\u00a0LightSwitchCodeOnly\u00a0\u7c7b \u5b66\u4e60\u4f7f\u7528\u4e2d\u5b8c\u5168\u6709\u95ee\u9898\uff1a\u539f\u56e0\u53ef\u80fd\u662f\u6587\u6863\u592a\u65e7\uff0c\u66f4\u65b0\u9891\u7e41\u4e5f\u53ef\u80fdUE4\u5b98\u65b9\u5e76\u4e0d\u91cd\u89c6C++ \u4e0d\u8fc7\u84dd\u56fe\u7684\u786e\u65b9\u4fbf\uff0c\u4f46\u6bd5\u7adfC++\u624d\u662f\u672c\u8d28\uff0c\u8fd8\u662f\u6709\u5fc5\u8981\u4e86\u89e3\u7684 \u4e0d\u591a\u8bf4\u5e9f\u8bdd\u4e86&#8230;\u4e0b\u9762\u662f\u6211\u9047\u5230\u7684\u95ee\u9898\u4ee5\u53ca\u76f8\u5bf9\u7684\u89e3\u51b3\u65b9\u6cd5\u3010\u6211\u4f7f\u7528\u7684\u662f4.18.3\u3011 \u9996\u5148\uff0c\u5f53\u6211\u5df2\u7ecf\u5b8c\u6210\u4e86\u4ec5\u4f7f\u7528\u84dd\u56fe\u5b8c\u6210\u8fd9\u4e2a\u53ef\u5f00\u5173\u706f\u7684\u7c7b\u65f6\uff0c\u5df2\u7ecf\u8feb\u4e0d\u53ca\u5f85\u60f3\u8981\u5c1d\u8bd5\u4f7f\u7528C++\u5b8c\u6210\u8fd9\u4e2a\u4efb\u52a1 \u7b2c\u4e00\u6b21\u4f7f\u7528\u53d1\u73b0\u8fd9\u4e2a\u7f16\u7801\u7684\u786e\u4e0e\u4f17\u4e0d\u540c\uff08\u4e0eUnity3D\u76f8\u6bd4\uff09 \u6bd4\u5982 UCLASS() \u8fd9\u6837\u7684\u5b8f&#8230;\u7b49\u7b49\uff0c\u8fd9\u88ab\u79f0\u4e3a\u53cd\u5c04\u673a\u5236\uff0c\u4e0e\u4e4b\u76f8\u5173\u7684\u66f4\u591a\u7684\u8d44\u6599\u8bf7\u53c2\u8003\u6b64\u6587\u7ae0\u7ed3\u5c3e\u7684\u53c2\u8003 \u4ee5\u4e0a\u5373\u4e3a\u5b98\u65b9\u6587\u6863\u4e2d\u7684\u8bf4\u660e\u3002\u3010\u6ce8\u610f\uff1a\u5728\u4e00\u5207\u95ee\u9898\u7684\u5f00\u59cb\u4e00\u5b9a\u8981\u5148\u68c0\u67e5\u62fc\u5199\u9519\u8bef&#8230;\u8840\u7684\u6559\u8bad\u3011 \u4e5f\u8bb8\u4f60\u7684Visual Studio\u5e76\u4e0d\u80fd\u597d\u597d\u5730\u5de5\u4f5c\uff0c\u4f60\u53ef\u4ee5\u53c2\u8003\u5b98\u65b9\u7684\u5efa\u8bae\uff1a \u4e3a\u865a\u5e7b 4 \u8bbe\u7f6e Visual Studio \u5f53\u7136\uff0c\u4e5f\u6709XCode\u7684\u76f8\u5173\u914d\u7f6e\u6307\u5bfc\u3002 \u4f46\u662f\u5373\u4f7f\u6211\u8ddf\u7740\u6307\u5bfc\u5b8c\u6210\u4e86\u8bbe\u7f6e\uff0c\u4f3c\u4e4e\u5e76\u6ca1\u6709\u6211\u60f3\u8c61\u4e2d\u7684\u90a3\u6837\u5b8c\u7f8e. \u95ee\u9898\u4e00\uff1a #include &#8220;Components\/PointLightComponent.h&#8221; #include &#8220;Components\/SphereComponent.h&#8221; \u6ca1\u9519\uff0c\u6211\u65e9\u8be5\u60f3\u5230\u7684\uff1a\u4e5f\u8bb8\u662f\u8fd9\u4e2a\u539f\u56e0\uff0c\u8fd9\u4e2a\u7ec4\u4ef6\u6ca1\u6709\u88abinclude \u8fd9\u5c31\u662f\u4e0e\u5b83\u4eec\u76f8\u5173\u7684\u79cd\u79cd\u9519\u8bef\u7684\u6839\u6e90 class UPointLightComponent* PointLight1; class USphereComponent* Sphere1; \u8bf7\u5c06\u5b83\u4eec\u6dfb\u52a0\u5230LightSwitchCodeOnly.h\u4e2d \u95ee\u9898\u4e8c\uff1a LightSwitchCodeOnly.h\u4e2d\uff1a UFUNCTION() \/\/void OnOverlapBegin(class AActor* otherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool BFromSweep, const FHitResult&amp; SweepResult); void OnOverlapBegin(class UPrimitiveComponent* HitComp,class AActor*&#8230;.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[10],"tags":[],"_links":{"self":[{"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/posts\/412"}],"collection":[{"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=412"}],"version-history":[{"count":5,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/posts\/412\/revisions"}],"predecessor-version":[{"id":423,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=\/wp\/v2\/posts\/412\/revisions\/423"}],"wp:attachment":[{"href":"https:\/\/sirokuma.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=412"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=412"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/sirokuma.cc\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=412"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}