ue5 c++ interface 接口

文章介绍了UnrealEngine5中如何使用纯C++接口(无UFUNCTION)和带有UFUNCTION的两种实现方式,包括`UAL_WeatherInterface`和`UALClimbItemInterface`的使用实例。
摘要由CSDN通过智能技术生成

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<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

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

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值