自定义结构属性编辑器添加Setter和Listener

时间:2017-08-01 15:55:19

标签: unreal-engine4

我一直在努力解决这个问题,并且非常感谢一些指导。

目标是创建一个下拉列表/组合框,其中包含用户可以在编辑器中选择的字符串。这是为了扩展详细信息定制。

我已经创建了一个这样的自定义结构。

USTRUCT()
struct FTaskComponentData
{
    GENERATED_BODY()

    UPROPERTY(VisibleAnywhere)
    TArray<FString>                                             Names;

};

然后我创建了一个类来实现IPropertyTypeCustomization,如下所示: (头文件):

class FTaskComponentDataCustomization : public IPropertyTypeCustomization
{
public:
    static TSharedRef<IPropertyTypeCustomization> MakeInstance();

    /** IPropertyTypeCustomization interface */
    virtual void CustomizeHeader(TSharedRef<class IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils) override;
    virtual void CustomizeChildren(TSharedRef<class IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils) override;

private:
    TSharedPtr<IPropertyHandle> UPropertyTaskNameHandle;

    /** Visibility delegate for the various methods of calculating magnitude */
    EVisibility GetPropertyVisibility(UProperty* InProperty) const;
};

(源文件):

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

void FTaskComponentDataCustomization::CustomizeHeader(TSharedRef<class IPropertyHandle> StructPropertyHandle, class FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
    uint32 NumChildren;
    StructPropertyHandle->GetNumChildren(NumChildren);

    for (uint32 ChildIndex = 0; ChildIndex < NumChildren; ++ChildIndex)
    {
        const TSharedRef< IPropertyHandle > ChildHandle = StructPropertyHandle->GetChildHandle(ChildIndex).ToSharedRef();

        if (ChildHandle->GetProperty()->GetName() == TEXT("Names"))
        {
            UPropertyTaskNameHandle = ChildHandle;
        }
    }

    check(UPropertyTaskNameHandle.IsValid());


    static TArray< TSharedPtr<FString>> something;

    something.Add(TSharedPtr<FString>(new FString("One")));
    something.Add(TSharedPtr<FString>(new FString("Two")));
    something.Add(TSharedPtr<FString>(new FString("Three")));


    HeaderRow.NameContent()
        [
            StructPropertyHandle->CreatePropertyNameWidget(LOCTEXT("Task", "Task Names"), LOCTEXT("IDK","IDK"), false, true, false)
        ]
    .ValueContent()
        .MinDesiredWidth(250)
        [
            SNew(STextComboBox)
            .OptionsSource(&something)
        ];
}

void FTaskComponentDataCustomization::CustomizeChildren(TSharedRef<class IPropertyHandle> StructPropertyHandle, class IDetailChildrenBuilder& StructBuilder, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
}


EVisibility FTaskComponentDataCustomization::GetPropertyVisibility(UProperty* InProperty) const {
    return EVisibility::Visible;
}

然后我在我的组件子类中包含了这个自定义结构,如下所示:

UPROPERTY(EditAnywhere, Category = "Planning | Task")
FTaskComponentData                          TaskData;
然后我按照这样注册FPropertyEditorModule:

FPropertyEditorModule& PropertyModule = FModuleManager::LoadModuleChecked<FPropertyEditorModule>("PropertyEditor");

    //Custom properties
    PropertyModule.RegisterCustomPropertyTypeLayout("TaskComponentData", FOnGetPropertyTypeCustomizationInstance::CreateStatic(&FTaskComponentDataCustomization::MakeInstance));

此时,显示所需的组合框..我有两个问题:

1)如何设置TArray以便我可以使用不同的字符串更新数据成员?

2)如何注册属性更改侦听器?现在,当我尝试从组合框中选择值时,没有任何属性更改侦听器从我的组件中触发。

或者我在哪里可以挖掘出这些功能?

0 个答案:

没有答案