-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
Copy pathNumericFieldDraggerUtility.cs
83 lines (69 loc) · 2.75 KB
/
NumericFieldDraggerUtility.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using UnityEngine.Bindings;
using UnityEngine.Scripting.APIUpdating;
namespace UnityEngine
{
[MovedFrom("UnityEditor")]
[VisibleToOtherModules("UnityEngine.UIElementsModule", "UnityEditor.UIBuilderModule")]
internal class NumericFieldDraggerUtility
{
public static float Acceleration(bool shiftPressed, bool altPressed)
{
return (shiftPressed ? 4 : 1) * (altPressed ? .25f : 1);
}
static bool s_UseYSign = false;
public static float NiceDelta(Vector2 deviceDelta, float acceleration)
{
deviceDelta.y = -deviceDelta.y;
if (Mathf.Abs(Mathf.Abs(deviceDelta.x) - Mathf.Abs(deviceDelta.y)) / Mathf.Max(Mathf.Abs(deviceDelta.x), Mathf.Abs(deviceDelta.y)) > .1f)
{
if (Mathf.Abs(deviceDelta.x) > Mathf.Abs(deviceDelta.y))
s_UseYSign = false;
else
s_UseYSign = true;
}
if (s_UseYSign)
return Mathf.Sign(deviceDelta.y) * deviceDelta.magnitude * acceleration;
else
return Mathf.Sign(deviceDelta.x) * deviceDelta.magnitude * acceleration;
}
const float kDragSensitivity = .03f;
public static double CalculateFloatDragSensitivity(double value)
{
if (double.IsInfinity(value) || double.IsNaN(value))
{
return 0.0;
}
return Math.Max(1, Math.Pow(Math.Abs(value), 0.5)) * kDragSensitivity;
}
public static double CalculateFloatDragSensitivity(double value, double minValue, double maxValue)
{
if (double.IsInfinity(value) || double.IsNaN(value))
{
return 0.0;
}
double range = Math.Abs(maxValue - minValue);
return range / 100.0f * kDragSensitivity;
}
public static long CalculateIntDragSensitivity(long value)
{
return (long)CalculateIntDragSensitivity((double)value);
}
public static ulong CalculateIntDragSensitivity(ulong value)
{
return (ulong)CalculateIntDragSensitivity((double)value);
}
public static double CalculateIntDragSensitivity(double value)
{
return Math.Max(1, Math.Pow(Math.Abs(value), 0.5) * kDragSensitivity);
}
public static long CalculateIntDragSensitivity(long value, long minValue, long maxValue)
{
long range = Math.Abs(maxValue - minValue);
return Math.Max(1, (long)(kDragSensitivity * range / 100));
}
}
}