89 lines
3.2 KiB
Markdown
89 lines
3.2 KiB
Markdown
|
# InlineEditConditionToggle
|
|||
|
|
|||
|
- **功能描述:** 使这个bool属性在被用作EditCondition的时候内联到对方的属性行里成为一个单选框,而不是自己成为一个编辑行。
|
|||
|
- **使用位置:** UPROPERTY
|
|||
|
- **元数据类型:** bool
|
|||
|
- **限制类型:** bool
|
|||
|
- **关联项:** [EditCondition](../EditCondition/EditCondition.md)
|
|||
|
- **常用程度:** ★★★★★
|
|||
|
|
|||
|
使这个bool属性在被用作EditCondition的时候内联到对方的属性行里成为一个单选框,而不是自己成为一个编辑行。
|
|||
|
|
|||
|
虽然EditCondition支持别的类型属性或者是表达式,但是这个InlineEditConditionToggle只支持bool属性。
|
|||
|
|
|||
|
## 测试代码:
|
|||
|
|
|||
|
```cpp
|
|||
|
public:
|
|||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InlineEditConditionToggle, meta = (InlineEditConditionToggle))
|
|||
|
bool MyBool_Inline;
|
|||
|
|
|||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InlineEditConditionToggle, meta = (EditCondition = "MyBool_Inline"))
|
|||
|
int32 MyInt_EditCondition_UseInline = 123;
|
|||
|
|
|||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InlineEditConditionToggle)
|
|||
|
int32 MyThirdInt_Inline = 123;
|
|||
|
|
|||
|
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = InlineEditConditionToggle, meta = (EditCondition = "MyThirdInt_Inline>200"))
|
|||
|
int32 MyInt_EditConditionExpression_UseInline = 123;
|
|||
|
```
|
|||
|
|
|||
|
## 测试效果:
|
|||
|
|
|||
|
可见MyBool_Inline变成了单选框。而MyThirdInt_Inline就没有被隐藏掉。
|
|||
|
|
|||
|

|
|||
|
|
|||
|
## 原理:
|
|||
|
|
|||
|
可以看到用这个判断是否支持出现单选框。
|
|||
|
|
|||
|
```cpp
|
|||
|
|
|||
|
bool FPropertyNode::SupportsEditConditionToggle() const
|
|||
|
{
|
|||
|
if (!Property.IsValid())
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
|
|||
|
FProperty* MyProperty = Property.Get();
|
|||
|
|
|||
|
static const FName Name_HideEditConditionToggle("HideEditConditionToggle");
|
|||
|
if (EditConditionExpression.IsValid() && !Property->HasMetaData(Name_HideEditConditionToggle))
|
|||
|
{
|
|||
|
const FBoolProperty* ConditionalProperty = EditConditionContext->GetSingleBoolProperty(EditConditionExpression);
|
|||
|
if (ConditionalProperty != nullptr)
|
|||
|
{
|
|||
|
// There are 2 valid states for inline edit conditions:
|
|||
|
// 1. The property is marked as editable and has InlineEditConditionToggle set.
|
|||
|
// 2. The property is not marked as editable and does not have InlineEditConditionToggle set.
|
|||
|
// In both cases, the original property will be hidden and only show up as a toggle.
|
|||
|
|
|||
|
static const FName Name_InlineEditConditionToggle("InlineEditConditionToggle");
|
|||
|
const bool bIsInlineEditCondition = ConditionalProperty->HasMetaData(Name_InlineEditConditionToggle);
|
|||
|
const bool bIsEditable = ConditionalProperty->HasAllPropertyFlags(CPF_Edit);
|
|||
|
|
|||
|
if (bIsInlineEditCondition == bIsEditable)
|
|||
|
{
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
if (bIsInlineEditCondition && !bIsEditable)
|
|||
|
{
|
|||
|
UE_LOG(LogPropertyNode, Warning, TEXT("Property being used as inline edit condition is not editable, but has redundant InlineEditConditionToggle flag. Field \"%s\" in class \"%s\"."), *ConditionalProperty->GetNameCPP(), *Property->GetOwnerStruct()->GetName());
|
|||
|
return true;
|
|||
|
}
|
|||
|
|
|||
|
// The property is already shown, and not marked as inline edit condition.
|
|||
|
if (!bIsInlineEditCondition && bIsEditable)
|
|||
|
{
|
|||
|
return false;
|
|||
|
}
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
return false;
|
|||
|
}
|
|||
|
```
|