Skip to content

Commit b352085

Browse files
committed
Added more examples to methods.
1 parent 208f8dd commit b352085

File tree

1 file changed

+108
-3
lines changed

1 file changed

+108
-3
lines changed

Packages/com.unity.inputsystem/InputSystem/Actions/InputAction.cs

Lines changed: 108 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2169,6 +2169,40 @@ public unsafe void ReadValue(void* buffer, int bufferSize)
21692169
/// <seealso cref="InputAction.ReadValue{TValue}"/>
21702170
/// <seealso cref="ReadValue(void*,int)"/>
21712171
/// <seealso cref="ReadValueAsObject"/>
2172+
/// <example>
2173+
/// <code>
2174+
/// using UnityEngine;
2175+
/// using UnityEngine.InputSystem;
2176+
///
2177+
/// public class Example : MonoBehaviour
2178+
/// {
2179+
/// public InputActionReference move;
2180+
///
2181+
/// void Awake()
2182+
/// {
2183+
/// if (move.action != null)
2184+
/// {
2185+
/// move.action.performed += context =>
2186+
/// {
2187+
/// // Note: Assumes the underlying value type is Vector2.
2188+
/// Vector2 value = context.ReadValue&lt;Vector2&gt;();
2189+
/// Debug.Log($"Value is: {value}");
2190+
/// };
2191+
/// }
2192+
/// }
2193+
///
2194+
/// void OnEnable()
2195+
/// {
2196+
/// move.action?.Enable();
2197+
/// }
2198+
///
2199+
/// void OnDisable()
2200+
/// {
2201+
/// move.action?.Disable();
2202+
/// }
2203+
/// }
2204+
/// </code>
2205+
/// </example>
21722206
public TValue ReadValue<TValue>()
21732207
where TValue : struct
21742208
{
@@ -2192,6 +2226,40 @@ public TValue ReadValue<TValue>()
21922226
/// If the currently active control is a <see cref="ButtonControl"/>, the <see cref="ButtonControl.pressPoint"/>
21932227
/// of the button will be taken into account (if set). If there is no custom button press point, the
21942228
/// global <see cref="InputSettings.defaultButtonPressPoint"/> will be used.
2229+
/// <example>
2230+
/// <code>
2231+
/// using UnityEngine;
2232+
/// using UnityEngine.InputSystem;
2233+
///
2234+
/// public class Example : MonoBehaviour
2235+
/// {
2236+
/// public InputActionReference fire;
2237+
///
2238+
/// void Awake()
2239+
/// {
2240+
/// if (fire.action != null)
2241+
/// {
2242+
/// fire.action.performed += context =>
2243+
/// {
2244+
/// // ReadValueAsButton attempts to interpret the value as a button.
2245+
/// bool value = context.ReadValueAsButton();
2246+
/// Debug.Log($"Button state is: {value}");
2247+
/// };
2248+
/// }
2249+
/// }
2250+
///
2251+
/// void OnEnable()
2252+
/// {
2253+
/// fire.action?.Enable();
2254+
/// }
2255+
///
2256+
/// void OnDisable()
2257+
/// {
2258+
/// fire.action?.Disable();
2259+
/// }
2260+
/// }
2261+
/// </code>
2262+
/// </example>
21952263
/// </remarks>
21962264
/// <seealso cref="InputSettings.defaultButtonPressPoint"/>
21972265
/// <seealso cref="ButtonControl.pressPoint"/>
@@ -2204,14 +2272,51 @@ public bool ReadValueAsButton()
22042272
}
22052273

22062274
/// <summary>
2207-
/// Same as <see cref="ReadValue{TValue}"/> except that it is not necessary to
2208-
/// know the type of value at compile time.
2275+
/// Same as <see cref="ReadValue{TValue}"/> except that it is not necessary to know the type of the value
2276+
/// at compile time.
22092277
/// </summary>
22102278
/// <returns>The current value from the binding that triggered the action or <c>null</c> if the action
22112279
/// is not currently in progress.</returns>
22122280
/// <remarks>
2213-
/// This method allocates GC heap memory. Using it during normal gameplay will lead
2281+
/// This method allocates GC heap memory due to boxing. Using it during normal gameplay will lead
22142282
/// to frame-rate instabilities.
2283+
/// <example>
2284+
/// <code>
2285+
/// using UnityEngine;
2286+
/// using UnityEngine.InputSystem;
2287+
///
2288+
/// public class Example : MonoBehaviour
2289+
/// {
2290+
/// public InputActionReference move;
2291+
///
2292+
/// void Awake()
2293+
/// {
2294+
/// if (move.action != null)
2295+
/// {
2296+
/// move.action.performed += context =>
2297+
/// {
2298+
/// // ReadValueAsObject allows reading the associated value as a boxed reference type.
2299+
/// object obj = context.ReadValueAsObject();
2300+
/// if (obj is Vector2)
2301+
/// Debug.Log($"Current value is Vector2 type: {obj}");
2302+
/// else
2303+
/// Debug.Log($"Current value is of another type: {context.valueType}");
2304+
/// };
2305+
/// }
2306+
/// }
2307+
///
2308+
/// void OnEnable()
2309+
/// {
2310+
/// move.action?.Enable();
2311+
/// }
2312+
///
2313+
/// void OnDisable()
2314+
/// {
2315+
/// move.action?.Disable();
2316+
/// }
2317+
/// }
2318+
/// </code>
2319+
/// </example>
22152320
/// </remarks>
22162321
/// <seealso cref="ReadValue{TValue}"/>
22172322
/// <seealso cref="InputAction.ReadValueAsObject"/>

0 commit comments

Comments
 (0)