diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs
new file mode 100644
index 0000000000..a6b86e6ba4
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs
@@ -0,0 +1,15 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+///
+/// Example script demonstrating how to look up a project-wide action.
+///
+public class AboutProjectWideActions : MonoBehaviour
+{
+ void Start()
+ {
+ #region about-project-wide-actions
+ InputSystem.actions.FindAction("Move");
+ #endregion
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs.meta
new file mode 100644
index 0000000000..ab449314a7
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 3f685e3a55948f643b87a9f7ffa03e45
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs
new file mode 100644
index 0000000000..596eff6cd3
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs
@@ -0,0 +1,44 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+class BindingConflictsExample
+{
+ public void Example()
+ {
+ #region bindingConflicts
+ // Create two actions in the same map.
+ var map = new InputActionMap();
+ var bAction = map.AddAction("B");
+ var shiftbAction = map.AddAction("ShiftB");
+
+ // Bind one of the actions to 'B' and the other to 'SHIFT+B'.
+ bAction.AddBinding("/b");
+ shiftbAction.AddCompositeBinding("OneModifier")
+ .With("Modifier", "/shift")
+ .With("Binding", "/b");
+
+ // Print something to the console when the actions are triggered.
+ bAction.performed += _ => Debug.Log("B action performed");
+ shiftbAction.performed += _ => Debug.Log("SHIFT+B action performed");
+
+ // Start listening to input.
+ map.Enable();
+
+ var keyboard = Keyboard.current ?? InputSystem.AddDevice();
+
+ // Now, let's assume the left shift key on the keyboard is pressed (here, we manually
+ // press it by queueing a state event for the control).
+ InputSystem.QueueDeltaStateEvent(keyboard.leftShiftKey, 1f);
+ InputSystem.Update();
+
+ // And then the B is pressed. This is a valid input for both
+ // bAction as well as shiftbAction.
+ //
+ // What will happen now is that shiftbAction will do its processing first. In response,
+ // it will *perform* the action (That is, we see the `performed` callback being invoked) and
+ // thus "consume" the input. bAction will stay silent as it will in turn be skipped over.
+ InputSystem.QueueDeltaStateEvent(keyboard.bKey, 1f);
+ InputSystem.Update();
+ #endregion
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs.meta
new file mode 100644
index 0000000000..6bb66d8fc2
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 516647ab991fd414bae37dc8e5448ed1
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs
new file mode 100644
index 0000000000..82b6791950
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs
@@ -0,0 +1,79 @@
+namespace DocCodeSamples.Tests
+{
+ #region declaration
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+
+ ///
+ /// Example script exposing serialized action references.
+ ///
+ public class ExampleScript : MonoBehaviour
+ {
+ ///
+ /// Reference to the "move" action.
+ ///
+ public InputAction move;
+
+ ///
+ /// Reference to the "jump" action.
+ ///
+ public InputAction jump;
+ }
+ #endregion
+
+ class ConfigureInputfromCode : MonoBehaviour
+ {
+ const string json = @"
+ {
+ ""maps"" : [
+ {
+ ""name"" : ""gameplay"",
+ ""actions"" : [
+ { ""name"" : ""fire"", ""type"" : ""button"" }
+ ]
+ }
+ ]
+ }";
+
+ void ConfigureFromJsonExample()
+ {
+ #region configurefromjson
+ // Load a set of action maps from JSON.
+ var maps = InputActionMap.FromJson(json);
+
+ // Load an entire InputActionAsset from JSON.
+ var asset = InputActionAsset.FromJson(json);
+ #endregion
+ }
+
+ void Start()
+ {
+ #region configurefromcode
+ {
+ // Create free-standing actions.
+ var lookAction = new InputAction("look", binding: "/leftStick");
+ var moveAction = new InputAction("move", binding: "/rightStick");
+
+ moveAction.AddCompositeBinding("1DAxis")
+ .With("Left", "/a")
+ .With("Right", "/d");
+ }
+
+ {
+ // Create an action map with actions.
+ var map = new InputActionMap("Gameplay");
+ var lookAction = map.AddAction("look");
+ lookAction.AddBinding("/leftStick");
+ }
+
+ {
+ // Create an action asset.
+ var asset = ScriptableObject.CreateInstance();
+ var gameplayMap = new InputActionMap("gameplay");
+ asset.AddActionMap(gameplayMap);
+ var lookAction = gameplayMap.AddAction("look", binding: "/leftStick");
+ }
+ #endregion
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs.meta
new file mode 100644
index 0000000000..b3c59b1cfc
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 530760504145d164081d6f8d53d4d7b3
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs
new file mode 100644
index 0000000000..c70bcb3382
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs
@@ -0,0 +1,94 @@
+namespace DocCodeSamples.Tests.ConfigureUnityEvents_ManualEnable
+{
+ #region manualEnableSingleton
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+
+ ///
+ /// Example script demonstrating manually enabling actions instead of using the
+ /// default project-wide action map.
+ ///
+ public class MyPlayerScript : MonoBehaviour
+ {
+ PlayerInput playerInput;
+
+ void Start()
+ {
+ playerInput = GetComponent();
+ InputSystem.actions.Disable();
+ playerInput.currentActionMap?.Enable();
+ }
+ }
+ #endregion
+}
+
+namespace DocCodeSamples.Tests.ConfigureUnityEvents_SendMessages
+{
+ #region sendMessages
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+
+ ///
+ /// Example script demonstrating the PlayerInput "Send Messages" behavior.
+ ///
+ public class MyPlayerScript : MonoBehaviour
+ {
+ // "jump" action becomes "OnJump" method.
+
+ ///
+ /// Called by PlayerInput when the "jump" action is triggered.
+ ///
+ // If you're not interested in the value from the control that triggers the action, use a method without arguments.
+ public void OnJump()
+ {
+ // your Jump code here
+ }
+
+ ///
+ /// Called by PlayerInput when the "move" action is triggered.
+ ///
+ /// Value of the control that triggered the action.
+ // If you are interested in the value from the control that triggers an action, you can declare a parameter of type InputValue.
+ public void OnMove(InputValue value)
+ {
+ // Read value from control. The type depends on what type of controls.
+ // the action is bound to.
+ var v = value.Get();
+
+ // IMPORTANT:
+ // The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get() later does not work correctly.
+ }
+ }
+ #endregion
+}
+
+namespace DocCodeSamples.Tests.ConfigureUnityEvents_InvokeUnityEvents
+{
+ #region invokeUnityEvents
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+
+ ///
+ /// Example script demonstrating the PlayerInput "Invoke Unity Events" behavior.
+ ///
+ public class MyPlayerScript : MonoBehaviour
+ {
+ ///
+ /// Called when the "fire" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnFire(InputAction.CallbackContext context)
+ {
+ }
+
+ ///
+ /// Called when the "move" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnMove(InputAction.CallbackContext context)
+ {
+ var value = context.ReadValue();
+ }
+ }
+ #endregion
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs.meta
new file mode 100644
index 0000000000..93269240ec
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 011c441b0e8cc5e4483097a37462f77c
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs
new file mode 100644
index 0000000000..cb0b142c3b
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs
@@ -0,0 +1,20 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+class ControlActuation : MonoBehaviour
+{
+ void Example()
+ {
+ #region actuation
+ // Check if leftStick is currently actuated.
+ if (Gamepad.current.leftStick.IsActuated())
+ Debug.Log("Left Stick is actuated");
+ #endregion
+
+ #region actuation2
+ // Check if left stick is actuated more than a quarter of its motion range.
+ if (Gamepad.current.leftStick.EvaluateMagnitude() > 0.25f)
+ Debug.Log("Left Stick actuated past 25%");
+ #endregion
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs.meta
new file mode 100644
index 0000000000..dc44b1d77c
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 6205d9108c3cef94bac6487cdff56fda
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs
new file mode 100644
index 0000000000..0f5d73fa15
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs
@@ -0,0 +1,45 @@
+using System.Linq;
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+class ControlPathsExample
+{
+ void Example()
+ {
+ #region parse
+ var parsed = InputControlPath.Parse("{LeftHand}/trigger").ToArray();
+
+ Debug.Log(parsed.Length); // Prints 2.
+ Debug.Log(parsed[0].layout); // Prints "XRController".
+ Debug.Log(parsed[0].name); // Prints an empty string.
+ Debug.Log(parsed[0].usages.First()); // Prints "LeftHand".
+ Debug.Log(parsed[1].layout); // Prints null.
+ Debug.Log(parsed[1].name); // Prints "trigger".
+ #endregion
+
+ #region findcontrols
+ var gamepad = Gamepad.all[0];
+ var leftStickX = gamepad["leftStick/x"];
+ var submitButton = gamepad["{Submit}"];
+ var allSubmitButtons = InputSystem.FindControls("*/{Submit}");
+ #endregion
+ }
+
+ void PathExamples()
+ {
+ #region pathExamples
+ // Matches all gamepads (also gamepads *based* on the Gamepad layout):
+ _ = "";
+ // Matches the "Submit" control on all devices:
+ _ = "*/";
+ // Matches the key that prints the "a" character on the current keyboard layout:
+ _ = "/#(a)";
+ // Matches the X axis of the left stick on a gamepad.
+ _ = "/leftStick/x";
+ // Matches the orientation control of the right-hand XR controller:
+ _ = "/orientation";
+ // Matches all buttons on a gamepad.
+ _ = "/";
+ #endregion
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs.meta
new file mode 100644
index 0000000000..74ff939df4
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 6cd13028e5f6fca49ba63d6ce015fa3b
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs
new file mode 100644
index 0000000000..7466c2f6e8
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs
@@ -0,0 +1,69 @@
+using UnityEngine;
+using UnityEditor;
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.Editor;
+
+namespace DocCodeSamples.Tests
+{
+ #region registernewprocessor
+ #if UNITY_EDITOR
+ [InitializeOnLoad]
+ #endif
+ ///
+ /// Example custom processor that registers itself with the Input System.
+ ///
+ public class MyValueShiftProcessor : InputProcessor
+ {
+ #if UNITY_EDITOR
+ static MyValueShiftProcessor()
+ {
+ Initialize();
+ }
+
+ #endif
+
+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
+ static void Initialize()
+ {
+ InputSystem.RegisterProcessor();
+ }
+
+ ///
+ /// Returns unchanged.
+ ///
+ /// Value to process.
+ /// Control from which the value originates.
+ /// The unchanged value.
+ public override float Process(float value, InputControl control)
+ {
+ return value;
+ }
+ }
+ #endregion
+
+ class ProcessorExamples : MonoBehaviour
+ {
+ void Start()
+ {
+ #region inputactionwithprocessor
+ var action = new InputAction(processors: "myvalueshift(valueShift=2.3)");
+ #endregion
+ }
+
+ void ConfigureProcessorBinding()
+ {
+ #region processorbindings
+ var action = new InputAction();
+ action.AddBinding("/leftStick")
+ .WithProcessor("invertVector2(invertX=false)");
+ #endregion
+ }
+
+ void AddProcessor()
+ {
+ #region addprocessor
+ var action = new InputAction(processors: "invertVector2(invertX=false)");
+ #endregion
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs.meta
new file mode 100644
index 0000000000..e0834c6da5
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: b792b40e3ffd72841b7a589e13c1f7d8
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs
new file mode 100644
index 0000000000..5d4ac9a385
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs
@@ -0,0 +1,30 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+///
+/// Example script demonstrating how to use the generated default actions class.
+///
+public class DefaultActions : MonoBehaviour
+{
+ #region default-actions
+ void Start()
+ {
+ // Create an instance of the default actions.
+ var actions = new DefaultInputActions();
+ actions.Player.Look.performed += OnLook;
+ actions.Player.Move.performed += OnMove;
+ actions.Enable();
+ }
+
+ #endregion
+
+ void OnLook(InputAction.CallbackContext context)
+ {
+ // your look code here
+ }
+
+ void OnMove(InputAction.CallbackContext context)
+ {
+ // your move code here
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs.meta
new file mode 100644
index 0000000000..8823f79d9a
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: ed9135782d61c324e81196fcd2a7b1d6
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs
index b1c414641b..c375f1e205 100644
--- a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs
@@ -44,5 +44,28 @@ void Update()
if (gamepad.startButton.wasPressedThisFrame)
gamepad.ResetHaptics();
}
+
+ void SetMotorSpeedsExample()
+ {
+ #region setMotorSpeeds
+ // Rumble the low-frequency (left) motor at 1/4 speed and the high-frequency
+ // (right) motor at 3/4 speed.
+ Gamepad.current.SetMotorSpeeds(0.25f, 0.75f);
+ #endregion
+ }
+
+ void GlobalHapticsExample()
+ {
+ #region globalHaptics
+ // Pause haptics globally.
+ InputSystem.PauseHaptics();
+
+ // Resume haptics globally.
+ InputSystem.ResumeHaptics();
+
+ // Stop haptics globally.
+ InputSystem.ResetHaptics();
+ #endregion
+ }
}
}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs
new file mode 100644
index 0000000000..dd8e9216c6
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs
@@ -0,0 +1,15 @@
+namespace DocCodeSamples.Tests
+{
+ using UnityEngine.InputSystem;
+
+ internal class GamepadPolling
+ {
+ void Example()
+ {
+ #region pollingFrequency
+ // Poll gamepads at 120 Hz.
+ InputSystem.pollingFrequency = 120;
+ #endregion
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs.meta
new file mode 100644
index 0000000000..9769cb0a5d
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 59ccd1766501a5141b0f2552eda97bf0
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs
new file mode 100644
index 0000000000..eb757082a9
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs
@@ -0,0 +1,65 @@
+namespace DocCodeSamples.Tests
+{
+ #region generate-cs-api
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+
+ // IGameplayActions is an interface generated from the newly added "gameplay"
+ // action map, triggered by the "Generate Interfaces" checkbox. Note that if
+ // you change the default values for the action map, the name of the interface
+ // will be different.
+
+ ///
+ /// Example script showing how to consume a C# class generated from an
+ /// .inputactions asset via the "Generate C# Class" option.
+ ///
+ public class MyPlayerScript : MonoBehaviour, MyPlayerControls.IGameplayActions
+ {
+ // MyPlayerControls is the C# class that Unity generated.
+ // It encapsulates the data from the .inputactions asset we created
+ // and automatically looks up all the maps and actions for us.
+ MyPlayerControls controls;
+
+ ///
+ /// Called by Unity when the component is enabled.
+ ///
+ public void OnEnable()
+ {
+ if (controls == null)
+ {
+ controls = new MyPlayerControls();
+ // Tell the "gameplay" action map that we want to be
+ // notified when actions get triggered.
+ controls.gameplay.SetCallbacks(this);
+ }
+ controls.gameplay.Enable();
+ }
+
+ ///
+ /// Called by Unity when the component is disabled.
+ ///
+ public void OnDisable()
+ {
+ controls.gameplay.Disable();
+ }
+
+ ///
+ /// Called when the "use" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnUse(InputAction.CallbackContext context)
+ {
+ // 'Use' code here.
+ }
+
+ ///
+ /// Called when the "move" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnMove(InputAction.CallbackContext context)
+ {
+ // 'Move' code here.
+ }
+ }
+ #endregion
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs.meta
new file mode 100644
index 0000000000..d2534ea987
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 734071bd08f7d0e44806e83545714cc4
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs
new file mode 100644
index 0000000000..8cd4b6cd91
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs
@@ -0,0 +1,232 @@
+namespace DocCodeSamples.Tests
+{
+ using System.Runtime.InteropServices;
+ using UnityEngine.InputSystem;
+ using UnityEngine.InputSystem.Controls;
+ using UnityEngine.InputSystem.Layouts;
+ using UnityEngine.InputSystem.LowLevel;
+ using UnityEngine.InputSystem.Utilities;
+
+ #region customDeviceClass
+ ///
+ /// Example state struct describing the memory layout of .
+ ///
+ public struct MyDeviceState : IInputStateTypeInfo
+ {
+ // FourCC type codes are used to identify the memory layouts of state blocks.
+ ///
+ /// The memory format identifier for this state struct.
+ ///
+ public FourCC format => new FourCC('M', 'D', 'E', 'V');
+
+ ///
+ /// Bit-packed state for firstButton and secondButton .
+ ///
+ [InputControl(name = "firstButton", layout = "Button", bit = 0)]
+ [InputControl(name = "secondButton", layout = "Button", bit = 1)]
+ public int buttons;
+
+ ///
+ /// Raw state for the device's analog axis control.
+ ///
+ [InputControl(layout = "Analog", parameters = "clamp=true,clampMin=0,clampMax=1")]
+ public float axis;
+ }
+
+ ///
+ /// Example custom device class using as its state layout.
+ ///
+ [InputControlLayout(stateType = typeof(MyDeviceState))]
+ public class MyDevice : InputDevice
+ {
+ ///
+ /// The device's first button control.
+ ///
+ public ButtonControl firstButton { get; private set; }
+
+ ///
+ /// The device's second button control.
+ ///
+ public ButtonControl secondButton { get; private set; }
+
+ ///
+ /// The device's analog axis control.
+ ///
+ public AxisControl axis { get; private set; }
+
+ ///
+ /// Looks up the device's child controls after they have been created.
+ ///
+ protected override void FinishSetup()
+ {
+ base.FinishSetup();
+
+ firstButton = GetChildControl("firstButton");
+ secondButton = GetChildControl("secondButton");
+ axis = GetChildControl("axis");
+ }
+ }
+ #endregion
+
+ class HidCreateCustomLayoutClassExamples
+ {
+ void RegisterAndCreate()
+ {
+ #region registerMyDevice
+ InputSystem.RegisterLayout(typeof(MyDevice), "MyDevice");
+ var device = InputSystem.AddDevice("MyDevice");
+ #endregion
+ }
+ }
+
+ #region dualShock4HidInputReport
+ // We receive data as raw HID input reports. This struct
+ // describes the raw binary format of such a report.
+ [StructLayout(LayoutKind.Explicit, Size = 32)]
+ struct DualShock4HIDInputReport : IInputStateTypeInfo
+ {
+ // Because all HID input reports are tagged with the 'HID ' FourCC,
+ // this is the format we need to use for this state struct.
+ public FourCC format => new FourCC('H', 'I', 'D');
+
+ // HID input reports can start with an 8-bit report ID. It depends on the device
+ // whether this is present or not. On the PS4 DualShock controller, it is
+ // present. We don't really need to add the field, but let's do so for the sake of
+ // completeness. This can also help with debugging.
+ [FieldOffset(0)] public byte reportId;
+
+ // The InputControl annotations here probably look a little scary, but what we do
+ // here is relatively straightforward. The fields we add we annotate with
+ // [FieldOffset] to force them to the right location, and then we add InputControl
+ // to attach controls to the fields. Each InputControl attribute can only do one of
+ // two things: either it adds a new control or it modifies an existing control.
+ // Given that our layout is based on Gamepad, almost all the controls here are
+ // inherited from Gamepad, and we just modify settings on them.
+
+ [InputControl(name = "leftStick", layout = "Stick", format = "VC2B")]
+ [InputControl(name = "leftStick/x", offset = 0, format = "BYTE",
+ parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
+ [InputControl(name = "leftStick/left", offset = 0, format = "BYTE",
+ parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
+ [InputControl(name = "leftStick/right", offset = 0, format = "BYTE",
+ parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1")]
+ [InputControl(name = "leftStick/y", offset = 1, format = "BYTE",
+ parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
+ [InputControl(name = "leftStick/up", offset = 1, format = "BYTE",
+ parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
+ [InputControl(name = "leftStick/down", offset = 1, format = "BYTE",
+ parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1,invert=false")]
+ [FieldOffset(1)] public byte leftStickX;
+ [FieldOffset(2)] public byte leftStickY;
+
+ [InputControl(name = "rightStick", layout = "Stick", format = "VC2B")]
+ [InputControl(name = "rightStick/x", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
+ [InputControl(name = "rightStick/left", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
+ [InputControl(name = "rightStick/right", offset = 0, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1")]
+ [InputControl(name = "rightStick/y", offset = 1, format = "BYTE", parameters = "invert,normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5")]
+ [InputControl(name = "rightStick/up", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0,clampMax=0.5,invert")]
+ [InputControl(name = "rightStick/down", offset = 1, format = "BYTE", parameters = "normalize,normalizeMin=0,normalizeMax=1,normalizeZero=0.5,clamp,clampMin=0.5,clampMax=1,invert=false")]
+ [FieldOffset(3)] public byte rightStickX;
+ [FieldOffset(4)] public byte rightStickY;
+
+ [InputControl(name = "dpad", format = "BIT", layout = "Dpad", sizeInBits = 4, defaultState = 8)]
+ [InputControl(name = "dpad/up", format = "BIT", layout = "DiscreteButton", parameters = "minValue=7,maxValue=1,nullValue=8,wrapAtValue=7", bit = 0, sizeInBits = 4)]
+ [InputControl(name = "dpad/right", format = "BIT", layout = "DiscreteButton", parameters = "minValue=1,maxValue=3", bit = 0, sizeInBits = 4)]
+ [InputControl(name = "dpad/down", format = "BIT", layout = "DiscreteButton", parameters = "minValue=3,maxValue=5", bit = 0, sizeInBits = 4)]
+ [InputControl(name = "dpad/left", format = "BIT", layout = "DiscreteButton", parameters = "minValue=5, maxValue=7", bit = 0, sizeInBits = 4)]
+ [InputControl(name = "buttonWest", displayName = "Square", bit = 4)]
+ [InputControl(name = "buttonSouth", displayName = "Cross", bit = 5)]
+ [InputControl(name = "buttonEast", displayName = "Circle", bit = 6)]
+ [InputControl(name = "buttonNorth", displayName = "Triangle", bit = 7)]
+ [FieldOffset(5)] public byte buttons1;
+
+ [InputControl(name = "leftShoulder", bit = 0)]
+ [InputControl(name = "rightShoulder", bit = 1)]
+ [InputControl(name = "leftTriggerButton", layout = "Button", bit = 2)]
+ [InputControl(name = "rightTriggerButton", layout = "Button", bit = 3)]
+ [InputControl(name = "select", displayName = "Share", bit = 4)]
+ [InputControl(name = "start", displayName = "Options", bit = 5)]
+ [InputControl(name = "leftStickPress", bit = 6)]
+ [InputControl(name = "rightStickPress", bit = 7)]
+ [FieldOffset(6)] public byte buttons2;
+
+ [InputControl(name = "systemButton", layout = "Button", displayName = "System", bit = 0)]
+ [InputControl(name = "touchpadButton", layout = "Button", displayName = "Touchpad Press", bit = 1)]
+ [FieldOffset(7)] public byte buttons3;
+
+ [InputControl(name = "leftTrigger", format = "BYTE")]
+ [FieldOffset(8)] public byte leftTrigger;
+
+ [InputControl(name = "rightTrigger", format = "BYTE")]
+ [FieldOffset(9)] public byte rightTrigger;
+
+ [FieldOffset(30)] public byte batteryLevel;
+ }
+ #endregion
+}
+
+namespace DocCodeSamples.Tests.DualShock4GamepadHidBasic
+{
+ using DocCodeSamples.Tests;
+ using UnityEngine.InputSystem;
+ using UnityEngine.InputSystem.Layouts;
+
+ #region dualShock4GamepadHidBasic
+ // Using InputControlLayoutAttribute, we tell the system about the state
+ // struct we created, which includes where to find all the InputControl
+ // attributes that we placed on there. This is how the Input System knows
+ // what controls to create and how to configure them.
+ ///
+ /// Example device layout for a PS4 DualShock controller reported as a generic HID.
+ ///
+ [InputControlLayout(stateType = typeof(DualShock4HIDInputReport))]
+ public class DualShock4GamepadHID : Gamepad
+ {
+ }
+ #endregion
+}
+
+namespace DocCodeSamples.Tests.DualShock4GamepadHidRegister
+{
+ using DocCodeSamples.Tests;
+ using UnityEditor;
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+ using UnityEngine.InputSystem.Layouts;
+
+ #region dualShock4GamepadHidRegister
+ ///
+ /// Example device layout for a PS4 DualShock controller that registers itself
+ /// as a match for the corresponding HID device description.
+ ///
+ [InputControlLayout(stateType = typeof(DualShock4HIDInputReport))]
+ #if UNITY_EDITOR
+ [InitializeOnLoad] // Make sure static constructor is called during startup.
+ #endif
+ public class DualShock4GamepadHID : Gamepad
+ {
+ static DualShock4GamepadHID()
+ {
+ // This is one way to match the device.
+ InputSystem.RegisterLayout(
+ matches: new InputDeviceMatcher()
+ .WithInterface("HID")
+ .WithManufacturer("Sony.+Entertainment")
+ .WithProduct("Wireless Controller"));
+
+ // Alternatively, you can also match by PID and VID, which is generally
+ // more reliable for HIDs.
+ InputSystem.RegisterLayout(
+ matches: new InputDeviceMatcher()
+ .WithInterface("HID")
+ .WithCapability("vendorId", 0x54C) // Sony Entertainment.
+ .WithCapability("productId", 0x9CC)); // Wireless controller.
+ }
+
+ // In the Player, to trigger the calling of the static constructor,
+ // create an empty method annotated with RuntimeInitializeOnLoadMethod.
+ [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
+ static void Init() {}
+ }
+ #endregion
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs.meta
new file mode 100644
index 0000000000..eaa2ef4b93
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 946bd56a5947977459b6467117b14992
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs
new file mode 100644
index 0000000000..1a3cce488f
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs
@@ -0,0 +1,47 @@
+namespace DocCodeSamples.Tests
+{
+ using UnityEngine.InputSystem;
+
+ internal class HidCreateCustomLayoutExisting
+ {
+ const string myDeviceJson = @"
+#region myDeviceJson
+ {
+ ""name"" : ""MyDevice"",
+ ""extend"" : ""Gamepad"", // Or some other thing
+ ""controls"" : [
+ {
+ ""name"" : ""firstButton"",
+ ""layout"" : ""Button"",
+ ""offset"" : 0,
+ ""bit"": 0,
+ ""format"" : ""BIT""
+ },
+ {
+ ""name"" : ""secondButton"",
+ ""layout"" : ""Button"",
+ ""offset"" : 0,
+ ""bit"": 1,
+ ""format"" : ""BIT""
+ },
+ {
+ ""name"" : ""axis"",
+ ""layout"" : ""Axis"",
+ ""offset"" : 4,
+ ""format"" : ""FLT"",
+ ""parameters"" : ""clamp=true,clampMin=0,clampMax=1""
+ }
+ ]
+ }
+#endregion
+";
+
+ void Example()
+ {
+ #region registerAndCreate
+ InputSystem.RegisterLayout(myDeviceJson);
+ var device = InputSystem.AddDevice("MyDevice");
+ #endregion
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs.meta
new file mode 100644
index 0000000000..4398154770
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fc61115c5b6577845a9a848ada360377
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs
new file mode 100644
index 0000000000..037c05da77
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs
@@ -0,0 +1,139 @@
+namespace DocCodeSamples.Tests
+{
+ #region interactions
+ using UnityEngine;
+ using UnityEngine.InputSystem;
+ using UnityEngine.InputSystem.Interactions;
+
+ ///
+ /// Example script demonstrating how to react to interactions on an action's callbacks.
+ ///
+ public class InteractionsExampleScript : MonoBehaviour
+ {
+ InputAction jumpAction;
+
+ private void Start()
+ {
+ jumpAction = InputSystem.actions.FindAction("Jump");
+
+
+ jumpAction.started += context =>
+ {
+ if (context.interaction is SlowTapInteraction)
+ {
+ // Show "charging" UI
+ }
+ };
+
+ jumpAction.performed += context =>
+ {
+ if (context.interaction is SlowTapInteraction)
+ {
+ // call "charged jump" code
+ }
+ else
+ {
+ // call "regular jump" code
+ };
+ };
+
+ jumpAction.canceled += context =>
+ {
+ // Hide "charging" UI
+ };
+ }
+ }
+ #endregion
+
+ class ExampleScript2 : MonoBehaviour
+ {
+ public PlayerInput playerInput;
+
+ private void Start()
+ {
+ #region timeout
+ // Returns a value between 0 (inclusive) and 1 (inclusive).
+ var warpActionCompletion = playerInput.actions["warp"].GetTimeoutCompletionPercentage();
+ #endregion
+
+ #region interactionactions
+ var Action = new InputAction(interactions: "tap(duration=0.8)");
+ #endregion
+ }
+
+ private void ConfigureBindingInteractions()
+ {
+ #region interactionbindings
+ var Action = new InputAction();
+ Action.AddBinding("/leftStick").WithInteractions("tap(duration=0.8)");
+ #endregion
+ }
+ }
+
+ #region custominteraction
+ // Interaction which performs when you quickly move an
+ // axis all the way from extreme to the other.
+ ///
+ /// Example custom interaction that performs when an axis moves quickly
+ /// from one extreme to the other.
+ ///
+ public class MyExampleInteraction : IInputInteraction
+ {
+ ///
+ /// Time window, in seconds, within which the axis must move from one extreme to the other.
+ ///
+ public float duration = 0.2f;
+
+ ///
+ /// Processes the current state of the control(s) the interaction is bound to.
+ ///
+ /// Context giving access to the control state and phase transition methods.
+ public void Process(ref InputInteractionContext context)
+ {
+ if (context.timerHasExpired)
+ {
+ context.Canceled();
+ return;
+ }
+
+ switch (context.phase)
+ {
+ case InputActionPhase.Waiting:
+ if (context.ReadValue() == 1)
+ {
+ context.Started();
+ context.SetTimeout(duration);
+ }
+ break;
+
+ case InputActionPhase.Started:
+ if (context.ReadValue() == -1)
+ context.Performed();
+ break;
+ }
+ }
+
+ // Unlike processors, Interactions can be stateful, meaning that you can keep a
+ // local state that changes over time as input is received. The system might
+ // invoke the Reset() method to ask Interactions to reset to the local state
+ // at certain points.
+ ///
+ /// Resets the interaction's local state.
+ ///
+ public void Reset()
+ {
+ }
+
+ void Start()
+ {
+ #region registerinteraction
+ InputSystem.RegisterInteraction();
+ #endregion
+
+ #region useinteraction
+ var Action = new InputAction(interactions: "MyExample(duration=0.5)");
+ #endregion
+ }
+ }
+ #endregion
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs.meta
new file mode 100644
index 0000000000..5d21920f22
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: be88f70640b2c6d4395bcdccf49c1638
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs
new file mode 100644
index 0000000000..48d3a13340
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs
@@ -0,0 +1,296 @@
+// This file mimics the C# class that Unity's Input Action Code Generator
+// would produce for an .inputactions asset with a "gameplay" action map
+// containing "use" and "move" actions. It exists purely so that
+// GenerateCsApiFromActions.cs has a real MyPlayerControls/IGameplayActions
+// pair to compile against for the "Generate C# Class" documentation sample.
+
+using System;
+using System.Collections;
+using System.Collections.Generic;
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.Utilities;
+
+namespace DocCodeSamples.Tests
+{
+ ///
+ /// Example generated wrapper class for an .inputactions asset, as produced by
+ /// Unity's Input Action Code Generator when "Generate C# Class" is enabled.
+ ///
+ public partial class MyPlayerControls : IInputActionCollection2, IDisposable
+ {
+ ///
+ /// The underlying wrapped by this class.
+ ///
+ public InputActionAsset asset { get; }
+
+ ///
+ /// Constructs the action asset and looks up its maps and actions.
+ ///
+ public MyPlayerControls()
+ {
+ asset = InputActionAsset.FromJson(@"{
+ ""name"": ""MyPlayerControls"",
+ ""maps"": [
+ {
+ ""name"": ""gameplay"",
+ ""id"": ""d55be63c-61eb-47ef-92dd-eef1248d601e"",
+ ""actions"": [
+ {
+ ""name"": ""move"",
+ ""type"": ""Value"",
+ ""id"": ""8387a17d-aedd-4411-9931-6a855a8299fb"",
+ ""expectedControlType"": ""Vector2"",
+ ""processors"": """",
+ ""interactions"": """",
+ ""initialStateCheck"": true
+ },
+ {
+ ""name"": ""use"",
+ ""type"": ""Button"",
+ ""id"": ""b5f08480-c03b-4654-8475-9c94e8ccccaf"",
+ ""expectedControlType"": ""Button"",
+ ""processors"": """",
+ ""interactions"": """",
+ ""initialStateCheck"": false
+ }
+ ],
+ ""bindings"": [
+ {
+ ""name"": """",
+ ""id"": ""2c541328-ed00-4524-817c-97599bac7de5"",
+ ""path"": ""/leftStick"",
+ ""interactions"": """",
+ ""processors"": """",
+ ""groups"": """",
+ ""action"": ""move"",
+ ""isComposite"": false,
+ ""isPartOfComposite"": false
+ },
+ {
+ ""name"": """",
+ ""id"": ""41041dd1-570a-487c-856e-d58cfa06509a"",
+ ""path"": ""/buttonNorth"",
+ ""interactions"": """",
+ ""processors"": """",
+ ""groups"": """",
+ ""action"": ""use"",
+ ""isComposite"": false,
+ ""isPartOfComposite"": false
+ }
+ ]
+ }
+ ],
+ ""controlSchemes"": []
+}");
+ // gameplay
+ m_gameplay = asset.FindActionMap("gameplay", throwIfNotFound: true);
+ m_gameplay_move = m_gameplay.FindAction("move", throwIfNotFound: true);
+ m_gameplay_use = m_gameplay.FindAction("use", throwIfNotFound: true);
+ }
+
+ ///
+ /// Destroys the underlying action asset.
+ ///
+ public void Dispose()
+ {
+ UnityEngine.Object.Destroy(asset);
+ }
+
+ ///
+ /// The binding mask applied to the underlying action asset.
+ ///
+ public InputBinding? bindingMask
+ {
+ get => asset.bindingMask;
+ set => asset.bindingMask = value;
+ }
+
+ ///
+ /// The devices the underlying action asset is restricted to, if any.
+ ///
+ public ReadOnlyArray? devices
+ {
+ get => asset.devices;
+ set => asset.devices = value;
+ }
+
+ ///
+ /// The control schemes defined on the underlying action asset.
+ ///
+ public ReadOnlyArray controlSchemes => asset.controlSchemes;
+
+ ///
+ /// Checks whether belongs to this asset.
+ ///
+ /// Action to check.
+ /// True if the action belongs to this asset.
+ public bool Contains(InputAction action)
+ {
+ return asset.Contains(action);
+ }
+
+ ///
+ /// Returns an enumerator over all actions in the asset.
+ ///
+ /// An enumerator over all actions in the asset.
+ public IEnumerator GetEnumerator()
+ {
+ return asset.GetEnumerator();
+ }
+
+ IEnumerator IEnumerable.GetEnumerator()
+ {
+ return GetEnumerator();
+ }
+
+ ///
+ /// Enables all action maps in the asset.
+ ///
+ public void Enable()
+ {
+ asset.Enable();
+ }
+
+ ///
+ /// Disables all action maps in the asset.
+ ///
+ public void Disable()
+ {
+ asset.Disable();
+ }
+
+ ///
+ /// All bindings in the asset.
+ ///
+ public IEnumerable bindings => asset.bindings;
+
+ ///
+ /// Finds an action by name or ID.
+ ///
+ /// Name or ID of the action to find.
+ /// If true, throws instead of returning null when not found.
+ /// The found action, or null if not found and is false.
+ public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
+ {
+ return asset.FindAction(actionNameOrId, throwIfNotFound);
+ }
+
+ ///
+ /// Finds a binding that matches .
+ ///
+ /// Mask to match bindings against.
+ /// The action the found binding belongs to.
+ /// The index of the found binding, or -1 if not found.
+ public int FindBinding(InputBinding bindingMask, out InputAction action)
+ {
+ return asset.FindBinding(bindingMask, out action);
+ }
+
+ // gameplay
+ private readonly InputActionMap m_gameplay;
+ private IGameplayActions m_GameplayActionsCallbackInterface;
+ private readonly InputAction m_gameplay_move;
+ private readonly InputAction m_gameplay_use;
+ ///
+ /// Accessor struct for the actions in the "gameplay" action map.
+ ///
+ public struct GameplayActions
+ {
+ private MyPlayerControls m_Wrapper;
+
+ ///
+ /// Constructs the accessor for the given .
+ ///
+ /// The instance to wrap.
+ public GameplayActions(MyPlayerControls wrapper) { m_Wrapper = wrapper; }
+
+ ///
+ /// The "move" action.
+ ///
+ public InputAction @move => m_Wrapper.m_gameplay_move;
+
+ ///
+ /// The "use" action.
+ ///
+ public InputAction @use => m_Wrapper.m_gameplay_use;
+
+ ///
+ /// Returns the underlying "gameplay" action map.
+ ///
+ /// The underlying action map.
+ public InputActionMap Get() { return m_Wrapper.m_gameplay; }
+
+ ///
+ /// Enables the "gameplay" action map.
+ ///
+ public void Enable() { Get().Enable(); }
+
+ ///
+ /// Disables the "gameplay" action map.
+ ///
+ public void Disable() { Get().Disable(); }
+
+ ///
+ /// Whether the "gameplay" action map is currently enabled.
+ ///
+ public bool enabled => Get().enabled;
+
+ ///
+ /// Implicitly converts to the underlying action map.
+ ///
+ /// Accessor to convert.
+ /// The underlying "gameplay" action map.
+ public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
+
+ ///
+ /// Registers to receive callbacks for the actions
+ /// in the "gameplay" action map, replacing any previously registered instance.
+ ///
+ /// Instance to register, or null to only unregister the current one.
+ public void SetCallbacks(IGameplayActions instance)
+ {
+ if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
+ {
+ @move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
+ @move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
+ @move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
+ @use.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnUse;
+ @use.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnUse;
+ @use.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnUse;
+ }
+ m_Wrapper.m_GameplayActionsCallbackInterface = instance;
+ if (instance != null)
+ {
+ @move.started += instance.OnMove;
+ @move.performed += instance.OnMove;
+ @move.canceled += instance.OnMove;
+ @use.started += instance.OnUse;
+ @use.performed += instance.OnUse;
+ @use.canceled += instance.OnUse;
+ }
+ }
+ }
+ ///
+ /// Accessor for the actions in the "gameplay" action map.
+ ///
+ public GameplayActions @gameplay => new GameplayActions(this);
+
+ ///
+ /// Callback interface for the actions in the "gameplay" action map.
+ ///
+ public interface IGameplayActions
+ {
+ ///
+ /// Called when the "move" action is triggered.
+ ///
+ /// Context for the triggered action.
+ void OnMove(InputAction.CallbackContext context);
+
+ ///
+ /// Called when the "use" action is triggered.
+ ///
+ /// Context for the triggered action.
+ void OnUse(InputAction.CallbackContext context);
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs.meta
new file mode 100644
index 0000000000..86446fb1a2
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/MyPlayerControls.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 756afa66ebe158f4c854d7f6566ca7ef
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs
new file mode 100644
index 0000000000..22141930d7
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs
@@ -0,0 +1,47 @@
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.Layouts;
+using UnityEngine.InputSystem.LowLevel;
+using UnityEngine.InputSystem.Utilities;
+
+#region mydevice
+///
+/// Example state struct for a custom device with a single deadzoned axis control.
+///
+public struct MyDeviceState : IInputStateTypeInfo
+{
+ ///
+ /// The memory format identifier for this state struct.
+ ///
+ public FourCC format => new FourCC('M', 'Y', 'D', 'V');
+
+ // Add an axis deadzone to the Control to ignore values
+ // smaller then 0.2, as our Control does not have a stable
+ // resting position.
+ ///
+ /// The axis control's raw value.
+ ///
+ [InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")]
+ public short axis;
+}
+#endregion
+
+class MyDeviceLayoutJson
+{
+ const string json = @"
+ #region mydevicejson
+ {
+ ""name"" : ""MyDevice"",
+ ""extend"" : ""Gamepad"", // Or some other thing
+ ""controls"" : [
+ {
+ ""name"" : ""axis"",
+ ""layout"" : ""Axis"",
+ ""offset"" : 4,
+ ""format"" : ""FLT"",
+ ""processors"" : ""AxisDeadzone(min=0.2)""
+ }
+ ]
+ }
+ #endregion
+";
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs.meta
new file mode 100644
index 0000000000..ac64dac120
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: db196c9c4aff9b949b705772eea8c0ee
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs
new file mode 100644
index 0000000000..4b4db3b4c1
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs
@@ -0,0 +1,97 @@
+using UnityEditor;
+using UnityEngine.InputSystem.Editor;
+#region boat
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+///
+/// Example script demonstrating reading a Vector2 action value via PlayerInput .
+///
+public class Boat : MonoBehaviour
+{
+ void OnMove(InputValue value)
+ {
+ // The X value will be used to rotate the boat
+ var stick = value.Get();
+ var direction = stick.x;
+ transform.Rotate(Vector3.up, direction);
+ // To move the boat forwards, this code block uses the Y value of the stick
+ var speed = stick.y;
+ transform.Translate(new Vector3(0, 0, speed), Space.Self);
+ }
+}
+#endregion
+
+class ProcessorsExamples : MonoBehaviour
+{
+ void Start()
+ {
+ #region processors
+ // This references the processor registered as "scale" and sets its "factor"
+ // parameter (a floating-point value) to a value of 2.5.
+ _ = "scale(factor=2.5)";
+
+ // Multiple processors can be chained together. They are processed
+ // from left to right.
+ // Example: First invert the value, then normalize [0..10] values to [0..1].
+ _ = "invert,normalize(min=0,max=10)";
+ #endregion
+ }
+}
+
+#region myvalueprocessor
+///
+/// Example custom processor that adds a fixed offset to incoming float values.
+///
+public class MyValueShiftProcessor : InputProcessor
+{
+ ///
+ /// Number to add to incoming values.
+ ///
+ [Tooltip("Number to add to incoming values.")]
+ public float valueShift = 0;
+
+ ///
+ /// Adds to .
+ ///
+ /// Value to process.
+ /// Control from which the value originates.
+ /// The shifted value.
+ public override float Process(float value, InputControl control)
+ {
+ return value + valueShift;
+ }
+}
+#endregion
+
+#region customizeUI
+// No registration is necessary for an InputParameterEditor.
+// The system automatically finds subclasses based on the
+// <..> type parameter.
+#if UNITY_EDITOR
+///
+/// Example custom Editor UI for .
+///
+public class MyValueShiftProcessorEditor : InputParameterEditor
+{
+ private GUIContent m_SliderLabel = new GUIContent("Shift By");
+
+ protected override void OnEnable()
+ {
+ // Put initialization code here. Use 'target' to refer
+ // to the instance of MyValueShiftProcessor that is being
+ // edited.
+ }
+
+ ///
+ /// Draws the custom Editor UI for the processor's parameters.
+ ///
+ public override void OnGUI()
+ {
+ // Define your custom UI here using EditorGUILayout.
+ target.valueShift = EditorGUILayout.Slider(m_SliderLabel,
+ target.valueShift, 0, 10);
+ }
+}
+#endif
+#endregion
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs.meta
new file mode 100644
index 0000000000..2f3f52894d
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 09c783fe8f5d3be489ae11c6662084a7
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs
new file mode 100644
index 0000000000..bfa34019c3
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs
@@ -0,0 +1,38 @@
+namespace DocCodeSamples.Tests
+{
+ #region quick-start-guide
+ using UnityEngine;
+ using UnityEngine.InputSystem; // 1. The Input System "using" statement
+
+ ///
+ /// Example script demonstrating the quick-start workflow for reading actions.
+ ///
+ public class Example : MonoBehaviour
+ {
+ // 2. These variables are to hold the Action references
+ InputAction moveAction;
+ InputAction jumpAction;
+
+ private void Start()
+ {
+ // 3. Find the references to the "Move" and "Jump" actions
+ moveAction = InputSystem.actions.FindAction("Move");
+ jumpAction = InputSystem.actions.FindAction("Jump");
+ }
+
+ void Update()
+ {
+ // 4. Read the "Move" action value, which is a 2D vector
+ // and the "Jump" action state, which is a boolean value
+
+ Vector2 moveValue = moveAction.ReadValue();
+ // your movement code here
+
+ if (jumpAction.IsPressed())
+ {
+ // your jump code here
+ }
+ }
+ }
+ #endregion
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs.meta
new file mode 100644
index 0000000000..c1ec648dc5
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 798d99c1545ef214b917926526fff94b
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs
new file mode 100644
index 0000000000..26c36ff643
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs
@@ -0,0 +1,60 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+using UnityEngine.InputSystem.LowLevel;
+
+class RecordControlStateHistoryExample
+{
+ void Example()
+ {
+ #region history
+ // Create history that records Vector2 control value changes.
+ // NOTE: You can also pass controls directly or use paths that match multiple
+ // controls (For example, "/").
+ // NOTE: The unconstrained InputStateHistory class can record changes on controls
+ // of different value types.
+ var history = new InputStateHistory("/primaryTouch/position");
+
+ // To start recording state changes of the controls to which the history
+ // is attached, call StartRecording.
+ history.StartRecording();
+
+ // To stop recording state changes, call StopRecording.
+ history.StopRecording();
+
+ // Recorded history can be accessed like an array.
+ for (var i = 0; i < history.Count; ++i)
+ {
+ // Each recorded value provides information about which control changed
+ // value (in cases state from multiple controls is recorded concurrently
+ // by the same InputStateHistory) and when it did so.
+
+ var time = history[i].time;
+ var control = history[i].control;
+ var value = history[i].ReadValue();
+ }
+
+ // Recorded history can also be iterated over.
+ foreach (var record in history)
+ Debug.Log(record.ReadValue());
+ Debug.Log(string.Join(",\n", history));
+
+ // You can also record state changes manually, which allows
+ // storing arbitrary histories in InputStateHistory.
+ // NOTE: This records a value change that didn't actually happen on the control.
+ history.RecordStateChange(Touchscreen.current.primaryTouch.position,
+ new Vector2(0.123f, 0.234f));
+
+ // State histories allocate unmanaged memory and need to be disposed.
+ history.Dispose();
+ #endregion
+ }
+
+ void Example100Samples()
+ {
+ #region 100samples
+ var history = new InputStateHistory(Gamepad.current.leftStick);
+ history.historyDepth = 100;
+ history.StartRecording();
+ #endregion
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs.meta
new file mode 100644
index 0000000000..288092f090
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: e441960e4fea0a24f8acc52ee4331ca1
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs
new file mode 100644
index 0000000000..daf2214304
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs
@@ -0,0 +1,31 @@
+using UnityEngine;
+#region using
+using UnityEngine.InputSystem;
+#endregion
+
+namespace DocCodeSamples.Tests
+{
+ internal class UsingActionsWorkflowExamples : MonoBehaviour
+ {
+ #region InputAction_variables
+ InputAction moveAction;
+ InputAction jumpAction;
+ #endregion
+
+ private void Start()
+ {
+ #region FindAction
+ moveAction = InputSystem.actions.FindAction("Move");
+ jumpAction = InputSystem.actions.FindAction("Jump");
+ #endregion
+ }
+
+ private void Update()
+ {
+ #region ReadActionValues
+ Vector2 moveValue = moveAction.ReadValue();
+ bool jumpValue = jumpAction.IsPressed();
+ #endregion
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs.meta
new file mode 100644
index 0000000000..3749f4a3e4
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: fc6256f3ac2a7b5418af84a8ac342786
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs
new file mode 100644
index 0000000000..19d8c48626
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs
@@ -0,0 +1,33 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+///
+/// Example script demonstrating the full actions-based workflow.
+///
+public class Example : MonoBehaviour
+{
+ // These variables are to hold the Action references
+ InputAction moveAction;
+ InputAction jumpAction;
+
+ private void Start()
+ {
+ // Find the references to the "Move" and "Jump" actions
+ moveAction = InputSystem.actions.FindAction("Move");
+ jumpAction = InputSystem.actions.FindAction("Jump");
+ }
+
+ void Update()
+ {
+ // Read the "Move" action value, which is a 2D vector
+ // and the "Jump" action state, which is a boolean value
+
+ Vector2 moveValue = moveAction.ReadValue();
+ // your movement code here
+
+ if (jumpAction.IsPressed())
+ {
+ // your jump code here
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs.meta
new file mode 100644
index 0000000000..67cd6f96df
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: a5ab1e79a15f8644883deb9dc8476d4d
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs
new file mode 100644
index 0000000000..f253f83cfe
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs
@@ -0,0 +1,27 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+///
+/// Example script demonstrating the direct workflow of polling devices in Update .
+///
+public class MyPlayerScript : MonoBehaviour
+{
+ void Update()
+ {
+ var gamepad = Gamepad.current;
+ if (gamepad == null)
+ {
+ return; // No gamepad connected.
+ }
+
+ if (gamepad.rightTrigger.wasPressedThisFrame)
+ {
+ // 'Use' code here
+ }
+
+ Vector2 move = gamepad.leftStick.ReadValue();
+ {
+ // 'Move' code here
+ }
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs.meta
new file mode 100644
index 0000000000..17861f07dc
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 329c13039d01b6445969f48a5f05af4b
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs
new file mode 100644
index 0000000000..b2abff3686
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs
@@ -0,0 +1,41 @@
+using UnityEngine;
+using UnityEngine.InputSystem;
+
+// This script is designed to have the OnMove and
+// OnJump methods called by a PlayerInput component
+
+///
+/// Example script demonstrating the PlayerInput "Invoke Unity Events" workflow.
+///
+public class ExampleScript : MonoBehaviour
+{
+ Vector2 moveAmount;
+
+ ///
+ /// Called by PlayerInput when the "move" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnMove(InputAction.CallbackContext context)
+ {
+ // read the value for the "move" action each event call
+ moveAmount = context.ReadValue();
+ }
+
+ ///
+ /// Called by PlayerInput when the "jump" action is triggered.
+ ///
+ /// Context for the triggered action.
+ public void OnJump(InputAction.CallbackContext context)
+ {
+ // your jump code goes here.
+ }
+
+ ///
+ /// Called once per frame by Unity.
+ ///
+ public void Update()
+ {
+ // to use the Vector2 value from the "move" action each
+ // frame, use the "moveAmount" variable here.
+ }
+}
diff --git a/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs.meta b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs.meta
new file mode 100644
index 0000000000..6c794d04d0
--- /dev/null
+++ b/Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs.meta
@@ -0,0 +1,2 @@
+fileFormatVersion: 2
+guid: 916cd0583fcce1a4585a33c98e74a290
\ No newline at end of file
diff --git a/Packages/com.unity.inputsystem/Documentation~/about-project-wide-actions.md b/Packages/com.unity.inputsystem/Documentation~/about-project-wide-actions.md
index df727a5287..2c101b6e94 100644
--- a/Packages/com.unity.inputsystem/Documentation~/about-project-wide-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/about-project-wide-actions.md
@@ -24,8 +24,6 @@ The benefit of assign an action asset as the project-wide actions is that you ca
For example, you can get a reference to an action named "Move" in your project-wide actions using a line of code like this:
-```
- InputSystem.actions.FindAction("Move");
-```
+ [!code-cs[project-wide actions](Packages/com.unity.inputsystem/DocCodeSamples.Tests/AboutProjectWideActions.cs#about-project-wide-actions)]
Project-wide actions are also enabled by default.
diff --git a/Packages/com.unity.inputsystem/Documentation~/add-processors-bindings-actions.md b/Packages/com.unity.inputsystem/Documentation~/add-processors-bindings-actions.md
index df67b202f6..5f9e5c8d7e 100644
--- a/Packages/com.unity.inputsystem/Documentation~/add-processors-bindings-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/add-processors-bindings-actions.md
@@ -23,11 +23,7 @@ To remove a Processor, click the Remove (-) icon next to it. You can also use th
If you create your bindings in code, you can add Processors like this:
-```CSharp
-var action = new InputAction();
-action.AddBinding("/leftStick")
- .WithProcessor("invertVector2(invertX=false)");
-```
+[!code-cs[processorbindings](Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs#processorbindings)]
## Processors on Actions
@@ -37,6 +33,4 @@ You can add and edit Processors on Actions in the [Input Actions Editor](actions
If you create your Actions in code, you can add Processors like this:
-```CSharp
-var action = new InputAction(processors: "invertVector2(invertX=false)");
-```
+[!code-cs[addprocessor](Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs#addprocessor)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/add-processors-controls.md b/Packages/com.unity.inputsystem/Documentation~/add-processors-controls.md
index a73eb63176..6d332c926c 100644
--- a/Packages/com.unity.inputsystem/Documentation~/add-processors-controls.md
+++ b/Packages/com.unity.inputsystem/Documentation~/add-processors-controls.md
@@ -10,33 +10,8 @@ The Input System adds Processors to a Control during device creation, if they're
If you're using a layout generated by the Input System from a [state struct](step-1-state-struct.md) using [`InputControlAttributes`](xref:UnityEngine.InputSystem.Layouts.InputControlAttribute), you can specify the Processors you want to use with the [`processors`](xref:UnityEngine.InputSystem.Layouts.InputControlAttribute) property of the attribute, like this:
-```CSharp
-public struct MyDeviceState : IInputStateTypeInfo
-{
- public FourCC format => return new FourCC('M', 'Y', 'D', 'V');
-
- // Add an axis deadzone to the Control to ignore values
- // smaller then 0.2, as our Control does not have a stable
- // resting position.
- [InputControl(layout = "Axis", processors = "AxisDeadzone(min=0.2)")]
- public short axis;
-}
-```
+[!code-cs[mydevice](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs#mydevice)]
If you [create a layout from JSON](add-layout-from-json.md), you can specify Processors on your Controls like this:
-```CSharp
-{
- "name" : "MyDevice",
- "extend" : "Gamepad", // Or some other thing
- "controls" : [
- {
- "name" : "axis",
- "layout" : "Axis",
- "offset" : 4,
- "format" : "FLT",
- "processors" : "AxisDeadzone(min=0.2)"
- }
- ]
-}
-```
+[!code-cs[mydevicejson](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorControls.cs#mydevicejson)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md
index 7810dea955..f89d6f24a0 100644
--- a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-actions.md
@@ -23,6 +23,4 @@ To apply interactions in the Input Action Editor:
If you create your Actions in code, you can add Interactions like this:
-```CSharp
-var Action = new InputAction(Interactions: "tap(duration=0.8)");
-```
+[!code-cs[interactionactions](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#interactionactions)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md
index 2ffa2d337f..180a06db5d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md
+++ b/Packages/com.unity.inputsystem/Documentation~/apply-interactions-bindings.md
@@ -25,8 +25,4 @@ To remove an Interaction, select the minus (-) button next to it. To change the
To add Interactions to bindings that you created in code, you can use the following code sample as a template:
-```CSharp
-var Action = new InputAction();
-action.AddBinding("/leftStick")
- .WithInteractions("tap(duration=0.8)");
-```
+[!code-cs[interactionbindings](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#interactionbindings)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/binding-conflicts.md b/Packages/com.unity.inputsystem/Documentation~/binding-conflicts.md
index bc9e96ddd8..1860a26ead 100644
--- a/Packages/com.unity.inputsystem/Documentation~/binding-conflicts.md
+++ b/Packages/com.unity.inputsystem/Documentation~/binding-conflicts.md
@@ -62,34 +62,4 @@ By using the **Pass Through** action type, conflict resolution is bypassed, whic
The following example illustrates how this works at the API level.
-```CSharp
-// Create two actions in the same map.
-var map = new InputActionMap();
-var bAction = map.AddAction("B");
-var shiftbAction = map.AddAction("ShiftB");
-
-// Bind one of the actions to 'B' and the other to 'SHIFT+B'.
-bAction.AddBinding("/b");
-shiftbAction.AddCompositeBinding("OneModifier")
- .With("Modifier", "/shift")
- .With("Binding", "/b");
-
-// Print something to the console when the actions are triggered.
-bAction.performed += _ => Debug.Log("B action performed");
-shiftbAction.performed += _ => Debug.Log("SHIFT+B action performed");
-
-// Start listening to input.
-map.Enable();
-
-// Now, let's assume the left shift key on the keyboard is pressed (here, we manually
-// press it with the InputTestFixture API).
-Press(Keyboard.current.leftShiftKey);
-
-// And then the B is pressed. This is a valid input for both
-// bAction as well as shiftbAction.
-//
-// What will happen now is that shiftbAction will do its processing first. In response,
-// it will *perform* the action (That is, we see the `performed` callback being invoked) and
-// thus "consume" the input. bAction will stay silent as it will in turn be skipped over.
-Press(keyboard.bKey);
-```
+[!code-cs[bindingconflicts](Packages/com.unity.inputsystem/DocCodeSamples.Tests/BindingConflicts.cs#bindingConflicts)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/configure-input-from-json.md b/Packages/com.unity.inputsystem/Documentation~/configure-input-from-json.md
index c1d784d2c4..1f24ba7f39 100644
--- a/Packages/com.unity.inputsystem/Documentation~/configure-input-from-json.md
+++ b/Packages/com.unity.inputsystem/Documentation~/configure-input-from-json.md
@@ -6,10 +6,4 @@ uid: input-system-configure-input-from-json
You can load actions as JSON in the form of a set of action maps or as a full [`InputActionAsset`](xref:UnityEngine.InputSystem.InputActionAsset). This also works at runtime in the Player.
-```CSharp
-// Load a set of action maps from JSON.
-var maps = InputActionMap.FromJson(json);
-
-// Load an entire InputActionAsset from JSON.
-var asset = InputActionAsset.FromJson(json);
-```
+[!code-cs[configurefromjson](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs#configurefromjson)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/configure-unity-events.md b/Packages/com.unity.inputsystem/Documentation~/configure-unity-events.md
index c9d52d84db..17826a3948 100644
--- a/Packages/com.unity.inputsystem/Documentation~/configure-unity-events.md
+++ b/Packages/com.unity.inputsystem/Documentation~/configure-unity-events.md
@@ -28,20 +28,7 @@ The Player Input component automatically handles enabling and disabling Actions,
While we advise against using it, if you **really need or want** to use `InputSystem.actions` for single player use cases, it is advisible to manually disable them and manually enable the default map that **Player Input** sets, during `Start()`, like so:
-```csharp
-public class MyPlayerScript : MonoBehaviour
-{
- PlayerInput playerInput;
-
- void Start()
- {
- playerInput = GetComponent();
- InputSystem.actions.Disable();
- playerInput.currentActionMap?.Enable();
- }
-}
-
-```
+[!code-cs[manualEnableSingleton](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs#manualEnableSingleton)]
When first enabled, the Player Input component enables all Actions from the the [`Default Action Map`](xref:UnityEngine.InputSystem.PlayerInput). If no default Action Map exists, the Player Input component does not enable any Actions. To manually enable Actions, you can call [`Enable`](xref:UnityEngine.InputSystem.InputActionMap) and [`Disable`](xref:UnityEngine.InputSystem.InputActionMap) on the action maps or Actions, like you would do [without `PlayerInput`](actions.md). To check which Action Map is currently enabled, or to switch to a different one, use the [`PlayerInput.currentActionMap`](xref:UnityEngine.InputSystem.PlayerInput) property. To switch actions maps with an action map name, you can also call [`PlayerInput.SwitchCurrentActionMap`](xref:UnityEngine.InputSystem.PlayerInput).
@@ -55,29 +42,7 @@ See the [notification behaviors](select-notification-behavior.md) section below
When the [notification behavior](select-notification-behavior.md) of `PlayerInput` is set to **Send Messages** or **Broadcast Messages**, you can set your app to respond to Actions by defining methods in components like so:
-```CSharp
-public class MyPlayerScript : MonoBehaviour
-{
- // "jump" action becomes "OnJump" method.
-
- // If you're not interested in the value from the control that triggers the action, use a method without arguments.
- public void OnJump()
- {
- // your Jump code here
- }
-
- // If you are interested in the value from the control that triggers an action, you can declare a parameter of type InputValue.
- public void OnMove(InputValue value)
- {
- // Read value from control. The type depends on what type of controls.
- // the action is bound to.
- var v = value.Get();
-
- // IMPORTANT:
- // The given InputValue is only valid for the duration of the callback. Storing the InputValue references somewhere and calling Get() later does not work correctly.
- }
-}
-```
+[!code-cs[sendMessages](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs#sendMessages)]
The component must be on the same `GameObject` if you are using `Send Messages`, or on the same or any child `GameObject` if you are using `Broadcast Messages`.
@@ -85,16 +50,4 @@ The component must be on the same `GameObject` if you are using `Send Messages`,
When the [notification behavior](select-notification-behavior.md) of `PlayerInput` is set to `Invoke Unity Events`, each Action has to be routed to a target method. The methods have the same format as the [`started`, `performed`, and `canceled` callbacks](set-callbacks-on-actions.md#action-callbacks) on [`InputAction`](xref:UnityEngine.InputSystem.InputAction).
-```CSharp
-public class MyPlayerScript : MonoBehaviour
-{
- public void OnFire(InputAction.CallbackContext context)
- {
- }
-
- public void OnMove(InputAction.CallbackContext context)
- {
- var value = context.ReadValue();
- }
-}
-```
+[!code-cs[invokeUnityEvents](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureUnityEvents.cs#invokeUnityEvents)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/control-actuation.md b/Packages/com.unity.inputsystem/Documentation~/control-actuation.md
index 53a08b7e3b..1faf614152 100644
--- a/Packages/com.unity.inputsystem/Documentation~/control-actuation.md
+++ b/Packages/com.unity.inputsystem/Documentation~/control-actuation.md
@@ -16,11 +16,7 @@ However in some scenarios you might want to directly read the actuation of a con
You can query whether a control is currently actuated using [`IsActuated`](xref:UnityEngine.InputSystem.InputControlExtensions).
-```CSharp
-// Check if leftStick is currently actuated.
-if (Gamepad.current.leftStick.IsActuated())
- Debug.Log("Left Stick is actuated");
-```
+[!code-cs[actuation](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs#actuation)]
It can be useful to determine not just whether a control is actuated at all, but also the amount by which it is actuated (that is, its magnitude). For example, for a [`Vector2Control`](xref:UnityEngine.InputSystem.Controls.Vector2Control) this is the length of the vector, whereas for a button it is the raw, absolute floating-point value.
@@ -28,11 +24,7 @@ In general, the current magnitude of a control is always greater than or equal t
You can query the current amount of actuation using [`EvaluateMagnitude`](xref:UnityEngine.InputSystem.InputControl).
-```CSharp
-// Check if left stick is actuated more than a quarter of its motion range.
-if (Gamepad.current.leftStick.EvaluateMagnitude() > 0.25f)
- Debug.Log("Left Stick actuated past 25%");
-```
+[!code-cs[actuation2](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlActuation.cs#actuation2)]
These two mechanisms use control actuation:
diff --git a/Packages/com.unity.inputsystem/Documentation~/control-paths.md b/Packages/com.unity.inputsystem/Documentation~/control-paths.md
index 4bbc1f7ad2..091929516a 100644
--- a/Packages/com.unity.inputsystem/Documentation~/control-paths.md
+++ b/Packages/com.unity.inputsystem/Documentation~/control-paths.md
@@ -57,20 +57,7 @@ The following table explains the use of each field:
Here are examples of control paths:
-```csharp
-// Matches all gamepads (also gamepads *based* on the Gamepad layout):
-""
-// Matches the "Submit" control on all devices:
-"*/"
-// Matches the key that prints the "a" character on the current keyboard layout:
-"/#(a)"
-// Matches the X axis of the left stick on a gamepad.
-"/leftStick/x"
-// Matches the orientation control of the right-hand XR controller:
-"/orientation"
-// Matches all buttons on a gamepad.
-"/"
-```
+[!code-cs[pathExamples](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs#pathExamples)]
### Wildcard characters
@@ -82,22 +69,8 @@ If you enter a control path as text, you can use the wildcard asterisk character
You can access the literal path of a given control with its [`InputControl.path`](xref:UnityEngine.InputSystem.InputControl.path) property. If you need to, you can manually parse a control path into its components using the [`InputControlPath.Parse(path)`](xref:UnityEngine.InputSystem.InputControlPath.Parse(System.String)) API:
-```CSharp
-var parsed = InputControlPath.Parse("{LeftHand}/trigger").ToArray();
-
-Debug.Log(parsed.Length); // Prints 2.
-Debug.Log(parsed[0].layout); // Prints "XRController".
-Debug.Log(parsed[0].name); // Prints an empty string.
-Debug.Log(parsed[0].usages.First()); // Prints "LeftHand".
-Debug.Log(parsed[1].layout); // Prints null.
-Debug.Log(parsed[1].name); // Prints "trigger".
-```
+[!code-cs[parse](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs#parse)]
You can use control paths to directly reference controls, or to let the Input System search for Controls among all devices using [`InputSystem.FindControls`](xref:UnityEngine.InputSystem.InputSystem).
-```CSharp
-var gamepad = Gamepad.all[0];
-var leftStickX = gamepad["leftStick/x"];
-var submitButton = gamepad["{Submit}"];
-var allSubmitButtons = InputSystem.FindControls("*/{Submit}");
-```
+[!code-cs[findcontrols](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ControlPaths.cs#findcontrols)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/create-actions-in-code.md b/Packages/com.unity.inputsystem/Documentation~/create-actions-in-code.md
index 67f1f1b1d8..a6010d1077 100644
--- a/Packages/com.unity.inputsystem/Documentation~/create-actions-in-code.md
+++ b/Packages/com.unity.inputsystem/Documentation~/create-actions-in-code.md
@@ -6,24 +6,6 @@ uid: input-system-create-actions-in-code
You can manually create and configure actions entirely in code, including assigning the bindings. This also works at runtime in the Player. For example:
-```CSharp
-// Create free-standing actions.
-var lookAction = new InputAction("look", binding: "/leftStick");
-var moveAction = new InputAction("move", binding: "/rightStick");
-
- .With("Left", "/a")
- .With("Right", "/d");
-
-// Create an action map with actions.
-var map = new InputActionMap("Gameplay");
-var lookAction = map.AddAction("look");
-lookAction.AddBinding("/leftStick");
-
-// Create an action asset.
-var asset = ScriptableObject.CreateInstance();
-var gameplayMap = new InputActionMap("gameplay");
-asset.AddActionMap(gameplayMap);
-var lookAction = gameplayMap.AddAction("look", "/leftStick");
-```
+[!code-cs[configurefromcode](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs#configurefromcode)]
Any action that you create in this way during Play mode doesn't persist in the input action asset after you exit Play mode. This means you can test your application in a realistic manner in the Editor without having to worry about inadvertently modifying the asset.
diff --git a/Packages/com.unity.inputsystem/Documentation~/declare-standalone-actions.md b/Packages/com.unity.inputsystem/Documentation~/declare-standalone-actions.md
index e2c4fd0c9c..02373e37dc 100644
--- a/Packages/com.unity.inputsystem/Documentation~/declare-standalone-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/declare-standalone-actions.md
@@ -6,16 +6,7 @@ uid: input-system-declare-standalone-actions
You can declare individual [`InputAction`](xref:UnityEngine.InputSystem.InputAction) and [`InputActionMap`](xref:UnityEngine.InputSystem.InputActionMap) objects as fields directly inside `MonoBehaviour` components.
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-public class ExampleScript : MonoBehaviour
-{
- public InputAction move;
- public InputAction jump;
-}
-```
+[!code-cs[declaration](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ConfigureInputfromCode.cs#declaration)]
The result is similar to using an action defined in the Input Actions Editor, except that you define the actions in the GameObject's properties and save them as scene or prefab data, instead of in a dedicated asset.
diff --git a/Packages/com.unity.inputsystem/Documentation~/default-actions.md b/Packages/com.unity.inputsystem/Documentation~/default-actions.md
index c514573edb..12a2430e36 100644
--- a/Packages/com.unity.inputsystem/Documentation~/default-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/default-actions.md
@@ -21,13 +21,4 @@ These default actions mean that in many cases, you can start scripting with the
The Input System package provides an asset called `DefaultInputActions.inputactions` which you can reference directly in your projects like any other Unity asset. The asset is also available in code form through the [`DefaultInputActions`](xref:UnityEngine.InputSystem.DefaultInputActions) class.
-```CSharp
-void Start()
-{
- // Create an instance of the default actions.
- var actions = new DefaultInputActions();
- actions.Player.Look.performed += OnLook;
- actions.Player.Move.performed += OnMove;
- actions.Enable();
-}
-```
+[!code-cs[default-actions](Packages/com.unity.inputsystem/DocCodeSamples.Tests/DefaultActions.cs#default-actions)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/gamepad-haptics.md b/Packages/com.unity.inputsystem/Documentation~/gamepad-haptics.md
index ed13454101..394f727873 100644
--- a/Packages/com.unity.inputsystem/Documentation~/gamepad-haptics.md
+++ b/Packages/com.unity.inputsystem/Documentation~/gamepad-haptics.md
@@ -6,13 +6,7 @@ uid: input-system-gamepad-haptics
The [`Gamepad`](xref:UnityEngine.InputSystem.Gamepad) class implements the [`IDualMotorRumble`](xref:UnityEngine.InputSystem.Haptics.IDualMotorRumble) interface that allows you to control the left and right motor speeds. In most common gamepads, the left motor emits a low-frequency rumble, and the right motor emits a high-frequency rumble.
-```c#
-
-// Rumble the low-frequency (left) motor at 1/4 speed and the high-frequency
-// (right) motor at 3/4 speed.
-Gamepad.current.SetMotorSpeeds(0.25f, 0.75f);
-
-```
+[!code-cs[setMotorSpeeds](Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs#setMotorSpeeds)]
Only the following combinations of devices/OSes currently support rumble:
@@ -43,17 +37,6 @@ In certain situations, you might want to globally pause or stop haptics for all
You can use the corresponding methods on [`InputSystem`](xref:UnityEngine.InputSystem.InputSystem) to achieve this result. These methods work the same way as device-specific methods, but affect all devices:
-```c#
-
-// Pause haptics globally.
-InputSystem.PauseHaptics();
-
-// Resume haptics globally.
-InputSystem.ResumeHaptics();
-
-// Stop haptics globally.
-InputSystem.ResetHaptics();
-
-```
+[!code-cs[globalHaptics](Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadHapticsExample.cs#globalHaptics)]
The difference between `PauseHaptics` and `ResetHaptics` is that the latter resets haptics playback state on each device to its initial state, whereas `PauseHaptics` preserves playback state in memory and only stops playback on the hardware.
diff --git a/Packages/com.unity.inputsystem/Documentation~/gamepad-polling.md b/Packages/com.unity.inputsystem/Documentation~/gamepad-polling.md
index 071dad5776..3b49a28a8d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/gamepad-polling.md
+++ b/Packages/com.unity.inputsystem/Documentation~/gamepad-polling.md
@@ -6,12 +6,7 @@ uid: input-system-polling-gamepad
The platform sets the default polling frequency to provide a good user experience for the devices supported on the platform. This frequency is guaranteed to be at least 60 Hz. You can override the polling frequency suggested by the target platform by explicitly setting [`InputSystem.pollingFrequency`](xref:UnityEngine.InputSystem.InputSystem.pollingFrequency) at runtime.
-```c#
-
-// Poll gamepads at 120 Hz.
-InputSystem.pollingFrequency = 120;
-
-```
+[!code-cs[pollingFrequency](Packages/com.unity.inputsystem/DocCodeSamples.Tests/GamepadPolling.cs#pollingFrequency)]
Increased frequency should lead to an increased number of events on the respective devices. The timestamps provided on the events should follow the spacing dictated by the polling frequency. The asynchronous background polling depends on the operating system's thread scheduling and can vary.
diff --git a/Packages/com.unity.inputsystem/Documentation~/generate-cs-api-from-actions.md b/Packages/com.unity.inputsystem/Documentation~/generate-cs-api-from-actions.md
index 80aed61fc8..19aa85e3c2 100644
--- a/Packages/com.unity.inputsystem/Documentation~/generate-cs-api-from-actions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/generate-cs-api-from-actions.md
@@ -24,51 +24,7 @@ You can optionally choose a path name, class name, and namespace for the generat
Once applied, the Input System creates a C# script containing API that matches the actions defined in the asset which you can access directly in code. The following example demonstrates this, assuming there is an action map named "gameplay" containing two actions, "use" and "move" defined in the action asset:
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-// IGameplayActions is an interface generated from the newly added "gameplay"
-// action map, triggered by the "Generate Interfaces" checkbox. Note that if
-// you change the default values for the action map, the name of the interface
-// will be different.
-
-public class MyPlayerScript : MonoBehaviour, IGameplayActions
-{
- // MyPlayerControls is the C# class that Unity generated.
- // It encapsulates the data from the .inputactions asset we created
- // and automatically looks up all the maps and actions for us.
- MyPlayerControls controls;
-
- public void OnEnable()
- {
- if (controls == null)
- {
- controls = new MyPlayerControls();
- // Tell the "gameplay" action map that we want to be
- // notified when actions get triggered.
- controls.gameplay.SetCallbacks(this);
- }
- controls.gameplay.Enable();
- }
-
- public void OnDisable()
- {
- controls.gameplay.Disable();
- }
-
- public void OnUse(InputAction.CallbackContext context)
- {
- // 'Use' code here.
- }
-
- public void OnMove(InputAction.CallbackContext context)
- {
- // 'Move' code here.
- }
-
-}
-```
+[!code-cs[generate-cs-api](Packages/com.unity.inputsystem/DocCodeSamples.Tests/GenerateCsApiFromActions.cs#generate-cs-api)]
> [!NOTE]
> To regenerate the .cs file, right-click the .inputactions asset in the Project Browser and select **Reimpor**.
diff --git a/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-class.md b/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-class.md
index 4b46c512ce..328b2df52d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-class.md
+++ b/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-class.md
@@ -6,37 +6,7 @@ uid: input-system-custom-class-layout
You can create your own [`InputDevice`](xref:UnityEngine.InputSystem.InputDevice) class and state layouts in C# to create a custom layout as follows:
-```c#
-
- public struct MyDeviceState : IInputStateTypeInfo
- {
- // FourCC type codes are used to identify the memory layouts of state blocks.
- public FourCC format => new FourCC('M', 'D', 'E', 'V');
-
- [InputControl(name = "firstButton", layout = "Button", bit = 0)]
- [InputControl(name = "secondButton", layout = "Button", bit = 1)]
- public int buttons;
- [InputControl(layout = "Analog", parameters="clamp=true,clampMin=0,clampMax=1")]
- public float axis;
- }
-
- [InputState(typeof(MyDeviceState)]
- public class MyDevice : InputDevice
- {
- public ButtonControl firstButton { get; private set; }
- public ButtonControl secondButton { get; private set; }
- public AxisControl axis { get; private set; }
-
- protected override void FinishSetup(InputControlSetup setup)
- {
- firstButton = setup.GetControl(this, "firstButton");
- secondButton = setup.GetControl(this, "secondButton");
- axis = setup.GetControl(this, "axis");
- base.FinishSetup(setup);
- }
- }
-
-```
+[!code-cs[customDeviceClass](Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutClass.cs#customDeviceClass)]
To create an instance of your device, register it as a layout and then instantiate it:
diff --git a/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-existing.md b/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-existing.md
index d2b20c68a8..b31241a48d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-existing.md
+++ b/Packages/com.unity.inputsystem/Documentation~/hid-create-custom-layout-existing.md
@@ -6,43 +6,8 @@ uid: input-system-use-existing-layout
To use one of the existing C# [`InputDevice`](xref:UnityEngine.InputSystem.InputDevice) classes in code to interface with a device, you can build on an existing layout using JSON:
-```json
-
- {
- "name" : "MyDevice",
- "extend" : "Gamepad", // Or some other thing
- "controls" : [
- {
- "name" : "firstButton",
- "layout" : "Button",
- "offset" : 0,
- "bit": 0,
- "format" : "BIT",
- },
- {
- "name" : "secondButton",
- "layout" : "Button",
- "offset" : 0,
- "bit": 1,
- "format" : "BIT",
- },
- {
- "name" : "axis",
- "layout" : "Axis",
- "offset" : 4,
- "format" : "FLT",
- "parameters" : "clamp=true,clampMin=0,clampMax=1"
- }
- ]
- }
-
-```
+[!code-json[myDeviceJson](Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs#myDeviceJson)]
You then register your layout with the system and then instantiate it:
-```c#
-
- InputSystem.RegisterControlLayout(myDeviceJson);
- var device = InputSystem.AddDevice("MyDevice");
-
-```
+[!code-cs[registerAndCreate](Packages/com.unity.inputsystem/DocCodeSamples.Tests/HidCreateCustomLayoutExisting.cs#registerAndCreate)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md
index dc390c260c..4b550003b3 100644
--- a/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/introduction-interactions.md
@@ -32,48 +32,7 @@ While `Performed` is typically the phase that triggers the actual response to an
The following example demonstrates this using a [Slow Tap interaction](./built-in-interactions.md#slowtap) on a `Jump` action so that the user can tap to jump immediately, or hold down the jump button to charge up a higher powered jump, displaying a UI to show the amount charged:
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-using UnityEngine.InputSystem.Interactions;
-
-public class ExampleScript : MonoBehaviour
-{
- InputAction jumpAction;
-
- private void Start()
- {
- jumpAction = InputSystem.actions.FindAction("Jump");
-
-
- jumpAction.started += context =>
- {
- if (context.interaction is SlowTapInteraction)
- {
- // Show "charging" UI
- }
- };
-
- jumpAction.performed += context =>
- {
- if (context.interaction is SlowTapInteraction)
- {
- // call "charged jump" code
- }
- else
- {
- // call "regular jump" code
- };
- };
-
- jumpAction.canceled += context =>
- {
- // Hide "charging" UI
- };
-
- }
-}
-```
+[!code-cs[intro-interactions](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#interactions)]
## Multiple Controls on an Action
@@ -93,10 +52,7 @@ Interactions might need to wait a certain time for a specific input to occur or
It can be useful to know how much of a timeout is left for an interaction to complete. For example, you might want to display a bar in the UI that is charging up while the interaction is waiting to complete. To query the percentage to which a timeout has completed, use [`GetTimeoutCompletionPercentage`](xref:UnityEngine.InputSystem.InputAction).
-```CSharp
-// Returns a value between 0 (inclusive) and 1 (inclusive).
-var warpActionCompletion = playerInput.actions["warp"].GetTimeoutCompletionPercentage();
-```
+[!code-cs[timeout](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#timeout)]
Note that each Interaction can have its own separate timeout (but only a single one at any one time). If [multiple interactions](#multiple-interactions-on-a-binding) are in effect, then [`GetTimeoutCompletionPercentage`](xref:UnityEngine.InputSystem.InputAction) will only use the timeout of the one interaction that is currently driving the action.
diff --git a/Packages/com.unity.inputsystem/Documentation~/introduction-to-processors.md b/Packages/com.unity.inputsystem/Documentation~/introduction-to-processors.md
index 5a5d38a6b5..327edf3364 100644
--- a/Packages/com.unity.inputsystem/Documentation~/introduction-to-processors.md
+++ b/Packages/com.unity.inputsystem/Documentation~/introduction-to-processors.md
@@ -17,16 +17,7 @@ Each Processor is [registered](xref:UnityEngine.InputSystem.InputSystem) using a
Processors can have parameters which can be booleans, integers, or floating-point numbers. When created in data such as [bindings](./bindings.md), processors are described as strings that look like function calls:
-```CSharp
- // This references the processor registered as "scale" and sets its "factor"
- // parameter (a floating-point value) to a value of 2.5.
- "scale(factor=2.5)"
-
- // Multiple processors can be chained together. They are processed
- // from left to right.
- // Example: First invert the value, then normalize [0..10] values to [0..1].
- "invert,normalize(min=0,max=10)"
-```
+[!code-cs[processors](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs#processors)]
## Choose the right ProcessorCollapse comment
@@ -53,24 +44,7 @@ You can achieve this by using an Invert Processor on the Action or the binding.
Finally, attach the following script to a GameObject with a PlayerInput component that references the corresponding Action Asset:
-```csharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-public class Boat : MonoBehaviour
-{
- void OnMove(InputValue value)
- {
- // The X value will be used to rotate the boat
- var stick = value.Get();
- var direction = stick.x;
- transform.Rotate(Vector3.up, direction);
- // To move the boat forwards, this code block uses the Y value of the stick
- var speed = stick.y;
- transform.Translate(new Vector3(0,0,speed),Space.Self);
- }
-}
-```
+[!code-cs[boat](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs#boat)]
### Normalize
diff --git a/Packages/com.unity.inputsystem/Documentation~/quick-start-guide.md b/Packages/com.unity.inputsystem/Documentation~/quick-start-guide.md
index b6fb4e5cbe..f5182e137d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/quick-start-guide.md
+++ b/Packages/com.unity.inputsystem/Documentation~/quick-start-guide.md
@@ -56,38 +56,7 @@ This workflow uses the following steps:
These steps are shown in the example script below:
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem; // 1. The Input System "using" statement
-
-public class Example : MonoBehaviour
-{
- // 2. These variables are to hold the Action references
- InputAction moveAction;
- InputAction jumpAction;
-
- private void Start()
- {
- // 3. Find the references to the "Move" and "Jump" actions
- moveAction = InputSystem.actions.FindAction("Move");
- jumpAction = InputSystem.actions.FindAction("Jump");
- }
-
- void Update()
- {
- // 4. Read the "Move" action value, which is a 2D vector
- // and the "Jump" action state, which is a boolean value
-
- Vector2 moveValue = moveAction.ReadValue();
- // your movement code here
-
- if (jumpAction.IsPressed())
- {
- // your jump code here
- }
- }
-}
-```
+[!code-cs[quick-start-guide](Packages/com.unity.inputsystem/DocCodeSamples.Tests/QuickStartGuide.cs#quick-start-guide)]
These actions named "Move" and "Jump" in this script work straight away with no configuration required because they match the names of some of the pre-configured defaults in the Input System package.
diff --git a/Packages/com.unity.inputsystem/Documentation~/record-control-state-history.md b/Packages/com.unity.inputsystem/Documentation~/record-control-state-history.md
index b87f796b7e..4277b4063d 100644
--- a/Packages/com.unity.inputsystem/Documentation~/record-control-state-history.md
+++ b/Packages/com.unity.inputsystem/Documentation~/record-control-state-history.md
@@ -6,53 +6,8 @@ uid: input-system-control-state-history
If you want to access the history of value changes on a control (for example, in order to compute exit velocity on a touch release), you can record state changes over time with [`InputStateHistory`](xref:UnityEngine.InputSystem.LowLevel.InputStateHistory) or [`InputStateHistory`](xref:UnityEngine.InputSystem.LowLevel.InputStateHistory`1). The latter restricts controls to those of a specific value type, which in turn simplifies some of the API.
-
-```CSharp
-// Create history that records Vector2 control value changes.
-// NOTE: You can also pass controls directly or use paths that match multiple
-// controls (For example, "/").
-// NOTE: The unconstrained InputStateHistory class can record changes on controls
-// of different value types.
-var history = new InputStateHistory("/primaryTouch/position");
-
-// To start recording state changes of the controls to which the history
-// is attached, call StartRecording.
-history.StartRecording();
-
-// To stop recording state changes, call StopRecording.
-history.StopRecording();
-
-// Recorded history can be accessed like an array.
-for (var i = 0; i < history.Count; ++i)
-{
- // Each recorded value provides information about which control changed
- // value (in cases state from multiple controls is recorded concurrently
- // by the same InputStateHistory) and when it did so.
-
- var time = history[i].time;
- var control = history[i].control;
- var value = history[i].ReadValue();
-}
-
-// Recorded history can also be iterated over.
-foreach (var record in history)
- Debug.Log(record.ReadValue());
-Debug.Log(string.Join(",\n", history));
-
-// You can also record state changes manually, which allows
-// storing arbitrary histories in InputStateHistory.
-// NOTE: This records a value change that didn't actually happen on the control.
-history.RecordStateChange(Touchscreen.current.primaryTouch.position,
- new Vector2(0.123f, 0.234f));
-
-// State histories allocate unmanaged memory and need to be disposed.
-history.Dispose();
-```
+[!code-cs[history](Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs#history)]
For example, if you want to have the last 100 samples of the left stick on the gamepad available, you can use this code:
-```CSharp
-var history = new InputStateHistory(Gamepad.current.leftStick);
-history.historyDepth = 100;
-history.StartRecording();
-```
+[!code-cs[100samples](Packages/com.unity.inputsystem/DocCodeSamples.Tests/RecordControlStateHistory.cs#100samples)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/using-actions-workflow.md b/Packages/com.unity.inputsystem/Documentation~/using-actions-workflow.md
index ceeec423c5..18345eeb65 100644
--- a/Packages/com.unity.inputsystem/Documentation~/using-actions-workflow.md
+++ b/Packages/com.unity.inputsystem/Documentation~/using-actions-workflow.md
@@ -45,60 +45,26 @@ To use `FindAction` to get references to your Actions and read user input in you
1. Create a new C# script in Unity.
1. Add the Input System's "using" statement to the top of your script. This allows you to use the Input System API throughout the rest of your script:
- using UnityEngine.InputSystem
+ [!code-cs[using](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs#using)]
1. Create some variables of type `InputAction` in your class body, one for each Action that you want to use in your script. These will store the references to each Action. A good naming convention is to add the word Action to the name of the action. For example:
- InputAction moveAction;
- InputAction jumpAction;
+ [!code-cs[InputAction_variables](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs#InputAction_variables)]
1. In your Start() method, use `FindAction` to find the reference to each action and store it in its respective variable, for example:
- moveAction = InputSystem.actions.FindAction("Move");
- jumpAction = InputSystem.actions.FindAction("Jump");
+ [!code-cs[FindAction](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs#FindAction)]
1. In your Update() method, read the value from your action variables. This allows you to write code that reads the latest values coming from your Actions each frame and respond accordingly. The way you read a value depends on the Action's **value type**. For example some actions might return a 1D or 2D axis value, and other actions might return a Boolean true/false value. In this example, the **Move** action returns a 2D axis, and the **Jump** action returns a Boolean.
- Vector2 moveValue = moveAction.ReadValue();
- bool jumpValue = jumpAction.IsPressed();
+ [!code-cs[ReadActionValues](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowExamples.cs#ReadActionValues)]
The following example script shows all these steps combined together into a single script:
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-public class Example : MonoBehaviour
-{
- // These variables are to hold the Action references
- InputAction moveAction;
- InputAction jumpAction;
-
- private void Start()
- {
- // Find the references to the "Move" and "Jump" actions
- moveAction = InputSystem.actions.FindAction("Move");
- jumpAction = InputSystem.actions.FindAction("Jump");
- }
-
- void Update()
- {
- // Read the "Move" action value, which is a 2D vector
- // and the "Jump" action state, which is a boolean value
-
- Vector2 moveValue = moveAction.ReadValue();
- // your movement code here
-
- if (jumpAction.IsPressed())
- {
- // your jump code here
- }
- }
-}
-```
+[!code-cs[fullexample](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingActionsWorkflowFullExample.cs)]
> [!TIP]
-> Aavoid using `FindAction` in your `Update()` loop, because it performs a string-based lookup which could impact performance. This is why the Action references in the example above are found during the Start() function, and stored in variables after finding them.
+> Avoid using `FindAction` in your `Update()` loop, because it performs a string-based lookup which could impact performance. This is why the Action references in the example above are found during the Start() function, and stored in variables after finding them.
> [!NOTE]
> The [InputSystem.actions](xref:UnityEngine.InputSystem.InputSystem) API refers specifically to the action asset assigned as the [project-wide actions](about-project-wide-actions.md). Most projects only require one action asset, but if you are using more than one action asset, you must create a reference using the type InputActionAsset to the asset you want to access.
diff --git a/Packages/com.unity.inputsystem/Documentation~/using-direct-workflow.md b/Packages/com.unity.inputsystem/Documentation~/using-direct-workflow.md
index 171733e41a..dfb8802fc3 100644
--- a/Packages/com.unity.inputsystem/Documentation~/using-direct-workflow.md
+++ b/Packages/com.unity.inputsystem/Documentation~/using-direct-workflow.md
@@ -11,32 +11,7 @@ It can be useful if you want a quick implementation with one specific type of de
You can directly read the values from connected devices by referring to the device’s [controls](controls.md) and reading the values they are currently generating, using code like this:
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-public class MyPlayerScript : MonoBehaviour
-{
- void Update()
- {
- var gamepad = Gamepad.current;
- if (gamepad == null)
- {
- return; // No gamepad connected.
- }
-
- if (gamepad.rightTrigger.wasPressedThisFrame)
- {
- // 'Use' code here
- }
-
- Vector2 move = gamepad.leftStick.ReadValue();
- {
- // 'Move' code here
- }
- }
-}
-```
+[!code-cs[using-direct-workflow](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingDirectWorkflow.cs)]
The example above reads values directly from the right trigger, and the left stick, of the currently connected [gamepad](devices-gamepads.md). It does not use the input system’s "Action" class, and instead the conceptual actions in your game or app, such as "move" and "use", are implicitly defined by what your code does in response to the input. You can use the same approach for other Device types such as the [keyboard](xref:UnityEngine.InputSystem.Keyboard) or [mouse](xref:UnityEngine.InputSystem.Mouse).
diff --git a/Packages/com.unity.inputsystem/Documentation~/using-playerinput-workflow.md b/Packages/com.unity.inputsystem/Documentation~/using-playerinput-workflow.md
index ddec8aadbc..c2e0eb1220 100644
--- a/Packages/com.unity.inputsystem/Documentation~/using-playerinput-workflow.md
+++ b/Packages/com.unity.inputsystem/Documentation~/using-playerinput-workflow.md
@@ -20,36 +20,7 @@ In the above example image, you can see the PlayerInput component set up to map
This is an example of the script which would provide an implementation of these methods
-```CSharp
-using UnityEngine;
-using UnityEngine.InputSystem;
-
-// This script is designed to have the OnMove and
-// OnJump methods called by a PlayerInput component
-
-public class ExampleScript : MonoBehaviour
-{
- Vector2 moveAmount;
-
- public void OnMove(InputAction.CallbackContext context)
- {
- // read the value for the "move" action each event call
- moveAmount = context.ReadValue();
- }
-
- public void OnJump(InputAction.CallbackContext context)
- {
- // your jump code goes here.
- }
-
- public void Update()
- {
- // to use the Vector2 value from the "move" action each
- // frame, use the "moveAmount" variable here.
- }
-
-}
-```
+[!code-cs[player-input-workflow](Packages/com.unity.inputsystem/DocCodeSamples.Tests/UsingPlayerinputWorkflow.cs)]
> [!NOTE]
> As a general rule, if you are using the PlayerInput workflow, you should read input through callbacks as described above, however if you need to access the input actions asset directly while using the PlayerInput component, you should access the [PlayerInput component's copy of the actions](xref:UnityEngine.InputSystem.PlayerInput), not `InputSystem.actions`.
diff --git a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md
index 4b78874465..e660618584 100644
--- a/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md
+++ b/Packages/com.unity.inputsystem/Documentation~/write-custom-interactions.md
@@ -8,58 +8,14 @@ You can also write a custom Interaction to use in your project. You can use cust
Add a class implementing the [`IInputInteraction`](xref:UnityEngine.InputSystem.IInputInteraction) interface, like this:
-```CSharp
-// Interaction which performs when you quickly move an
-// axis all the way from extreme to the other.
-public class MyExampleInteraction : IInputInteraction
-{
- public float duration = 0.2;
-
- void Process(ref InputInteractionContext context)
- {
- if (context.timerHasExpired)
- {
- context.Canceled();
- return;
- }
-
- switch (context.phase)
- {
- case InputActionPhase.Waiting:
- if (context.control.ReadValue() == 1)
- {
- context.Started();
- context.SetTimeout(duration);
- }
- break;
-
- case InputActionPhase.Started:
- if (context.control.ReadValue() == -1)
- context.Performed();
- break;
- }
- }
-
- // Unlike processors, Interactions can be stateful, meaning that you can keep a
- // local state that changes over time as input is received. The system might
- // invoke the Reset() method to ask Interactions to reset to the local state
- // at certain points.
- void Reset()
- {
- }
-}
-```
+[!code-cs[custominteraction](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#custominteraction)]
Register your interaction with the Input System in your initialization code:
-```CSharp
-InputSystem.RegisterInteraction();
-```
+[!code-cs[registerinteraction](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#registerinteraction)]
Your new Interaction is now available in the [Input Action Asset Editor window](xref:input-system-action-assets).
You can also add it in code using this call:
-```CSharp
-var Action = new InputAction(Interactions: "MyExample(duration=0.5)");
-```
+[!code-cs[useinteraction](Packages/com.unity.inputsystem/DocCodeSamples.Tests/IntroductionInteractions.cs#useinteraction)]
diff --git a/Packages/com.unity.inputsystem/Documentation~/write-custom-processors.md b/Packages/com.unity.inputsystem/Documentation~/write-custom-processors.md
index 418dcf158d..ecdf2f79c3 100644
--- a/Packages/com.unity.inputsystem/Documentation~/write-custom-processors.md
+++ b/Packages/com.unity.inputsystem/Documentation~/write-custom-processors.md
@@ -16,18 +16,7 @@ To create a custom processor:
**1.** Add a class derived from [`InputProcessor`](xref:UnityEngine.InputSystem.InputProcessor`1), and implement the [`Process`](xref:UnityEngine.InputSystem.InputProcessor`1) method:
-```CSharp
-public class MyValueShiftProcessor : InputProcessor
-{
- [Tooltip("Number to add to incoming values.")]
- public float valueShift = 0;
-
- public override float Process(float value, InputControl control)
- {
- return value + valueShift;
- }
-}
-```
+[!code-cs[myvalueprocessor](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs#myvalueprocessor)]
> [!IMPORTANT]
> Processors must be __stateless__, because they are not part of the [input state](control-state.md) that the Input System keeps. For this reason, you can't store local states in a processor if the processor changes based on the input value.
@@ -36,61 +25,14 @@ public class MyValueShiftProcessor : InputProcessor
Register the new processor to the Input System. Call [`InputSystem.RegisterProcessor`](xref:UnityEngine.InputSystem.InputSystem) in your initialization code. You can do this locally within the Processor class:
-```CSharp
-#if UNITY_EDITOR
-[InitializeOnLoad]
-#endif
-public class MyValueShiftProcessor : InputProcessor
-{
- #if UNITY_EDITOR
- static MyValueShiftProcessor()
- {
- Initialize();
- }
- #endif
-
- [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSceneLoad)]
- static void Initialize()
- {
- InputSystem.RegisterProcessor();
- }
-
- //...
-}
-```
+[!code-cs[registernewprocessor](Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs#registernewprocessor)]
Your new Processor is now available in the in the [Input Actions Editor](actions-editor.md) and you can also add it in code like this:
-```CSharp
-var action = new InputAction(processors: "myvalueshift(valueShift=2.3)");
-```
+[!code-cs[inputactionwithprocessor](Packages/com.unity.inputsystem/DocCodeSamples.Tests/CustomProcessors.cs#inputactionwithprocessor)]
## Customize the Editor UI
To customize the UI for editing your Processor, create a custom [`InputParameterEditor`](xref:UnityEngine.InputSystem.Editor.InputParameterEditor`1) class for it:
-```CSharp
-// No registration is necessary for an InputParameterEditor.
-// The system automatically finds subclasses based on the
-// <..> type parameter.
-#if UNITY_EDITOR
-public class MyValueShiftProcessorEditor : InputParameterEditor
-{
- private GUIContent m_SliderLabel = new GUIContent("Shift By");
-
- public override void OnEnable()
- {
- // Put initialization code here. Use 'target' to refer
- // to the instance of MyValueShiftProcessor that is being
- // edited.
- }
-
- public override void OnGUI()
- {
- // Define your custom UI here using EditorGUILayout.
- target.valueShift = EditorGUILayout.Slider(m_SliderLabel,
- target.valueShift, 0, 10);
- }
-}
-#endif
-```
+[!code-cs[customizeUI](Packages/com.unity.inputsystem/DocCodeSamples.Tests/ProcessorsExamples.cs#customizeUI)]