Notes_Knowledge points of Slate part/compiler extension part_Add custom operation to the right button of the object in the world outline_Operate the right button of the file bar file_Add an Actor detail panel attribute_Custom mapping variable

Scattered knowledge points

//菜单分隔符
	Builder.AddMenuSeparator();

	//子菜单
	Builder.AddSubMenu(
		LOCTEXT("OOO","JJJJ"),
		LOCTEXT("CCCC","KKKK"),
		FNewMenuDelegate::CreateRaw	(this,&FMyToolModule::SubPullDownBar)
	);

	//图片Slate
	Builder.AddWidget(
			SNew(SImage),
			LOCTEXT("SImageO","ImageJK")
	);

	//输入框
	Builder.AddEditableText(
	LOCTEXT("EditableText","EditableTextJK"),
	LOCTEXT("EditableTextO","EditableTextJK1"),
	FSlateIcon(),
	LOCTEXT("Demo","DemoJK")
	);
	
	//搜索
	Builder.AddSearchWidget();

	//子菜单自定义Widget(Slate)
	Builder.AddWrapperSubMenu(
	LOCTEXT("WrapperSubMenu","WrapperSubMenuJK"),
	LOCTEXT("WrapperSubMenuO","WrapperSubMenuJK1"),
			FOnGetContent::CreateStatic<TSharedPtr<FUICommandList>>	(&FTest::MakeNewWidget,PluginCommands),
		FSlateIcon()
	);
	//自定义方法如下:
	TSharedRef<SWidget> FTest::MakeNewWidget	(TSharedPtr<FUICommandList> Plu)
	{
		return SNew(SImage);
	}	

For objects in the world outline, right click to perform some operations

1. First bind the method

{
{
		auto& MenuButtonArray =  LevelEditorModule.GetAllLevelViewportContextMenuExtenders();
		MenuButtonArray.Add(FLevelEditorModule::FLevelViewportMenuExtender_SelectedActors::CreateRaw(this,&FMyToolModule::SelectCueAS));
		MyDeleHandel = MenuButtonArray.Last().GetHandle();
}
}

2. The specific method is as follows

TSharedRef<FExtender> FMyToolModule::SelectCueAS(const TSharedRef<FUICommandList> MyCommandList,
	const TArray<AActor*> AllActor)
{
	TSharedRef<FExtender> Extender = MakeShareable(new FExtender);
	EdtorPrint(FString::Printf(TEXT("Actor Num = %d"),AllActor.Num()));
	
	if (AllActor.Num()>0)
	{
		//获取Level
		FLevelEditorModule& LevelEditorModule = FModuleManager::LoadModuleChecked<FLevelEditorModule>("LevelEditor");
		TSharedPtr<FUICommandList>LevelCommand = LevelEditorModule.GetGlobalLevelEditorActions();
		Extender->AddMenuExtension("ActorControl",EExtensionHook::After,LevelCommand,FMenuExtensionDelegate::CreateRaw(this,&FMyToolModule::AddSelectButton));

	}
	return Extender;
}

3. Binding style, the style is as follows

 

//Actor选择扩展
void FMyToolModule::AddSelectButton(FMenuBuilder& Builder)
{
	Builder.AddMenuEntry(FMyToolCommands::Get().PluginAction);
	//菜单分隔符
	Builder.AddMenuSeparator();
	
	Builder.AddSubMenu(
	LOCTEXT("OK_ONE", "just a task"),
	LOCTEXT("OK_TWO", "just a task button"),
		FNewMenuDelegate::CreateRaw(this,&FMyToolModule::SubPullDownBar)
	);
}	

Perform some operations on the right button of the file in the file bar

The method is similar to the above

1. First bind the method

{
		FContentBrowserModule& ContentBrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
		auto& Cont =  ContentBrowserModule.GetAllPathViewContextMenuExtenders();
		Cont.Add(FContentBrowserMenuExtender_SelectedPaths::CreateRaw(this,&FMyToolModule::GetPathFromEditor));
	//此处需要换成FContentBrowserModule并且需要在build中添加该模块
	//"ContentBrowser"
}

2. Implementation of specific methods

TSharedRef<FExtender> FMyToolModule::GetPathFromEditor(const TArray<FString>& NewPath)
{
	TSharedRef<FExtender> Extender = MakeShareable(new FExtender);
	EdtorPrint(FString::Printf(TEXT("Actor Num = %d"),NewPath.Num()));
	
	if (NewPath.Num()>0)
	{
		//获取Level
		FContentBrowserModule& BrowserModule = FModuleManager::LoadModuleChecked<FContentBrowserModule>("ContentBrowser");
	
		Extender->AddMenuExtension("NewFolder",EExtensionHook::After,PluginCommands,FMenuExtensionDelegate::CreateRaw(this,&FMyToolModule::AddSelectButton));

	}
	for (auto xx : NewPath)
	{
		EdtorPrint(xx);
	}
	return Extender;
}

The binding style is the same as above, so I won’t go into details


Add an Actor detail panel property

1. Add a module

"PropertyEditor"

2. Create a custom class xxx.h

.h
class FMyTestDetailCustom : public IDetailCustomization
{
public:

	 FMyTestDetailCustom();
	//负责映射到对象面板上
	virtual void CustomizeDetails( IDetailLayoutBuilder& DetailBuilder ) override;

	//实例化面板
	static TSharedRef< IDetailCustomization > MakeInstance();
	                  
};
	.cpp
	#define LOCTEXT_NAMESPACE "MyTestDetailCustom"
void FMyTestDetailCustom::CustomizeDetails(IDetailLayoutBuilder& DetailBuilder)
{
	IDetailCategoryBuilder& DetailCategoryBuilderIns =  DetailBuilder.EditCategory(TEXT("CustomizeDetails"));


	DetailCategoryBuilderIns.AddCustomRow(LOCTEXT("MM","Test")).WholeRowContent()
	[
		SNew(STextBlock)
		.Text(LOCTEXT("QQ","Test"))
	];
}
TSharedRef< IDetailCustomization > FMyTestDetailCustom::MakeInstance()
{
	return MakeShareable(new FMyTestDetailCustom);
}

3. Add corresponding mapping

//在创建的插件的.h文件中,找到PropertyEditorModule.cpp中的两个方法抄过来;
	void FPropertyEditorModule::RegisterCustomClassLayout( FName ClassName, FOnGetDetailCustomizationInstance DetailLayoutDelegate )
	void FPropertyEditorModule::RegisterCustomPropertyTypeLayout( FName PropertyTypeName, FOnGetPropertyTypeCustomizationInstance PropertyTypeLayoutDelegate, TSharedPtr<IPropertyTypeIdentifier> Identifier)
	//再定义自定义方法调用上面方法进行绑定
	void RegisterPropertyTypeCustomizations();
	void RegisterObjectCustomizations();

	//具体写法:
	void FTestDetailsModule::RegisterObjectCustomizations()
{
	RegisterCustomClassLayout("CustomizeObject",FOnGetDetailCustomizationInstance::CreateStatic(&FMyTestDetailCustom::MakeInstance));
}

void FTestDetailsModule::RegisterCustomClassLayout(FName ClassName,
	FOnGetDetailCustomizationInstance DetailLayoutDelegate)
{
	check(ClassName!= NAME_None);

	RegisteredClassNames.Add(ClassName);
	
	FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
	PropertyModule.RegisterCustomClassLayout(ClassName,DetailLayoutDelegate);
}

void FTestDetailsModule::RegisterCustomPropertyTypeLayout(FName PropertyTypeName,
	FOnGetPropertyTypeCustomizationInstance PropertyTypeLayoutDelegate)
{
	check(PropertyTypeName != NAME_None);

	RegisteredPropertyTypes.Add(PropertyTypeName);
	
	FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
	PropertyModule.RegisterCustomPropertyTypeLayout(PropertyTypeName,PropertyTypeLayoutDelegate);
}
	//绑定好了之后找到StartupModule()进行调用
	//先获取实例,然后调用上面写好的方法,并更新映射
	void FTestDetailsModule::StartupModule()
{
	FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
	
	RegisterPropertyTypeCustomizations();
	RegisterObjectCustomizations();
	
	PropertyModule.NotifyCustomizationModuleChanged();//更新映射
}
	//因为绑定后你还得解绑,所以我们先创建两个变量来保存相关内容
	.h:
	private:
	TSet< FName > RegisteredClassNames;
	TSet< FName > RegisteredPropertyTypes;
	.cpp
	//解绑:
	void FTestDetailsModule::ShutdownModule()
{
	if (FModuleManager::Get().IsModuleLoaded("PropertyEditor"))
	{
		FPropertyEditorModule& PropertyModule = FModuleManager::GetModuleChecked<FPropertyEditorModule>("PropertyEditor");
		
		for (auto It = RegisteredClassNames.CreateIterator();It;++It)
		{
			if (It->IsValid())
			{
				PropertyModule.UnregisterCustomClassLayout(*It);
			}
		}

		for (auto It = RegisteredPropertyTypes.CreateIterator();It;++It)
		{
			if (It->IsValid())
			{
				PropertyModule.UnregisterCustomPropertyTypeLayout(*It);
			}
		}
		
	}
}
	//这样就完成了基础的映射到UObject 对象的处理

custom mapping variables

1. Create a Struct structure file

USTRUCT(BlueprintType)
struct TESTDETAILS_API FStructVariable
{
	GENERATED_USTRUCT_BODY()
	

	
};

2. Create a StructVariableDetail file, inherit and copy the corresponding method

struct TESTDETAILS_API FStructVariableDetail:public IPropertyTypeCustomization
{
	
public:
	virtual void CustomizeHeader( TSharedRef<IPropertyHandle> PropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& CustomizationUtils )override;
	
	virtual void CustomizeChildren( TSharedRef<IPropertyHandle> PropertyHandle, IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& CustomizationUtils ) override;


	//实例化面板
	static TSharedRef< IPropertyTypeCustomization > MakeInstance();
	                  
};
.cpp具体方法实现
void FStructVariableDetail::CustomizeHeader(TSharedRef<IPropertyHandle> PropertyHandle, FDetailWidgetRow& HeaderRow,
                                      IPropertyTypeCustomizationUtils& CustomizationUtils)
{
	HeaderRow
	.NameContent()
	[
	PropertyHandle->CreatePropertyNameWidget()
	]
	.ValueContent()
	.MinDesiredWidth(125.0f)
	.MaxDesiredWidth(325.0f)
	[
		SNew(SImage)
	];
}

void FStructVariableDetail::CustomizeChildren(TSharedRef<IPropertyHandle> PropertyHandle,
	IDetailChildrenBuilder& ChildBuilder, IPropertyTypeCustomizationUtils& CustomizationUtils)
{
	
}

TSharedRef<IPropertyTypeCustomization> FStructVariableDetail::MakeInstance()
{
	return MakeShareable(new FStructVariableDetail);
}
	

3. Finally mapped to the previous method, that is, in the TestDetails.cpp file
 

void FTestDetailsModule::RegisterPropertyTypeCustomizations()
{
    RegisterCustomPropertyTypeLayout("StructVariable",FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FStructVariableDetail::MakeInstance));
}

Supongo que te gusta

Origin blog.csdn.net/qq_35337794/article/details/123167611
Recomendado
Clasificación