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

  • 相关阅读:
    python-并发编程之多进程
    python-继承以及继承问题和多态
    python-面向对象的命名空间和组合
    python-初识面向对象
    python-模块与包
    python-异常处理
    ios开发相关网站
    优秀Android开源项目
    知名应用背后的第三方开源项目
    贪心算法
  • 原文地址:https://www.cnblogs.com/timy/p/8683949.html
Copyright © 2020-2023  润新知