ED01.PostEditChangeProperty
大约 1 分钟
导|案例1- 收集Datatable表格中的名称
UPROPERTY(BlueprintReadWrite, EditAnywhere)
bool bAutoMatching = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite)
TArray<FName> CollectedNames;
UPROPERTY(BlueprintReadWrite, EditAnywhere, Category = "DataTable")
TObjectPtr<const UDataTable> DataTable;
InlineEditConditionToggle
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta=(InlineEditConditionToggle))
bool bAutoMatching = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite,meta=(EditCondition="bAsPackageName"))
TArray<FName> CollectedNames;
PostEditChangeProperty
#if WITH_EDITOR
void YourClass::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
FName PropertyName = PropertyChangedEvent.GetPropertyName();
// 处理 AutoMatching 逻辑
if (PropertyName == GET_MEMBER_NAME_CHECKED(UMultiDataTableRows, bAutoMatching) ||
PropertyName == GET_MEMBER_NAME_CHECKED(UMultiDataTableRows, MatchingField))
{
if (bAutoMatching)
{
RowNames.Empty();
const TArray<FName>& CollectedNames = GetRowNames();
if (CollectedNames.IsEmpty()) return;
if (MatchingField.IsEmpty())
{
RowNames.Append(CollectedNames);
}
else
{
for (const FName& Name : CollectedNames)
{
if (Name.ToString().StartsWith(MatchingField))
{
RowNames.Add(Name);
}
}
}
}
}
}
#endif
案例2- 预览包名
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PackageName")
bool bAsPackageName = false;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PackageName",meta=(EditCondition="bAsPackageName"))
FString PackageNamePrefix;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "PackageName",meta=(EditCondition="bAsPackageName"))
FString PackageNameSuffix;
UPROPERTY(BlueprintReadOnly,VisibleAnywhere,Category = "PackageName",meta=(EditCondition="bAsPackageName"))
FString PackageNamePreview;
void UMultiDataTableRows::PostEditChangeProperty(FPropertyChangedEvent& PropertyChangedEvent)
{
Super::PostEditChangeProperty(PropertyChangedEvent);
const FName PropertyName = PropertyChangedEvent.GetPropertyName();
if (PropertyName == GET_MEMBER_NAME_CHECKED(UMultiDataTableRows, bAsPackageName) ||
PropertyName == GET_MEMBER_NAME_CHECKED(UMultiDataTableRows, PackageNamePrefix) ||
PropertyName == GET_MEMBER_NAME_CHECKED(UMultiDataTableRows, PackageNameSuffix))
{
if (bAsPackageName && DataTable)
{
TArray<FName> RowNamesList = DataTable->GetRowNames();
if (!RowNamesList.IsEmpty())
{
PackageNamePreview = PackageNamePrefix + "_" + RowNamesList[0].ToString() + "_" + PackageNameSuffix;
}
}
}
}