美文网首页
例子:创建类

例子:创建类

作者: 右腕 | 来源:发表于2019-02-16 19:42 被阅读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);

    相关文章

      网友评论

          本文标题:例子:创建类

          本文链接:https://www.haomeiwen.com/subject/ojeieqtx.html