• ue5 c++ interface 接口


    https://docs.unrealengine.com/5.2/en-US/interfaces-in-unreal-engine/

    1 纯c++ 接口  没有ufunction

    1. #pragma once
    2. #include "CoreMinimal.h"
    3. #include "UObject/Interface.h"
    4. #include "ALWorldWeatherConfig.h"
    5. #include "AL_WeatherInterface.generated.h"
    6. // This class does not need to be modified.
    7. UINTERFACE(MinimalAPI)
    8. class UAL_WeatherInterface : public UInterface
    9. {
    10. GENERATED_BODY()
    11. };
    12. /**
    13. *
    14. */
    15. class SKYCREATORPLUGIN_API IAL_WeatherInterface
    16. {
    17. GENERATED_BODY()
    18. // Add interface functions to this class. This is the class that will be inherited to implement this interface.
    19. public:
    20. //纯虚函数
    21. virtual void GetLevelWeatherPresetConfig(TSoftObjectPtr& PresetConfig) const = 0;
    22. };
    23. UCLASS()
    24. class ABOVELAND_API AALWorldSettings : public AWorldSettings, public IAL_WeatherInterface
    25. {
    26. GENERATED_BODY()
    27. public:
    28. UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AL Weather")
    29. TSoftObjectPtr WeatherConfig;
    30. //interface override 必须有override
    31. virtual void GetLevelWeatherPresetConfig(TSoftObjectPtr& PresetConfig) const override;
    32. };
    33. //调用
    34. if (IAL_WeatherInterface* Interface = Cast(InWorld.GetWorldSettings()))
    35. {
    36. Interface->GetLevelWeatherPresetConfig(WorldWeatherConfig);
    37. }

    2 纯c++ 有ufunction

    1. UINTERFACE(MinimalAPI, BlueprintType)
    2. class UALClimbItemInterface : public UInterface
    3. {
    4. GENERATED_BODY()
    5. };
    6. /**
    7. *
    8. */
    9. class ABOVELAND_API IALClimbItemInterface
    10. {
    11. GENERATED_BODY()
    12. // Add interface functions to this class. This is the class that will be inherited to implement this interface.
    13. public:
    14. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
    15. void CalculateClimbItemData();
    16. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
    17. void CopyClimbItemData(UPARAM(ref) FClimbItemData& InOutRes,bool InOrOut);
    18. UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
    19. void ShowHook(bool IsShow);
    20. };
    21. UCLASS()
    22. class ABOVELAND_API AALClimbStaticMeshActor : public AStaticMeshActor ,public IALClimbItemInterface
    23. {
    24. GENERATED_BODY()
    25. public:
    26. AALClimbStaticMeshActor();
    27. public:
    28. //必须带_Implementation 必须带override
    29. void CalculateClimbItemData_Implementation() override;
    30. void CopyClimbItemData_Implementation(FClimbItemData& InOutRes, bool InOrOut) override;
    31. void ShowHook_Implementation(bool IsShow) override;
    32. };
    33. //调用
    34. IALClimbItemInterface::Execute_CopyClimbItemData(CurClimbItemActor, ClimbItemData, false);

  • 相关阅读:
    Linux 指令心法(十二)`rm` 永久性地删除文件或目录
    蓝桥杯实战应用【算法代码篇】-小朋友崇拜圈(附Java、Python和C++代码)
    Gorm 中的钩子和回调
    C++:多态
    this指向详解
    编译原理龙书-词法分析
    【编程题】【Scratch三级】2021.09 接红包游戏
    Octave安装
    c strtok和strtok_s
    ROS Action通信
  • 原文地址:https://blog.csdn.net/opk8848/article/details/132578518