ue5 c++ 资源查看的上下文菜单扩展 完整代码
时间: 2023-10-06 18:08:28 浏览: 195
下面是UE5中资源查看的上下文菜单扩展的完整代码示例:
```cpp
#include "MyAssetActions.h"
#include "MyAsset.h"
#include "Framework/MultiBox/MultiBoxBuilder.h"
#define LOCTEXT_NAMESPACE "MyAssetActions"
FText FMyAssetActions::GetName() const
{
return LOCTEXT("MyAssetActionsName", "My Asset");
}
FColor FMyAssetActions::GetTypeColor() const
{
return FColor::Green;
}
UClass* FMyAssetActions::GetSupportedClass() const
{
return UMyAsset::StaticClass();
}
void FMyAssetActions::GetActions(const TArray<UObject*>& InObjects, FMenuBuilder& MenuBuilder)
{
// Add a menu item for the "Do Something" action
MenuBuilder.AddMenuEntry(
LOCTEXT("MyAssetAction_DoSomething", "Do Something"),
LOCTEXT("MyAssetAction_DoSomethingTooltip", "Does something with the selected My Asset(s)"),
FSlateIcon(),
FUIAction(
FExecuteAction::CreateRaw(this, &FMyAssetActions::DoSomething, InObjects),
FCanExecuteAction::CreateRaw(this, &FMyAssetActions::CanDoSomething, InObjects)
)
);
}
bool FMyAssetActions::HasActions(const TArray<UObject*>& InObjects) const
{
return true;
}
void FMyAssetActions::DoSomething(const TArray<UObject*>& InObjects)
{
// Do something with the selected My Asset(s) here
}
bool FMyAssetActions::CanDoSomething(const TArray<UObject*>& InObjects) const
{
// Return true if we can do something with the selected My Asset(s), false otherwise
return true;
}
#undef LOCTEXT_NAMESPACE
```
阅读全文