• 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);

  • 相关阅读:
    通过PLC网关如何实现三菱FX3U的远程上下载程序?
    代码自动化审核操作详解(svnchecker+checkstyle)
    【MFC】 前言(1)
    Linux中磁盘管理
    常用设计模式总结
    【数据分析】时间序列
    元宇宙营销面临的三大挑战
    数据结构实验之队列(文末附完整代码)
    工厂设备扫码使用售卖联网开发需要怎么开发开源代码?
    Java6种单例模式写法
  • 原文地址:https://blog.csdn.net/opk8848/article/details/132578518