vault backup: 2024-10-12 17:19:45

This commit is contained in:
2024-10-12 17:19:46 +08:00
parent ff94ddca61
commit 244c0c52f6
960 changed files with 31348 additions and 10 deletions

View File

@@ -0,0 +1,58 @@
# AllowedLocators
- **功能描述:** 用来给Sequencer定位可绑定的对象
- **使用位置:** UPROPERTY
- **引擎模块:** Scene
- **元数据类型:** string="abc"
- **限制类型:** FUniversalObjectLocator
- **常用程度:** ★
用来给Sequencer定位可绑定的对象。
看起来是Sequencer用来定位Actor做属性绑定的辅助定位器。只用在FUniversalObjectLocator 这个写好的属性里一般我们用不到去扩展这部分因此只是OnlyInternal。
## 源码中搜索得到:
```cpp
// Helper struct for Binding Properties UI for locators.
USTRUCT()
struct FMovieSceneUniversalLocatorInfo
{
GENERATED_BODY()
// Locator for the entry
UPROPERTY(EditAnywhere, Category = "Default", meta=(AllowedLocators="Actor"))
FUniversalObjectLocator Locator;
// Flags for how to resolve the locator
UPROPERTY()
ELocatorResolveFlags ResolveFlags = ELocatorResolveFlags::None;
};
```
看起来是允许定位的对象类型。
## 原理:
```cpp
TMap<FName, TSharedPtr<ILocatorEditor>> ApplicableLocators;
void FUniversalObjectLocatorCustomization::CustomizeHeader(TSharedRef<IPropertyHandle> StructPropertyHandle, FDetailWidgetRow& HeaderRow, IPropertyTypeCustomizationUtils& StructCustomizationUtils)
{
TArray<FString> AllowedTypes;
if (PropertyHandle->HasMetaData("AllowedLocators"))
{
PropertyHandle->GetMetaData("AllowedLocators").ParseIntoArray(AllowedTypes, TEXT(","));
}
}
FUniversalObjectLocatorEditorModule& Module = FModuleManager::Get().LoadModuleChecked<FUniversalObjectLocatorEditorModule>("UniversalObjectLocatorEditor");
for (TPair<FName, TSharedPtr<ILocatorEditor>> Pair : Module.LocatorEditors)
{
if (AllowedTypes.Num() == 0 || AllowedTypes.Contains(Pair.Key.ToString()))
{
ApplicableLocators.Add(Pair.Key, Pair.Value);
}
}
```

View File

@@ -0,0 +1,58 @@
# MakeEditWidget
- **功能描述:** 使FVector和FTranform在场景编辑器里出现一个可移动的控件。
- **使用位置:** UPROPERTY
- **引擎模块:** Scene
- **元数据类型:** bool
- **限制类型:** FVectorFTranform
- **关联项:** [ValidateWidgetUsing](../ValidateWidgetUsing/ValidateWidgetUsing.md)
- **常用程度:** ★★★
使FVector和FTranform在场景编辑器里出现一个可移动的控件。
这样相比直接的数值编辑更加的直观一些。
## 测试代码:
```cpp
UCLASS(BlueprintType)
class INSIDER_API AMyActor_EditWidget :public AActor
{
GENERATED_BODY()
public:
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="EditWidget")
FVector MyVector;
UPROPERTY(EditAnywhere,BlueprintReadWrite,Category="EditWidget",meta=(MakeEditWidget))
FVector MyVector_MakeEditWidget;
};
```
## 测试结果:
在蓝图里继承的AMyActor_EditWidget 子类里加上另外一个FTransform变量可以看见“Show 3D Widget”的选项这个和MyVector_MakeEditWidget都在场景里出现了可移动的控件。
![Untitled](Untitled.png)
## 原理:
判断如果是FVector或FTransform并且有MakeEditWidget属性则可以创建控件。
```cpp
/** Value of UPROPERTY can be edited with a widget in the editor (translation, rotation) */
static UNREALED_API const FName MD_MakeEditWidget;
/** Specifies a function used for validation of the current value of a property. The function returns a string that is empty if the value is valid, or contains an error description if the value is invalid */
static UNREALED_API const FName MD_ValidateWidgetUsing;
bool FLegacyEdModeWidgetHelper::CanCreateWidgetForStructure(const UStruct* InPropStruct)
{
return InPropStruct && (InPropStruct->GetFName() == NAME_Vector || InPropStruct->GetFName() == NAME_Transform);
}
bool FLegacyEdModeWidgetHelper::ShouldCreateWidgetForProperty(FProperty* InProp)
{
return CanCreateWidgetForProperty(InProp) && InProp->HasMetaData(MD_MakeEditWidget);
}
```

Binary file not shown.

After

Width:  |  Height:  |  Size: 503 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 609 KiB

View File

@@ -0,0 +1,77 @@
# ValidateWidgetUsing
- **功能描述:** 提供一个函数来验证当前属性值是否合法。
- **使用位置:** UPROPERTY
- **引擎模块:** Scene
- **元数据类型:** bool
- **限制类型:** 带有MakeEditWidget的FVectorFTransform
- **关联项:** [MakeEditWidget](../MakeEditWidget/MakeEditWidget.md)
- **常用程度:** ★★★
ValidateWidgetUsing提供一个函数来验证当前属性值是否合法。
- 当前属性要有MakeEditWidget的标记
- 函数的原型是FString MyFunc(),返回非空表示错误信息。
## 测试代码:
```cpp
UFUNCTION()
FString ValidateMyVector()
{
if (MyVector_MakeEditWidget_Validate.Length()>100.f)
{
return TEXT("Exceed max length:100");
}
return TEXT("");
}
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = "EditWidget", meta = (MakeEditWidget, ValidateWidgetUsing = "ValidateMyVector"))
FVector MyVector_MakeEditWidget_Validate;
```
## 测试结果:
可见MyVector_MakeEditWidget_Validate长度超过100之后控件颜色变成红色并且显示出错误的信息在控件上。
![Untitled](Untitled.png)
## 原理:
逻辑比较简单。发现有验证函数,就调用验证函数来验证。如果有错误信息,就一起改变最终输出的颜色和显示文字。
```cpp
static FLegacyEdModeWidgetHelper::FPropertyWidgetInfo CreateWidgetInfo(const TArray<FPropertyWidgetInfoChainElement>& Chain, bool bIsTransform, FProperty* CurrentProp, int32 Index = INDEX_NONE)
{
check(CurrentProp);
FEdMode::FPropertyWidgetInfo WidgetInfo;
WidgetInfo.PropertyValidationName = FName(*CurrentProp->GetMetaData(FEdMode::MD_ValidateWidgetUsing));
return WidgetInfo;
}
void FLegacyEdModeWidgetHelper::FPropertyWidgetInfo::GetTransformAndColor(UObject* BestSelectedItem, bool bIsSelected, FTransform& OutLocalTransform, FString& OutValidationMessage, FColor& OutDrawColor) const
{
// Determine the desired color
if (PropertyValidationName != NAME_None)
{
if (UFunction* ValidateFunc = BestSelectedItem->FindFunction(PropertyValidationName))
{
BestSelectedItem->ProcessEvent(ValidateFunc, &OutValidationMessage);
// if we have a negative result, the widget color is red.
OutDrawColor = OutValidationMessage.IsEmpty() ? OutDrawColor : FColor::Red;
}
}
}
void FLegacyEdModeWidgetHelper::DrawHUD(FEditorViewportClient* ViewportClient, FViewport* Viewport, const FSceneView* View, FCanvas* Canvas)
{
FTransform LocalWidgetTransform;
FString ValidationMessage;
FColor WidgetColor;
WidgetInfo.GetTransformAndColor(BestSelectedItem, bSelected, /*out*/ LocalWidgetTransform, /*out*/ ValidationMessage, /*out*/ WidgetColor);
Canvas->DrawItem(TextItem);
}
```