https://docs.unrealengine.com/5.2/en-US/interfaces-in-unreal-engine/
1 纯c++ 接口 没有ufunction文章来源:https://www.toymoban.com/news/detail-693485.html
#pragma once
#include "CoreMinimal.h"
#include "UObject/Interface.h"
#include "ALWorldWeatherConfig.h"
#include "AL_WeatherInterface.generated.h"
// This class does not need to be modified.
UINTERFACE(MinimalAPI)
class UAL_WeatherInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class SKYCREATORPLUGIN_API IAL_WeatherInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
//纯虚函数
virtual void GetLevelWeatherPresetConfig(TSoftObjectPtr<UALWorldWeatherConfig>& PresetConfig) const = 0;
};
UCLASS()
class ABOVELAND_API AALWorldSettings : public AWorldSettings, public IAL_WeatherInterface
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AL Weather")
TSoftObjectPtr<UALWorldWeatherConfig> WeatherConfig;
//interface override 必须有override
virtual void GetLevelWeatherPresetConfig(TSoftObjectPtr<UALWorldWeatherConfig>& PresetConfig) const override;
};
//调用
if (IAL_WeatherInterface* Interface = Cast<IAL_WeatherInterface>(InWorld.GetWorldSettings()))
{
Interface->GetLevelWeatherPresetConfig(WorldWeatherConfig);
}
2 纯c++ 有ufunction文章来源地址https://www.toymoban.com/news/detail-693485.html
UINTERFACE(MinimalAPI, BlueprintType)
class UALClimbItemInterface : public UInterface
{
GENERATED_BODY()
};
/**
*
*/
class ABOVELAND_API IALClimbItemInterface
{
GENERATED_BODY()
// Add interface functions to this class. This is the class that will be inherited to implement this interface.
public:
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
void CalculateClimbItemData();
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
void CopyClimbItemData(UPARAM(ref) FClimbItemData& InOutRes,bool InOrOut);
UFUNCTION(BlueprintNativeEvent, BlueprintCallable, Category = "ALClimbItemInterface")
void ShowHook(bool IsShow);
};
UCLASS()
class ABOVELAND_API AALClimbStaticMeshActor : public AStaticMeshActor ,public IALClimbItemInterface
{
GENERATED_BODY()
public:
AALClimbStaticMeshActor();
public:
//必须带_Implementation 必须带override
void CalculateClimbItemData_Implementation() override;
void CopyClimbItemData_Implementation(FClimbItemData& InOutRes, bool InOrOut) override;
void ShowHook_Implementation(bool IsShow) override;
};
//调用
IALClimbItemInterface::Execute_CopyClimbItemData(CurClimbItemActor, ClimbItemData, false);
到了这里,关于ue5 c++ interface 接口的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!