diff --git a/ExternalSampleProjects/InputDeviceTester/Library/EditorGridSettings.asset b/ExternalSampleProjects/InputDeviceTester/Library/EditorGridSettings.asset new file mode 100644 index 0000000000..410ec0b132 --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/Library/EditorGridSettings.asset @@ -0,0 +1,31 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 53 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 15011, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: UnityEditor.dll::UnityEditor.GridSettings + m_ActiveModeIndex: 0 + m_GridModes: + - rid: 35489430871212034 + - rid: 35489430871212035 + m_GridSize: {x: 1, y: 1, z: 1} + m_GridMultiplier: 0 + references: + version: 2 + RefIds: + - rid: 35489430871212034 + type: {class: WorldGridMode, ns: UnityEditor, asm: UnityEditor.CoreModule} + data: + - rid: 35489430871212035 + type: {class: CustomGridMode, ns: UnityEditor, asm: UnityEditor.CoreModule} + data: + m_Position: {x: 0, y: 0, z: 0} + m_Rotation: {x: 0, y: 0, z: 0, w: 1} diff --git a/ExternalSampleProjects/InputDeviceTester/Library/EditorSnapSettings.asset b/ExternalSampleProjects/InputDeviceTester/Library/EditorSnapSettings.asset new file mode 100644 index 0000000000..00af9e065f --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/Library/EditorSnapSettings.asset @@ -0,0 +1,22 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 53 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 13954, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: UnityEditor.dll::UnityEditor.EditorSnapSettingsData + m_SnapEnabled: 0 + m_AngleSnapEnabled: 0 + m_ScaleSnapEnabled: 0 + m_SnapSettings: + m_SnapToGrid: 1 + m_Rotation: 15 + m_Scale: 1 + m_IncrementalSnapSize: {x: 0.25, y: 0.25, z: 0.25} diff --git a/ExternalSampleProjects/InputDeviceTester/Library/EditorToolsSettings.asset b/ExternalSampleProjects/InputDeviceTester/Library/EditorToolsSettings.asset new file mode 100644 index 0000000000..8d1dff44fc --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/Library/EditorToolsSettings.asset @@ -0,0 +1,59 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &1 +MonoBehaviour: + m_ObjectHideFlags: 53 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 15008, guid: 0000000000000000e000000000000000, type: 0} + m_Name: + m_EditorClassIdentifier: UnityEditor.dll::UnityEditor.EditorToolsSettingsData + m_DefaultState: + m_StateToolOwnerTypeName: UnityEditor.SceneView, UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_GroupsSettingsList: + - groupType: UnityEngine.CircleCollider2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.HingeJoint2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.BoxCollider2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.PolygonCollider2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.EdgeCollider2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.CapsuleCollider2D, UnityEngine.Physics2DModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.ArticulationBody, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.CharacterJoint, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.CapsuleCollider, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.ConfigurableJoint, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.HingeJoint, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.BoxCollider, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.SphereCollider, UnityEngine.PhysicsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.LightProbeGroup, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.ParticleSystem, UnityEngine.ParticleSystemModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.LightProbeProxyVolume, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.LineRenderer, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + - groupType: UnityEngine.TrailRenderer, UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + collapsed: 0 + m_LastPivotModeTypeString: UnityEditor.CenterPivotMode, UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_LastPivotRotationTypeString: UnityEditor.LocalPivotRotation, UnityEditor.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null + m_CustomStates: [] + m_GroupsSettingsList: [] + m_LastPivotModeTypeString: + m_LastPivotRotationTypeString: diff --git a/ExternalSampleProjects/InputDeviceTester/Library/LastSceneManagerSetup.txt b/ExternalSampleProjects/InputDeviceTester/Library/LastSceneManagerSetup.txt new file mode 100644 index 0000000000..dd18ea7047 --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/Library/LastSceneManagerSetup.txt @@ -0,0 +1 @@ +sceneSetups: [] diff --git a/ExternalSampleProjects/InputDeviceTester/Library/StateCache/SceneView/8c/8cd7c613bf844de3b80696e27a479d5e.json b/ExternalSampleProjects/InputDeviceTester/Library/StateCache/SceneView/8c/8cd7c613bf844de3b80696e27a479d5e.json new file mode 100644 index 0000000000..f39c3e7a0b --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/Library/StateCache/SceneView/8c/8cd7c613bf844de3b80696e27a479d5e.json @@ -0,0 +1 @@ +{"cameraMode":{"drawMode":0,"name":"Shaded","section":"Shading Mode"},"sceneLighting":true,"audioPlay":false,"sceneViewState":{"m_AlwaysRefresh":false,"showFog":true,"showSkybox":true,"showFlares":true,"showImageEffects":true,"showParticleSystems":true,"showVisualEffectGraphs":true,"m_FxEnabled":true},"in2DMode":false,"pivot":{"x":0.0,"y":0.0,"z":0.0},"rotation":{"x":-0.08717229217290878,"y":0.8995905518531799,"z":-0.21045254170894623,"w":-0.37262260913848877},"size":10.0,"orthographic":false} \ No newline at end of file diff --git a/ExternalSampleProjects/InputDeviceTester/Library/expandedItems b/ExternalSampleProjects/InputDeviceTester/Library/expandedItems new file mode 100644 index 0000000000..87a5fd2e2b Binary files /dev/null and b/ExternalSampleProjects/InputDeviceTester/Library/expandedItems differ diff --git a/ExternalSampleProjects/InputDeviceTester/UserSettings/HierarchyWindow.settings b/ExternalSampleProjects/InputDeviceTester/UserSettings/HierarchyWindow.settings new file mode 100644 index 0000000000..151dba2e8c --- /dev/null +++ b/ExternalSampleProjects/InputDeviceTester/UserSettings/HierarchyWindow.settings @@ -0,0 +1,57 @@ +{ + "ValidContent": 8, + "ViewModelState": [], + "SearchText": "", + "Columns": [ + { + "ColumnId": "Visibility", + "Visible": true, + "Width": 20.0, + "Index": 0 + }, + { + "ColumnId": "Picking", + "Visible": true, + "Width": 20.0, + "Index": 1 + }, + { + "ColumnId": "HierarchyViewColumn Name", + "Visible": true, + "Width": 231.60000610351563, + "Index": 2 + }, + { + "ColumnId": "GameObject/Active", + "Visible": false, + "Width": 50.0, + "Index": 3 + }, + { + "ColumnId": "HierarchyViewColumn Navigate", + "Visible": true, + "Width": 18.0, + "Index": 3 + }, + { + "ColumnId": "GameObject/Static", + "Visible": false, + "Width": 75.0, + "Index": 5 + }, + { + "ColumnId": "GameObject/Layer", + "Visible": false, + "Width": 150.0, + "Index": 6 + }, + { + "ColumnId": "GameObject/Tag", + "Visible": false, + "Width": 100.0, + "Index": 7 + } + ], + "ScrollPositionX": -1.0, + "ScrollPositionY": -1.0 +} \ No newline at end of file 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. + _ = "/