1.c++定义多播委托,示例代码:
- #include "Delegates/Delegate.h"
-
- //注意:若创建的是全局的VM,则在所有的VM中这里的第一个参数类型名称都不能有重复,否则可能编译不通过
- DECLARE_DYNAMIC_MULTICAST_DELEGATE_OneParam(FMyDelegate, UObject*, SelectAgent);
-
- /**
- *
- */
- UCLASS(Blueprintable, DisplayName = "VM_PlaceEntity")
- class PR_PLACEENTITY_MODEL_API UVM_PlaceEntity : public UMVVMViewModelBase
- {
- GENERATED_BODY()
-
- public:
- UPROPERTY(BlueprintReadWrite, FieldNotify, Setter, Getter)
- UObject* SelectAgent;
-
- UPROPERTY(BlueprintAssignable, Category = "VM_PlaceEntity")
- FMyDelegate MulticastDelegate_SelectAgent;
-
- private:
- void SetSelectAgent(UObject* Value) { UE_MVVM_SET_PROPERTY_VALUE(SelectAgent, Value); MulticastDelegate_SelectAgent.Broadcast(Value); }
- UObject* GetSelectAgent() const { return SelectAgent; }
-
- };
-
2. 蓝图使用