Skip to content

Commit d4c93c3

Browse files
committed
Added example to class documentation
1 parent 15f33ea commit d4c93c3

File tree

1 file changed

+59
-13
lines changed
  • Packages/com.unity.inputsystem/InputSystem/Plugins/EnhancedTouch

1 file changed

+59
-13
lines changed

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

Lines changed: 59 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,24 @@ namespace UnityEngine.InputSystem.EnhancedTouch
3333
/// A Touch instance is a struct which only contains a reference to the actual data which is stored in unmanaged
3434
/// memory.
3535
/// </remarks>
36+
/// <example>
37+
/// <code>
38+
/// void Awake()
39+
/// {
40+
/// // Enable EnhancedTouch.
41+
/// EnhancedTouchSupport.Enable();
42+
/// }
43+
///
44+
/// void Update()
45+
/// {
46+
/// foreach (var touch in Touch.activeTouches)
47+
/// if (touch.began)
48+
/// Debug.Log($"Touch {touch} started this frame");
49+
/// else if (touch.ended)
50+
/// Debug.Log($"Touch {touch} ended this frame");
51+
/// }
52+
/// </code>
53+
/// </example>
3654
[System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Naming", "CA1724:TypeNamesShouldNotMatchNamespaces")]
3755
public struct Touch : IEquatable<Touch>
3856
{
@@ -327,27 +345,55 @@ public TouchHistory history
327345
/// Due to this setup, touch events that will reach <c>UnityEngine.Input</c> only in the next frame may have
328346
/// already reached the Input System.
329347
///
348+
/// In order to evaluate all active touches on a per-frame basis see <see cref="activeFingers"/>.
349+
/// </remarks>
330350
/// <example>
331351
/// <code>
332-
/// void Awake()
333-
/// {
334-
/// // Enable EnhancedTouch.
335-
/// EnhancedTouchSupport.Enable();
336-
/// }
352+
/// using UnityEngine;
353+
/// using UnityEngine.InputSystem.EnhancedTouch;
337354
///
338-
/// void Update()
355+
/// // Alias EnhancedTouch.Touch to "Touch" for less typing.
356+
/// using Touch = UnityEngine.InputSystem.EnhancedTouch.Touch;
357+
/// using TouchPhase = UnityEngine.InputSystem.TouchPhase;
358+
///
359+
/// public class Example : MonoBehaviour
339360
/// {
340-
/// foreach (var touch in Touch.activeTouches)
341-
/// if (touch.began)
342-
/// Debug.Log($"Touch {touch} started this frame");
343-
/// else if (touch.ended)
344-
/// Debug.Log($"Touch {touch} ended this frame");
361+
/// void Awake()
362+
/// {
363+
/// // Note that enhanced touch support needs to be explicitly enabled.
364+
/// EnhancedTouchSupport.Enable();
365+
/// }
366+
///
367+
/// void Update()
368+
/// {
369+
/// // Illustrates how to examine all active touches once per frame and show their last recorded position
370+
/// // in the associated screen-space.
371+
/// foreach (var touch in Touch.activeTouches)
372+
/// {
373+
/// switch (touch.phase)
374+
/// {
375+
/// case TouchPhase.Began:
376+
/// Debug.Log($"Frame {Time.frameCount}: Touch {touch} started this frame at ({touch.screenPosition.x}, {touch.screenPosition.y})");
377+
/// break;
378+
/// case TouchPhase.Ended:
379+
/// Debug.Log($"Frame {Time.frameCount}:Touch {touch} ended this frame at ({touch.screenPosition.x}, {touch.screenPosition.y})");
380+
/// break;
381+
/// case TouchPhase.Moved:
382+
/// Debug.Log($"Frame {Time.frameCount}: Touch {touch} moved this frame to ({touch.screenPosition.x}, {touch.screenPosition.y})");
383+
/// break;
384+
/// case TouchPhase.Canceled:
385+
/// Debug.Log($"Frame {Time.frameCount}: Touch {touch} was canceled this frame");
386+
/// break;
387+
/// case TouchPhase.Stationary:
388+
/// Debug.Log($"Frame {Time.frameCount}: ouch {touch} was not updated this frame");
389+
/// break;
390+
/// }
391+
/// }
392+
/// }
345393
/// }
346394
/// </code>
347395
/// </example>
348-
/// </remarks>
349396
/// <exception cref="InvalidOperationException"><c>EnhancedTouch</c> has not been enabled via <see cref="EnhancedTouchSupport.Enable"/>.</exception>
350-
/// <seealso cref="activeFingers"/>
351397
public static ReadOnlyArray<Touch> activeTouches
352398
{
353399
get

0 commit comments

Comments
 (0)