62 lines
2.4 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# LinearDeltaSensitivity
- **功能描述:** 在设定Delta后进一步设定数字输入框变成线性改变以及改变的敏感度值越大越不敏感
- **使用位置:** UPROPERTY
- **引擎模块:** Numeric Property
- **元数据类型:** float/int
- **限制类型:** float,int32
- **关联项:** [Delta](Delta/Delta.md)
- **常用程度:** ★★★
生效的条件:
1. 先设置Delta>0
2. 不设置UIMin, UIMax
3. 设定LinearDeltaSensitivity >0
## 测试代码:
```cpp
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DeltaTest, meta = (UIMin = "0", UIMax = "1000", Delta = 10))
float MyFloat_Delta10_UIMinMax = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DeltaTest, meta = (Delta = 10, LinearDeltaSensitivity = 50))
float MyFloat_Delta10_LinearDeltaSensitivity50 = 100;
UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = DeltaTest, meta = (UIMin = "0", UIMax = "1000", Delta = 10, LinearDeltaSensitivity = 50))
float MyFloat_Delta10_LinearDeltaSensitivity50_UIMinMax = 100;
```
## 测试效果:
效果解析请参见Delta的解析
![Delta](Delta/Delta.gif)
## 原理:
可见只有没有UIMinMax且已经设置Delta后才能走进线性改变的代码分支。
```cpp
, _Delta(0)
virtual FReply SSpinBox<NumericType>::OnMouseMove(const FGeometry& MyGeometry, const FPointerEvent& MouseEvent) override
{
if (bUnlimitedSpinRange)
{
// If this control has a specified delta and sensitivity then we use that instead of the current value for determining how much to change.
const double Sign = (MouseEvent.GetCursorDelta().X > 0) ? 1.0 : -1.0;
if (LinearDeltaSensitivity.IsSet() && LinearDeltaSensitivity.Get() != 0 && Delta.IsSet() && Delta.Get() > 0)
{
const double MouseDelta = FMath::Abs(MouseEvent.GetCursorDelta().X / (float)LinearDeltaSensitivity.Get());
NewValue = InternalValue + (Sign * MouseDelta * FMath::Pow((double)Delta.Get(), (double)SliderExponent.Get())) * Step;
}
else
{
const double MouseDelta = FMath::Abs(MouseEvent.GetCursorDelta().X / SliderWidthInSlateUnits);
const double CurrentValue = FMath::Clamp<double>(FMath::Abs(InternalValue), 1.0, (double)std::numeric_limits<NumericType>::max());
NewValue = InternalValue + (Sign * MouseDelta * FMath::Pow((double)CurrentValue, (double)SliderExponent.Get())) * Step;
}
}
}
```