在unreal中在FUICommandList对象上调用MapAction方法时ExcuteAction参数如何传入一个带参方法
在Unreal Engine中,可以使用TBaseDelegate来传递带参数的方法作为ExecuteAction参数。以下是一个示例:
void MyClass::MyMethod(int32 MyParam)
{
// 在这里实现自己的逻辑
}
void MyClass::SetupCommands()
{
FUICommandList& CommandList = ... ; // 获取FUICommandList对象的引用
// 创建一个TBaseDelegate,将带参数的方法绑定到ExecuteAction参数上
FUIAction MyAction;
MyAction.ExecuteAction = FUIAction::FDelegate::CreateRaw(this, &MyClass::MyMethod, 123); // 这里的123是传递给方法的参数
// 将Action与Command绑定
CommandList.MapAction(
MyCommand,
MyAction,
FUIActionBinding::Execute | FUIActionBinding::CanExecute
);
}
上面的示例中,MyMethod是一个带有int32参数的方法。在SetupCommands方法中,通过使用FUIAction::FDelegate::CreateRaw来创建一个TBaseDelegate,并将带参数的方法绑定到其中。然后,使用MapAction方法将Action与Command绑定在一起。
请注意,示例中的MyCommand是一个自定义的FUICommandInfo对象,您需要根据自己的需求替换为实际的Command对象
原文地址: https://www.cveoy.top/t/topic/hNUN 著作权归作者所有。请勿转载和采集!