例子:创建类

2019-02-16  本文已影响0人  右腕

1.新建基类为Actor的类FloatingActor

2.修改代码(Super为宏GENERATED_BODY()产生的基类)

3.编译项目

编译完成后

4.将FloatingActor类移动到场景中生成对象

增加1个圆锥体

1.为场景中的立方体添加1个Camera组件。(取消选中后再点击)调整Camera组件的位置

2.新建基类为Actor的类CameraDirector


UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Switch Components") 

 class UPointLightComponent* PointLight1; 

 UPROPERTY(VisibleAnywhere, BlueprintReadOnly, Category="Switch Components") 

 class USphereComponent* Sphere1;

UPROPERTY(EditAnywhere, BlueprintReadWrite, Category="Switch Variables") 

 float DesiredIntensity;

C++基类,蓝图派生类:

C++和蓝图混合更多参考Exposing Gameplay Elements to Blueprints和Guidelines for Programming for Blueprints

//BlueprintNativeEvent为蓝图可以覆盖

UFUNCTION(BlueprintNativeEvent, Category="Switch Functions") 

 void OnOverlapBegin

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult); 

//蓝图不覆盖该函数时,将调用此版本的函数<function name>_Implementation()

 void OnOverlapBegin_Implementation

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

UFUNCTION(BlueprintNativeEvent, Category="Switch Functions")

{

if (OtherActor && (OtherActor != this) && OtherComp) 

    ToggleLight(); 

}

 void OnOverlapEnd

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex); 

 void OnOverlapEnd_Implementation

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

void ALightSwitchBoth::ToggleLight()

{

 PointLight1->ToggleVisibility();

}

纯C++:

UFUNCTION() 

 void OnOverlapBegin

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex, bool bFromSweep, const FHitResult& SweepResult);

UFUNCTION() 

 void OnOverlapEnd

(class UPrimitiveComponent* OverlappedComp, class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);

上一篇下一篇

猜你喜欢

热点阅读