Published on

编辑器扩展:自定义属性界面

Authors
  • avatar
    Name
    东哥
    Twitter

前言

编辑器扩展:自定义属性界面,

未完待续...

SObjectPropertyEntryBox

用于选择资源的界面控件

image-20210106105801136

直接上代码

  • .h


`TSharedPtr<FAssetThumbnailPool>` AssetThumbnailPool;
UObject* SelectObject;
`TSharedPtr<SObjectPropertyEntryBox>` EditWidgetBox;
  • cpp
void SOVR_Hud::Construct(const FArguments& InArgs)
{
	AssetThumbnailPool = MakeShareable(new FAssetThumbnailPool(24));
    ................................
	SAssignNew(EditWidgetBox,SObjectPropertyEntryBox)
			.AllowedClass(UWidgetBlueprint::StaticClass())
			.OnObjectChanged(this, &SOVR_Hud::OnSetObject)
			.ObjectPath(this,&SOVR_Hud::GetPathName)
			.OnShouldFilterAsset(this,&SOVR_Hud::ShouldFilterAsset)
			.ThumbnailPool(AssetThumbnailPool)
void SOVR_Hud::OnSetObject(const FAssetData& AssetData)
{
	SelectObject = AssetData.GetAsset();
}
FString SOVR_Hud::GetPathName()const
{
	return SelectObject ? SelectObject->GetPathName() : TEXT("");
}
  • AllowedClass : Class类型, 这个是资源的类型
  • OnObjectChanged : 选择改变以后的代理
  • ObjectPath : 提供资源的路径名称
  • OnShouldFilterAsset : 过滤选项, 非必须
  • ThumbnailPool: Icon的对象池, 如果不设置就没有Icon

注意:

GetPathName()必须要返回真实的PathName,否则会导致界面显示还是None,如果没有正确的资源那么需要返回空或者None,否则会导致启动插件一次性卡顿并报警告

SClassPropertyEntryBox

类似的, 用于选择Class的界面控件

image-20210106110849937

SAssignNew(ClassBox, SClassPropertyEntryBox)
			.MetaClass(AActor::StaticClass())
		//.RequiredInterface(UStaticMesh::StaticClass())
		.IsBlueprintBaseOnly(false)
		.ShowTreeView(true)
		.SelectedClass(this, &SOVR_Hud::OnGetClass)
		.OnSetClass(this, &SOVR_Hud::OnSetClass)
const UClass* SOVR_Hud::OnGetClass() const
{
	return SelectedClass;
}
void SOVR_Hud::OnSetClass(const UClass* SetClass)
{
	SelectedClass = SetClass;
}