A game about forced loneliness, made by TACStudios
1////REVIEW: move everything from InputControlExtensions here? 2 3namespace UnityEngine.InputSystem 4{ 5 /// <summary> 6 /// Various useful extension methods. 7 /// </summary> 8 public static class InputExtensions 9 { 10 /// <summary> 11 /// Return true if the given phase is <see cref="InputActionPhase.Started"/> or <see cref="InputActionPhase.Performed"/>. 12 /// </summary> 13 /// <param name="phase">An action phase.</param> 14 /// <returns>True if the phase is started or performed.</returns> 15 /// <seealso cref="InputAction.phase"/> 16 public static bool IsInProgress(this InputActionPhase phase) 17 { 18 return phase == InputActionPhase.Started || phase == InputActionPhase.Performed; 19 } 20 21 /// <summary> 22 /// Return true if the given phase is <see cref="TouchPhase.Canceled"/> or <see cref="TouchPhase.Ended"/>, i.e. 23 /// if a touch with that phase would no longer be ongoing. 24 /// </summary> 25 /// <param name="phase">A touch phase.</param> 26 /// <returns>True if the phase indicates a touch that has ended.</returns> 27 /// <seealso cref="Controls.TouchControl.phase"/> 28 public static bool IsEndedOrCanceled(this TouchPhase phase) 29 { 30 return phase == TouchPhase.Canceled || phase == TouchPhase.Ended; 31 } 32 33 /// <summary> 34 /// Return true if the given phase is <see cref="TouchPhase.Began"/>, <see cref="UnityEngine.TouchPhase.Moved"/>, or 35 /// <see cref="TouchPhase.Stationary"/>, i.e. if a touch with that phase would indicate an ongoing touch. 36 /// </summary> 37 /// <param name="phase">A touch phase.</param> 38 /// <returns>True if the phase indicates a touch that is ongoing.</returns> 39 /// <seealso cref="Controls.TouchControl.phase"/> 40 public static bool IsActive(this TouchPhase phase) 41 { 42 switch (phase) 43 { 44 case TouchPhase.Began: 45 case TouchPhase.Moved: 46 case TouchPhase.Stationary: 47 return true; 48 } 49 return false; 50 } 51 52 /// <summary> 53 /// Check if a <see cref="Key"/> enum value represents a modifier key. 54 /// </summary> 55 /// <param name="key">The key enum value you want to check.</param> 56 /// <returns><c>true</c> if <paramref name="key"/> represents a modifier key, else <c>false</c>.</returns> 57 /// <remarks> 58 /// Modifier keys are any keys you can hold down to modify the output of other keys pressed simultaneously, 59 /// such as the "shift" or "control" keys. 60 /// </remarks> 61 public static bool IsModifierKey(this Key key) 62 { 63 switch (key) 64 { 65 case Key.LeftAlt: 66 case Key.RightAlt: 67 case Key.LeftShift: 68 case Key.RightShift: 69 case Key.LeftMeta: 70 case Key.RightMeta: 71 case Key.LeftCtrl: 72 case Key.RightCtrl: 73 return true; 74 } 75 return false; 76 } 77 78 ////REVIEW: Is this a good idea? Ultimately it's up to any one keyboard layout to define this however it wants. 79 /// <summary> 80 /// Check if a <see cref="Key"/> enum value represents key generating text input. 81 /// </summary> 82 /// <param name="key">The key enum value you want to check.</param> 83 /// <returns><c>true</c> if <paramref name="key"/> represents a key generating non-whitespace text input, else <c>false</c>.</returns> 84 public static bool IsTextInputKey(this Key key) 85 { 86 switch (key) 87 { 88 case Key.LeftShift: 89 case Key.RightShift: 90 case Key.LeftAlt: 91 case Key.RightAlt: 92 case Key.LeftCtrl: 93 case Key.RightCtrl: 94 case Key.LeftMeta: 95 case Key.RightMeta: 96 case Key.ContextMenu: 97 case Key.Escape: 98 case Key.LeftArrow: 99 case Key.RightArrow: 100 case Key.UpArrow: 101 case Key.DownArrow: 102 case Key.Backspace: 103 case Key.PageDown: 104 case Key.PageUp: 105 case Key.Home: 106 case Key.End: 107 case Key.Insert: 108 case Key.Delete: 109 case Key.CapsLock: 110 case Key.NumLock: 111 case Key.PrintScreen: 112 case Key.ScrollLock: 113 case Key.Pause: 114 case Key.None: 115 case Key.Space: 116 case Key.Enter: 117 case Key.Tab: 118 case Key.NumpadEnter: 119 case Key.F1: 120 case Key.F2: 121 case Key.F3: 122 case Key.F4: 123 case Key.F5: 124 case Key.F6: 125 case Key.F7: 126 case Key.F8: 127 case Key.F9: 128 case Key.F10: 129 case Key.F11: 130 case Key.F12: 131 case Key.OEM1: 132 case Key.OEM2: 133 case Key.OEM3: 134 case Key.OEM4: 135 case Key.OEM5: 136 case Key.IMESelected: 137 return false; 138 } 139 return true; 140 } 141 } 142}