一、委托
1、定义和声明
DECLARE_DELEGATE(FStandardDelegateSignature)
DECLARE_DELEGATE_OneParam(FParamDelegateSignature ,FLinearColor)
DECLARE_DELEGATE_几Param(FParamDelegateSignature ,几参数)
DECLARE_MULTICAST_DELEGATE(FMulticastDelegateSignature)
FStandardDelegateSignature MyStandardDelegate;
FParamDelegateSignature MyParamterDelegate;
FMulticastDelegateSignature MyMulticastDelegate;
2、绑定与解绑
1、单播
MyGameMode->MyStandardDelegate.BindUObject(this, &ADelegateListener::EnableLight);
MyGameMode->MyStandardDelegate.Unbind();
MyGameMode->MyParamterDelegate.BindUObject(this, &AParamDelegateListener::SetLightColor,false);
2、多播
MyDelegateHandle= MyGameMode->MyMulticastDelegate.AddUObject(this, &AMulticastDelegateListener::ToggleLight);
MyGameMode->MyMulticastDelegate.Remove(MyDelegateHandle);
3、执行
1、单播
MyGameMode->MyStandardDelegate.ExecuteIfBound();
MyGameMode->MyParamterDelegate.ExecuteIfBound(FLinearColor(1,0,0,1));
2、多播
MyGameMode->MyMulticastDelegate.Broadcast();
二、自定义事件
1、声明和定义
DECLARE_EVENT(AMyTriggerVolume,FPlayerEntered)
FPlayerEntered OnPlayerEntered;
2、绑定与解绑
TriggerEventSource->OnPlayerEntered.AddUObject(this, &ATriggerVolEventListener::onTriggerEvent);
TriggerEventSource->OnPlayerEntered.Remove(MyDelegateHandle);
3、执行
OnPlayerEntered.Broadcast();