[UE4]多播代理

1. 第一种

DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FReceiveDelegateEvent, FString, Value1, FString, Value2);

UPROPERTY(BlueprintAssignable, Category = "Event")
FReceiveDelegateEvent  ReceiveDelegateEvent;
UFUNCTION(BlueprintCallable, Category = "My|MyActor")
void BroadcastToBluePrint(FString value1, FString value2);

void AMyActor::BroadcastToBluePrint(FString value1, FString value2)
{
  this->ReceiveDelegateEvent.Broadcast(value1, value2);
}

 

2.第二种

.h

// Fill out your copyright notice in the Description page of Project Settings.  
  
#pragma once  
  
#include "UObject/NoExportTypes.h"  
#include "Kismet/BlueprintAsyncActionBase.h"  
#include "MyObject.generated.h"  
  
/** 
 *  
 */  
UCLASS()  
class TTTTT_API UMyObject : public UBlueprintAsyncActionBase  
{  
    GENERATED_BODY()  
      
public:  
  
    DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FTestDelegate, FString, Content, int32, StatusCode);  
  
    UFUNCTION(BlueprintCallable, Category = "MyObject")  
        static UMyObject* DDDelegate(FString url,  FString Content);  
  
    UPROPERTY(BlueprintAssignable)  
        FTestDelegate OnSuccess;  
  
    UPROPERTY(BlueprintAssignable)  
        FTestDelegate OnFail;  
private:  
    void DDUseDelegate(bool bSucceeded);  
};  

.cpp

// Fill out your copyright notice in the Description page of Project Settings.  
  
#include "TTTTT.h"  
#include "MyObject.h"  
  
UMyObject* UMyObject::DDDelegate(FString url, FString Content)  
{  
    UMyObject* Helper = NewObject<UMyObject>();  
  
    return Helper;  
}  
  
void UMyObject::DDUseDelegate(bool bSucceeded)  
{  
    if (bSucceeded)  
    {  
        OnSuccess.Broadcast("",0);  
    }  
    else  
    {  
        OnFail.Broadcast("", 1);  
    }  
}  

posted on 2018-03-31 19:53  一粒沙  阅读(792)  评论(0编辑  收藏  举报