Survivalcraft API 1.8.2.3 v1.8.2.3
Survivalcraft 2.4
载入中...
搜索中...
未找到
TouchInputWidget.cs
浏览该文件的文档.
1using Engine;
2using Engine.Input;
3
4namespace Game {
5 public class TouchInputWidget : Widget {
6 public int? m_touchId;
7
9
11
13
14 public bool m_touchMoved;
15
16 public double m_touchTime;
17
19
21
22 public float m_radius = 30f;
23
24 public float Radius {
25 get => m_radius;
26 set => m_radius = MathUtils.Max(value, 1f);
27 }
28
30 get {
32 return m_touchInput;
33 }
34 return null;
35 }
36 }
37
38 public override void Update() {
39 m_touchInput = null;
40 double frameStartTime = Time.FrameStartTime;
41 int frameIndex = Time.FrameIndex;
42 foreach (TouchLocation touchLocation in Input.TouchLocations) {
43 if (touchLocation.State == TouchLocationState.Pressed) {
44 if (HitTestGlobal(touchLocation.Position) == this) {
45 m_touchId = touchLocation.Id;
46 m_touchLastPosition = touchLocation.Position;
47 m_touchOrigin = touchLocation.Position;
48 m_touchOriginLimited = touchLocation.Position;
49 m_touchTime = frameStartTime;
50 m_touchFrameIndex = frameIndex;
51 m_touchMoved = false;
52 }
53 }
54 else if (touchLocation.State == TouchLocationState.Moved) {
55 if (m_touchId.HasValue
56 && touchLocation.Id == m_touchId.Value) {
58 TouchInput value = default;
59 value.InputType = !m_touchMoved ? TouchInputType.Hold : TouchInputType.Move;
60 value.Duration = (float)(frameStartTime - m_touchTime);
61 value.DurationFrames = frameIndex - m_touchFrameIndex;
62 value.Position = touchLocation.Position;
63 value.Move = touchLocation.Position - m_touchLastPosition;
64 value.TotalMove = touchLocation.Position - m_touchOrigin;
65 value.TotalMoveLimited = touchLocation.Position - m_touchOriginLimited;
66 if (MathF.Abs(value.TotalMoveLimited.X) > m_radius) {
67 m_touchOriginLimited.X = touchLocation.Position.X - MathF.Sign(value.TotalMoveLimited.X) * m_radius;
68 }
69 if (MathF.Abs(value.TotalMoveLimited.Y) > m_radius) {
70 m_touchOriginLimited.Y = touchLocation.Position.Y - MathF.Sign(value.TotalMoveLimited.Y) * m_radius;
71 }
72 m_touchInput = value;
73 m_touchLastPosition = touchLocation.Position;
74 }
75 }
76 else if (touchLocation.State == TouchLocationState.Released
77 && m_touchId.HasValue
78 && touchLocation.Id == m_touchId.Value) {
79 if (frameStartTime - m_touchTime <= SettingsManager.MinimumHoldDuration
81 TouchInput value2 = default;
82 value2.InputType = TouchInputType.Tap;
83 value2.Duration = (float)(frameStartTime - m_touchTime);
84 value2.DurationFrames = frameIndex - m_touchFrameIndex;
85 value2.Position = touchLocation.Position;
86 m_touchInput = value2;
87 }
88 m_touchId = null;
89 }
90 }
91 }
92 }
93}
static int Max(int x1, int x2)
static int FrameIndex
定义 Time.cs:26
static double FrameStartTime
定义 Time.cs:42
float GlobalScale
bool IsVisibleGlobal
virtual Widget HitTestGlobal(Vector2 point, Func< Widget, bool > predicate=null)
WidgetInput Input
bool IsEnabledGlobal
static float Distance(Vector2 v1, Vector2 v2)