Skip to content

Commit 15f33ea

Browse files
committed
DOCS: Improved documentation to comply with standards.
1 parent a318c46 commit 15f33ea

File tree

1 file changed

+96
-72
lines changed
  • Packages/com.unity.inputsystem/InputSystem/Plugins/EnhancedTouch

1 file changed

+96
-72
lines changed

Packages/com.unity.inputsystem/InputSystem/Plugins/EnhancedTouch/Touch.cs

Lines changed: 96 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace UnityEngine.InputSystem.EnhancedTouch
2222
/// and touch phases (<see cref="TouchControl.phase"/>) in order to tell one touch apart from another.
2323
///
2424
/// Also, this class protects against losing touches. If a touch is shorter-lived than a single input update,
25-
/// <see cref="Touchscreen"/> may overwrite it with a new touch coming in in the same update whereas this class
25+
/// <see cref="Touchscreen"/> may overwrite it with a new touch coming in the same update whereas this class
2626
/// will retain all changes that happened on the touchscreen in any particular update.
2727
///
2828
/// The API makes a distinction between "fingers" and "touches". A touch refers to one contact state change event, that is, a
@@ -42,167 +42,173 @@ public struct Touch : IEquatable<Touch>
4242
/// <summary>
4343
/// Whether this touch record holds valid data.
4444
/// </summary>
45-
/// <value>If true, the data contained in the touch is valid.</value>
4645
/// <remarks>
4746
/// Touch data is stored in unmanaged memory as a circular input buffer. This means that when
4847
/// the buffer runs out of capacity, older touch entries will get reused. When this happens,
4948
/// existing <c>Touch</c> instances referring to the record become invalid.
50-
///
49+
/// <para>
5150
/// This property can be used to determine whether the record held on to by the <c>Touch</c>
5251
/// instance is still valid.
53-
///
52+
/// </para>
53+
/// <para>
5454
/// This property will be <c>false</c> for default-initialized <c>Touch</c> instances.
55-
///
55+
/// </para>
56+
/// <para>
5657
/// Note that accessing most of the other properties on this struct when the touch is
57-
/// invalid will trigger <c>InvalidOperationException</c>.
58+
/// invalid will trigger <see cref="InvalidOperationException"/>.
59+
/// </para>
5860
/// </remarks>
5961
public bool valid => m_TouchRecord.valid;
6062

6163
/// <summary>
62-
/// The finger used for the touch contact. Null only for default-initialized
63-
/// instances of the struct.
64+
/// The finger used for the touch contact.
6465
/// </summary>
65-
/// <value>Finger used for the touch contact.</value>
66-
/// <seealso cref="activeFingers"/>
66+
/// <remarks>
67+
/// Note that this is only <c>null</c> for default-initialized instances of the struct.
68+
/// <para>
69+
/// See <see cref="activeFingers"/> for how to access all active fingers.
70+
/// </para>
71+
/// </remarks>
6772
public Finger finger => m_Finger;
6873

6974
/// <summary>
7075
/// Current phase of the touch.
7176
/// </summary>
72-
/// <value>Current phase of the touch.</value>
7377
/// <remarks>
7478
/// Every touch goes through a predefined cycle that starts with <see cref="TouchPhase.Began"/>,
7579
/// then potentially <see cref="TouchPhase.Moved"/> and/or <see cref="TouchPhase.Stationary"/>,
7680
/// and finally concludes with either <see cref="TouchPhase.Ended"/> or <see cref="TouchPhase.Canceled"/>.
77-
///
78-
/// This property indicates where in the cycle the touch is.
81+
/// <para>
82+
/// This property indicates where in the cycle the touch is and is based on <see cref="TouchControl.phase"/>.
83+
/// </para>
84+
/// <para>
85+
/// Use <see cref="isInProgress"/> to more conveniently evaluate whether this touch is currently active or not.
86+
/// </para>
7987
/// </remarks>
80-
/// <seealso cref="isInProgress"/>
81-
/// <seealso cref="TouchControl.phase"/>
8288
public TouchPhase phase => state.phase;
8389

8490
/// <summary>
8591
/// Whether the touch has begun this frame, i.e. whether <see cref="phase"/> is <see cref="TouchPhase.Began"/>.
8692
/// </summary>
87-
/// <seealso cref="phase"/>
88-
/// <seealso cref="ended"/>
89-
/// <seealso cref="inProgress"/>
93+
/// <remarks>
94+
/// <para>
95+
/// Use <see cref="isInProgress"/> to more conveniently evaluate whether this touch is currently active or not.
96+
/// </para>
97+
/// </remarks>
9098
public bool began => phase == TouchPhase.Began;
9199

92100
/// <summary>
93101
/// Whether the touch is currently in progress, i.e. whether <see cref="phase"/> is either
94102
/// <see cref="TouchPhase.Moved"/>, <see cref="TouchPhase.Stationary"/>, or <see cref="TouchPhase.Began"/>.
95103
/// </summary>
96-
/// <seealso cref="phase"/>
97-
/// <seealso cref="began"/>
98-
/// <seealso cref="ended"/>
99104
public bool inProgress => phase == TouchPhase.Moved || phase == TouchPhase.Stationary || phase == TouchPhase.Began;
100105

101106
/// <summary>
102107
/// Whether the touch has ended this frame, i.e. whether <see cref="phase"/> is either
103108
/// <see cref="TouchPhase.Ended"/> or <see cref="TouchPhase.Canceled"/>.
104109
/// </summary>
105-
/// <seealso cref="phase"/>
106-
/// <seealso cref="began"/>
107-
/// <seealso cref="isInProgress"/>
110+
/// <remarks>
111+
/// Use <see cref="isInProgress"/> to more conveniently evaluate whether this touch is currently active or not.
112+
/// </remarks>
108113
public bool ended => phase == TouchPhase.Ended || phase == TouchPhase.Canceled;
109114

110115
/// <summary>
111116
/// Unique ID of the touch as (usually) assigned by the platform.
112117
/// </summary>
113-
/// <value>Unique, non-zero ID of the touch.</value>
114118
/// <remarks>
115-
/// Each touch contact that is made with the screen receives its own unique ID which is
116-
/// normally assigned by the underlying platform.
117-
///
119+
/// Each touch contact that is made with the screen receives its own unique, non-zero ID which is
120+
/// normally assigned by the underlying platform via <see cref="TouchControl.touchId"/>.
121+
/// <para>
118122
/// Note a platform may reuse touch IDs after their respective touches have finished.
119123
/// This means that the guarantee of uniqueness is only made with respect to <see cref="activeTouches"/>.
120-
///
124+
/// </para>
125+
/// <para>
121126
/// In particular, all touches in <see cref="history"/> will have the same ID whereas
122-
/// touches in the a finger's <see cref="Finger.touchHistory"/> may end up having the same
127+
/// touches in the finger's <see cref="Finger.touchHistory"/> may end up having the same
123128
/// touch ID even though constituting different physical touch contacts.
129+
/// </para>
124130
/// </remarks>
125-
/// <seealso cref="TouchControl.touchId"/>
126131
public int touchId => state.touchId;
127132

128133
/// <summary>
129134
/// Normalized pressure of the touch against the touch surface.
130135
/// </summary>
131-
/// <value>Pressure level of the touch.</value>
132136
/// <remarks>
133137
/// Not all touchscreens are pressure-sensitive. If unsupported, this property will
134138
/// always return 0.
135-
///
139+
/// <para>
136140
/// In general, touch pressure is supported on mobile platforms only.
137-
///
141+
/// </para>
142+
/// <para>
143+
/// Touch pressure may also be retrieved directly from the device control via <see cref="TouchControl.pressure"/>.
144+
/// </para>
145+
/// <para>
138146
/// Note that it is possible for the value to go above 1 even though it is considered normalized. The reason is
139147
/// that calibration on the system can put the maximum pressure point below the physically supported maximum value.
148+
/// </para>
140149
/// </remarks>
141-
/// <seealso cref="TouchControl.pressure"/>
142150
public float pressure => state.pressure;
143151

144152
/// <summary>
145-
/// Screen-space radius of the touch.
153+
/// Screen-space radius of the touch which define its horizontal and vertical extents.
146154
/// </summary>
147-
/// <value>Horizontal and vertical extents of the touch contact.</value>
148155
/// <remarks>
149156
/// If supported by the underlying device, this reports the size of the touch contact based on its
150157
/// <see cref="screenPosition"/> center point. If not supported, this will be <c>default(Vector2)</c>.
158+
/// <para>
159+
/// Touch radius may also be retrieved directly from the device control via <see cref="TouchControl.radius"/>.
160+
/// </para>
151161
/// </remarks>
152-
/// <seealso cref="TouchControl.radius"/>
153162
public Vector2 radius => state.radius;
154163

155164
/// <summary>
156-
/// Time in seconds on the same timeline as <c>Time.realTimeSinceStartup</c> when the touch began.
165+
/// Start time of the touch in seconds on the same timeline as <c>Time.realTimeSinceStartup</c>.
157166
/// </summary>
158-
/// <value>Start time of the touch.</value>
159167
/// <remarks>
160168
/// This is the value of <see cref="InputEvent.time"/> when the touch started with
161-
/// <see cref="phase"/> <see cref="TouchPhase.Began"/>.
169+
/// <see cref="phase"/> <see cref="TouchPhase.Began"/>. Note that start time may also be retrieved directly
170+
/// from the device control via <see cref="TouchControl.startTime"/>.
162171
/// </remarks>
163-
/// <seealso cref="TouchControl.startTime"/>
164172
public double startTime => state.startTime;
165173

166174
/// <summary>
167-
/// Time in seconds on the same timeline as <c>Time.realTimeSinceStartup</c> when the touch record was
168-
/// reported.
175+
/// Time the touch record was reported on the same timeline as <see cref="UnityEngine.Time.realtimeSinceStartup"/>.
169176
/// </summary>
170-
/// <value>Time the touch record was reported.</value>
171177
/// <remarks>
172178
/// This is the value <see cref="InputEvent.time"/> of the event that signaled the current state
173179
/// change for the touch.
174180
/// </remarks>
175181
public double time => m_TouchRecord.time;
176182

177183
/// <summary>
178-
/// The touchscreen on which the touch occurred.
184+
/// The <see cref="Touchscreen"/> associated with the touch contact.
179185
/// </summary>
180-
/// <value>Touchscreen associated with the touch.</value>
181186
public Touchscreen screen => finger.screen;
182187

183188
/// <summary>
184189
/// Screen-space position of the touch.
185190
/// </summary>
186-
/// <value>Screen-space position of the touch.</value>
187-
/// <seealso cref="TouchControl.position"/>
191+
/// <remarks>Also see <see cref="TouchControl.position"/> for retrieving position directly from a device
192+
/// control.</remarks>
188193
public Vector2 screenPosition => state.position;
189194

190195
/// <summary>
191196
/// Screen-space position where the touch started.
192197
/// </summary>
193-
/// <value>Start position of the touch.</value>
194-
/// <seealso cref="TouchControl.startPosition"/>
198+
/// <remarks>Also see <see cref="TouchControl.startPosition"/> for retrieving start position directly from
199+
/// a device control.</remarks>
195200
public Vector2 startScreenPosition => state.startPosition;
196201

197202
/// <summary>
198203
/// Screen-space motion delta of the touch.
199204
/// </summary>
200-
/// <value>Screen-space motion delta of the touch.</value>
201205
/// <remarks>
202206
/// Note that deltas have behaviors attached to them different from most other
203207
/// controls. See <see cref="Pointer.delta"/> for details.
208+
/// <para>
209+
/// Also see <see cref="TouchControl.delta"/> for retrieving delta directly from a device control.
210+
/// </para>
204211
/// </remarks>
205-
/// <seealso cref="TouchControl.delta"/>
206212
public Vector2 delta => state.delta;
207213

208214
/// <summary>
@@ -214,8 +220,10 @@ public struct Touch : IEquatable<Touch>
214220
/// to increase the tap count. I.e. if a new tap finishes within that time after <see cref="startTime"/>
215221
/// of the previous touch, the tap count is increased by one. If more than <see cref="InputSettings.multiTapDelayTime"/>
216222
/// passes after a tap with no successive tap, the tap count is reset to zero.
223+
/// <para>
224+
/// Also see <see cref="TouchControl.tapCount"/> for retrieving tap count directly from a device control.
225+
/// </para>
217226
/// </remarks>
218-
/// <seealso cref="TouchControl.tapCount"/>
219227
public int tapCount => state.tapCount;
220228

221229
/// <summary>
@@ -227,8 +235,9 @@ public struct Touch : IEquatable<Touch>
227235
/// stays within <see cref="InputSettings.tapRadius"/> of its <see cref="startScreenPosition"/>. If this
228236
/// is the case for a touch, this button is set to 1 at the time the touch goes to <see cref="phase"/>
229237
/// <see cref="TouchPhase.Ended"/>.
230-
///
238+
/// <para>
231239
/// Resets to 0 only when another touch is started on the control or when the control is reset.
240+
/// </para>
232241
/// </remarks>
233242
/// <seealso cref="tapCount"/>
234243
/// <seealso cref="InputSettings.defaultTapTime"/>
@@ -238,16 +247,21 @@ public struct Touch : IEquatable<Touch>
238247
/// <summary>
239248
/// The index of the display containing the touch.
240249
/// </summary>
241-
/// <value>A zero based number representing the display index containing the touch.</value>
242-
/// <seealso cref="TouchControl.displayIndex"/>
243-
/// <seealso cref="Display"/>
250+
/// <remarks>
251+
/// A zero based number representing the display index of the <see cref="Display"/> that contains the touch.
252+
/// <para>
253+
/// Also see <see cref="TouchControl.displayIndex"/> for retrieving display index directly from a device
254+
/// control.
255+
/// </para>
256+
/// </remarks>
244257
public int displayIndex => state.displayIndex;
245258

246259
/// <summary>
247-
/// Whether the touch is currently in progress, i.e. has a <see cref="phase"/> of
248-
/// <see cref="TouchPhase.Began"/>, <see cref="TouchPhase.Moved"/>, or <see cref="TouchPhase.Stationary"/>.
260+
/// Whether the touch is currently in progress.
249261
/// </summary>
250-
/// <value>Whether the touch is currently ongoing.</value>
262+
/// <remarks>This is effectively equivalent to checking if <see cref="phase"/> is equal to either of:
263+
/// <see cref="TouchPhase.Began"/>, <see cref="TouchPhase.Moved"/>, or <see cref="TouchPhase.Stationary"/>.
264+
/// </remarks>
251265
public bool isInProgress
252266
{
253267
get
@@ -287,7 +301,7 @@ public TouchHistory history
287301
}
288302

289303
/// <summary>
290-
/// All touches that are either on-going as of the current frame or have ended in the current frame.
304+
/// All touches that are either ongoing as of the current frame or have ended in the current frame.
291305
/// </summary>
292306
/// <remarks>
293307
/// A touch that begins in a frame will always have its phase set to <see cref="TouchPhase.Began"/> even
@@ -351,14 +365,13 @@ public static ReadOnlyArray<Touch> activeTouches
351365
/// </summary>
352366
/// <remarks>
353367
/// For querying only active fingers, use <see cref="activeFingers"/>.
368+
/// For querying only active touches, use <see cref="activeTouches"/>.
354369
///
355370
/// The length of this array will always correspond to the maximum number of concurrent touches supported by the system.
356371
/// Note that the actual number of physically supported concurrent touches as determined by the current hardware and
357372
/// operating system may be lower than this number.
358373
/// </remarks>
359374
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
360-
/// <seealso cref="activeTouches"/>
361-
/// <seealso cref="activeFingers"/>
362375
public static ReadOnlyArray<Finger> fingers
363376
{
364377
get
@@ -371,9 +384,10 @@ public static ReadOnlyArray<Finger> fingers
371384
/// <summary>
372385
/// Set of currently active fingers, i.e. touch contacts that currently have an active touch (as defined by <see cref="activeTouches"/>).
373386
/// </summary>
387+
/// <remarks>
388+
/// To instead get a collection of all fingers (not only currently active) use <see cref="fingers"/>.
389+
/// </remarks>
374390
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
375-
/// <seealso cref="activeTouches"/>
376-
/// <seealso cref="fingers"/>
377391
public static ReadOnlyArray<Finger> activeFingers
378392
{
379393
get
@@ -401,9 +415,11 @@ public static IEnumerable<Touchscreen> screens
401415
/// <summary>
402416
/// Event that is invoked when a finger touches a <see cref="Touchscreen"/>.
403417
/// </summary>
418+
/// <remarks>
419+
/// In order to react to a finger being moved or released, see <see cref="onFingerMove"/> and
420+
/// <see cref="onFingerUp"/> respectively.
421+
/// </remarks>
404422
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
405-
/// <seealso cref="onFingerUp"/>
406-
/// <seealso cref="onFingerMove"/>
407423
public static event Action<Finger> onFingerDown
408424
{
409425
add
@@ -425,9 +441,11 @@ public static event Action<Finger> onFingerDown
425441
/// <summary>
426442
/// Event that is invoked when a finger stops touching a <see cref="Touchscreen"/>.
427443
/// </summary>
444+
/// <remarks>
445+
/// In order to react to a finger that touches a <see cref="Touchscreen"/> or a finger that is being moved
446+
/// use <see cref="onFingerDown"/> and <see cref="onFingerMove"/> respectively.
447+
/// </remarks>
428448
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
429-
/// <seealso cref="onFingerDown"/>
430-
/// <seealso cref="onFingerMove"/>
431449
public static event Action<Finger> onFingerUp
432450
{
433451
add
@@ -450,9 +468,11 @@ public static event Action<Finger> onFingerUp
450468
/// Event that is invoked when a finger that is in contact with a <see cref="Touchscreen"/> moves
451469
/// on the screen.
452470
/// </summary>
471+
/// <remarks>
472+
/// In order to react to a finger that touches a <see cref="Touchscreen"/> or a finger that stops touching
473+
/// a <see cref="Touchscreen"/>, use <see cref="onFingerDown"/> and <see cref="onFingerUp"/> respectively.
474+
/// </remarks>
453475
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
454-
/// <seealso cref="onFingerUp"/>
455-
/// <seealso cref="onFingerDown"/>
456476
public static event Action<Finger> onFingerMove
457477
{
458478
add
@@ -501,6 +521,7 @@ internal Touch(Finger finger, InputStateHistory<TouchState>.Record touchRecord)
501521
m_TouchRecord = touchRecord;
502522
}
503523

524+
/// <inheritdoc/>
504525
public override string ToString()
505526
{
506527
if (!valid)
@@ -509,16 +530,19 @@ public override string ToString()
509530
return $"{{id={touchId} finger={finger.index} phase={phase} position={screenPosition} delta={delta} time={time}}}";
510531
}
511532

533+
/// <inheritdoc/>
512534
public bool Equals(Touch other)
513535
{
514536
return Equals(m_Finger, other.m_Finger) && m_TouchRecord.Equals(other.m_TouchRecord);
515537
}
516538

539+
/// <inheritdoc/>
517540
public override bool Equals(object obj)
518541
{
519542
return obj is Touch other && Equals(other);
520543
}
521544

545+
/// <inheritdoc/>
522546
public override int GetHashCode()
523547
{
524548
unchecked

0 commit comments

Comments
 (0)