ue5 c++ interface 接口

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

1 纯c++ 接口  没有ufunction

#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& PresetConfig) const = 0;
};



UCLASS()
class ABOVELAND_API AALWorldSettings : public AWorldSettings, public IAL_WeatherInterface
{
	GENERATED_BODY()
public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "AL Weather")
	TSoftObjectPtr WeatherConfig;

	//interface override 必须有override
	virtual void GetLevelWeatherPresetConfig(TSoftObjectPtr& PresetConfig) const override;

};



//调用

		if (IAL_WeatherInterface* Interface = Cast(InWorld.GetWorldSettings()))
		{
			Interface->GetLevelWeatherPresetConfig(WorldWeatherConfig);
		}

2 纯c++ 有ufunction

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)