From 05d23b81d67990d136776d6b426c1d6240394d2c Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Mon, 2 Dec 2024 14:02:53 +0000 Subject: [PATCH 1/7] Updated InputValue documentation Updated InputValue documentation --- .../Plugins/PlayerInput/InputValue.cs | 69 ++++++++++++++++++- 1 file changed, 68 insertions(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index c781ae9418..c6f9020f44 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -25,7 +25,7 @@ public class InputValue /// Read the value as an object. /// /// - /// This method allocates GC memory and will thus created garbage. If used during gameplay, + /// This method allocates GC memory and will thus create garbage. If used during gameplay, /// it will lead to GC spikes. /// /// The current value in the form of a boxed object. @@ -35,6 +35,43 @@ public object Get() } ////TODO: add automatic conversions + /// + /// Read the value of the action. + /// + /// The current value from the action cast to the specified type. + /// Type of value to read. This must correspond to the + /// expected by either or, if it is a composite, by the + /// in use. + /// Common types are float and Vector2, and depend on the type of the associated action + /// The given type + /// does not match the value type expected by the control or binding composite. + /// + /// The following example shows how to read a value from a message. + /// + /// + /// + /// [RequireComponent(typeof(PlayerInput))] + /// public class MyPlayerLogic : MonoBehaviour + /// { + /// private Vector2 m_Move; + /// + /// // 'Move' input action has been triggered. + /// public void OnMove(InputValue value) + /// { + /// // Read value from control. The type depends on what type of controls the action is bound to. + /// m_Move = value.Get<Vector2>(); + /// } + /// + /// public void OnUpdate() + /// { + /// // Update transform from m_Move + /// } + /// } + /// + /// + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// + /// public TValue Get() where TValue : struct { @@ -45,6 +82,36 @@ public TValue Get() } ////TODO: proper message if value type isn't right + /// + /// Check if the action button is pressed + /// + /// True if the button is activated over the button threshold. False otherwise + /// + /// The following example shows how to read a value from a message. + /// + /// + /// + /// [RequireComponent(typeof(PlayerInput))] + /// public class MyPlayerLogic : MonoBehaviour + /// { + /// private bool m_Fire; + /// + /// // 'Fire' input action has been triggered. + /// public void OnFire(InputValue value) + /// { + /// m_Fire = value.isPressed; + /// } + /// + /// public void OnUpdate() + /// { + /// // Perform fire action if m_Fire is true + /// } + /// } + /// + /// + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// + /// public bool isPressed => Get() >= ButtonControl.s_GlobalDefaultButtonPressPoint; internal InputAction.CallbackContext? m_Context; From 8634a0646f95a54f5ea7271cd84915e9547bc873 Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Mon, 2 Dec 2024 14:22:19 +0000 Subject: [PATCH 2/7] Minor formatting update --- .../InputSystem/Plugins/PlayerInput/InputValue.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index c6f9020f44..c15f25af5d 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -42,12 +42,12 @@ public object Get() /// Type of value to read. This must correspond to the /// expected by either or, if it is a composite, by the /// in use. - /// Common types are float and Vector2, and depend on the type of the associated action + /// The type depends on what type of controls the action is bound to. Common types are float and Vector2 /// The given type /// does not match the value type expected by the control or binding composite. /// /// The following example shows how to read a value from a message. - /// + /// /// /// /// [RequireComponent(typeof(PlayerInput))] @@ -61,7 +61,7 @@ public object Get() /// // Read value from control. The type depends on what type of controls the action is bound to. /// m_Move = value.Get<Vector2>(); /// } - /// + /// /// public void OnUpdate() /// { /// // Update transform from m_Move @@ -88,7 +88,7 @@ public TValue Get() /// True if the button is activated over the button threshold. False otherwise /// /// The following example shows how to read a value from a message. - /// + /// /// /// /// [RequireComponent(typeof(PlayerInput))] @@ -101,7 +101,7 @@ public TValue Get() /// { /// m_Fire = value.isPressed; /// } - /// + /// /// public void OnUpdate() /// { /// // Perform fire action if m_Fire is true From 82023e22534efbce777eb04a010431552dab6236 Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Mon, 2 Dec 2024 15:01:28 +0000 Subject: [PATCH 3/7] Feedback updates --- .../InputSystem/Plugins/PlayerInput/InputValue.cs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index c15f25af5d..2c2c8becf1 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -22,7 +22,7 @@ namespace UnityEngine.InputSystem public class InputValue { /// - /// Read the value as an object. + /// Read the current value as an object. /// /// /// This method allocates GC memory and will thus create garbage. If used during gameplay, @@ -36,13 +36,13 @@ public object Get() ////TODO: add automatic conversions /// - /// Read the value of the action. + /// Read the current value of the action. /// /// The current value from the action cast to the specified type. /// Type of value to read. This must correspond to the /// expected by either or, if it is a composite, by the /// in use. - /// The type depends on what type of controls the action is bound to. Common types are float and Vector2 + /// The type depends on what type of controls the action is bound to. Common types are float and /// The given type /// does not match the value type expected by the control or binding composite. /// @@ -69,7 +69,7 @@ public object Get() /// } /// /// - /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. /// /// public TValue Get() @@ -83,7 +83,7 @@ public TValue Get() ////TODO: proper message if value type isn't right /// - /// Check if the action button is pressed + /// Check if the action button is pressed. /// /// True if the button is activated over the button threshold. False otherwise /// @@ -109,7 +109,7 @@ public TValue Get() /// } /// /// - /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. /// /// public bool isPressed => Get() >= ButtonControl.s_GlobalDefaultButtonPressPoint; From 9a5efa3a4322399831acabf3672bdc7e6f8bdc78 Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Mon, 2 Dec 2024 15:40:08 +0000 Subject: [PATCH 4/7] Fixed XMLDoc validation error --- .../InputSystem/Plugins/PlayerInput/InputValue.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index 2c2c8becf1..69a6f3e3b6 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -71,7 +71,7 @@ public object Get() /// /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. /// - /// + /// public TValue Get() where TValue : struct { From 1a31cbb3ea39360d7453e62ffefc8cf3128eefb8 Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Mon, 2 Dec 2024 16:31:59 +0000 Subject: [PATCH 5/7] Documentation feedback and fixed a test validation failure --- .../Plugins/PlayerInput/InputValue.cs | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index 69a6f3e3b6..e3be0edbef 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -40,9 +40,10 @@ public object Get() /// /// The current value from the action cast to the specified type. /// Type of value to read. This must correspond to the - /// expected by either or, if it is a composite, by the - /// in use. - /// The type depends on what type of controls the action is bound to. Common types are float and + /// of the action or, if it is a composite, by the + /// . + /// The type depends on what type of controls the action is bound to. + /// Common types are float and /// The given type /// does not match the value type expected by the control or binding composite. /// @@ -62,7 +63,7 @@ public object Get() /// m_Move = value.Get<Vector2>(); /// } /// - /// public void OnUpdate() + /// public void Update() /// { /// // Update transform from m_Move /// } @@ -87,24 +88,23 @@ public TValue Get() /// /// True if the button is activated over the button threshold. False otherwise /// - /// The following example shows how to read a value from a message. + /// The following example check if a button is pressed when receiving a message. /// /// /// /// [RequireComponent(typeof(PlayerInput))] /// public class MyPlayerLogic : MonoBehaviour /// { - /// private bool m_Fire; - /// /// // 'Fire' input action has been triggered. /// public void OnFire(InputValue value) /// { - /// m_Fire = value.isPressed; + /// if (value.isPressed) + /// FireWeapon(); /// } /// - /// public void OnUpdate() + /// public void FireWeapon() /// { - /// // Perform fire action if m_Fire is true + /// // Weapon firing code /// } /// } /// From b875e48a2c134e88a74fab4cd456f1ba2e18615c Mon Sep 17 00:00:00 2001 From: Ben Pitt Date: Tue, 3 Dec 2024 12:33:16 +0000 Subject: [PATCH 6/7] added "using" statement to code example --- .../InputSystem/Plugins/PlayerInput/InputValue.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index e3be0edbef..b8862170dd 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -51,6 +51,8 @@ public object Get() /// /// /// + /// using UnityEngine; + /// using UnityEngine.InputSystem; /// [RequireComponent(typeof(PlayerInput))] /// public class MyPlayerLogic : MonoBehaviour /// { From 3cfee0ae42f737695ceaa1caa18b7ea0a581a48e Mon Sep 17 00:00:00 2001 From: Lyndon Homewood Date: Tue, 3 Dec 2024 15:46:00 +0000 Subject: [PATCH 7/7] Fixed examples structure --- .../InputSystem/Plugins/PlayerInput/InputValue.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs index b8862170dd..61cba088fb 100644 --- a/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs +++ b/Packages/com.unity.inputsystem/InputSystem/Plugins/PlayerInput/InputValue.cs @@ -48,7 +48,8 @@ public object Get() /// does not match the value type expected by the control or binding composite. /// /// The following example shows how to read a value from a message. - /// + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// /// /// /// using UnityEngine; @@ -72,8 +73,6 @@ public object Get() /// } /// /// - /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. - /// /// public TValue Get() where TValue : struct @@ -88,10 +87,11 @@ public TValue Get() /// /// Check if the action button is pressed. /// - /// True if the button is activated over the button threshold. False otherwise /// + /// True if the button is activated over the button threshold. False otherwise /// The following example check if a button is pressed when receiving a message. - /// + /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. + /// /// /// /// [RequireComponent(typeof(PlayerInput))] @@ -111,8 +111,6 @@ public TValue Get() /// } /// /// - /// The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get<T>() later does not work correctly. - /// /// public bool isPressed => Get() >= ButtonControl.s_GlobalDefaultButtonPressPoint;