1.7 KiB
Raw Blame History

NoElementDuplicate

  • 功能描述: 去除TArray属性里数据项的Duplicate菜单项按钮。
  • 使用位置: UPROPERTY
  • 引擎模块: Container Property
  • 元数据类型: bool
  • 限制类型: TArray
  • 常用程度:

去除TArray属性里数据项的Duplicate菜单项按钮。

用于TArray属性值可以是任何类型可以是数值结构也可以是Object*。

测试代码:

public:
	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = IntArray)
	TArray<int32> MyIntArray;

	UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = IntArray, meta = (NoElementDuplicate))
	TArray<int32> MyIntArray_NoElementDuplicate;

效果:

可以看到带有NoElementDuplicate的数组在值的右侧下拉箭头的菜单项里只有两项。

Untitled

原理:

判断如有NoElementDuplicate则只生成Insert_Delete 菜单否则是默认的Insert_Delete_Duplicate 。当然要求当前属性是数组属性且不是EditFixedSize固定大小的。

void GetRequiredPropertyButtons( TSharedRef<FPropertyNode> PropertyNode, TArray<EPropertyButton::Type>& OutRequiredButtons, bool bUsingAssetPicker )
{
		const FArrayProperty* OuterArrayProp = NodeProperty->GetOwner<FArrayProperty>();
		
		if( OuterArrayProp )
		{
			if( PropertyNode->HasNodeFlags(EPropertyNodeFlags::SingleSelectOnly) && !(OuterArrayProp->PropertyFlags & CPF_EditFixedSize) )
			{
				if (OuterArrayProp->HasMetaData(TEXT("NoElementDuplicate")))
				{
					OutRequiredButtons.Add( EPropertyButton::Insert_Delete );
				}
				else
				{
					OutRequiredButtons.Add( EPropertyButton::Insert_Delete_Duplicate );
				}
			}
		}
}