Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 22 additions & 22 deletions Assets/Samples/SimpleDemo/SimpleControls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Utilities;

public class SimpleControls : IInputActionCollection, IDisposable
public class @SimpleControls: IInputActionCollection, IDisposable
{
private InputActionAsset asset;
public SimpleControls()
public @SimpleControls()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""SimpleControls"",
Expand Down Expand Up @@ -207,8 +207,8 @@ public void Disable()
private readonly InputAction m_gameplay_look;
public struct GameplayActions
{
private SimpleControls m_Wrapper;
public GameplayActions(SimpleControls wrapper) { m_Wrapper = wrapper; }
private @SimpleControls m_Wrapper;
public GameplayActions(@SimpleControls wrapper) { m_Wrapper = wrapper; }
public InputAction @fire => m_Wrapper.m_gameplay_fire;
public InputAction @move => m_Wrapper.m_gameplay_move;
public InputAction @look => m_Wrapper.m_gameplay_look;
Expand All @@ -221,28 +221,28 @@ public void SetCallbacks(IGameplayActions instance)
{
if (m_Wrapper.m_GameplayActionsCallbackInterface != null)
{
fire.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
fire.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
fire.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
look.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
look.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
look.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
@fire.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
@fire.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
@fire.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnFire;
@move.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@move.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@move.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMove;
@look.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
@look.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
@look.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnLook;
}
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
if (instance != null)
{
fire.started += instance.OnFire;
fire.performed += instance.OnFire;
fire.canceled += instance.OnFire;
move.started += instance.OnMove;
move.performed += instance.OnMove;
move.canceled += instance.OnMove;
look.started += instance.OnLook;
look.performed += instance.OnLook;
look.canceled += instance.OnLook;
@fire.started += instance.OnFire;
@fire.performed += instance.OnFire;
@fire.canceled += instance.OnFire;
@move.started += instance.OnMove;
@move.performed += instance.OnMove;
@move.canceled += instance.OnMove;
@look.started += instance.OnLook;
@look.performed += instance.OnLook;
@look.canceled += instance.OnLook;
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions Assets/Tests/InputSystem/CoreTests_Editor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1808,13 +1808,16 @@ public void Editor_ActionTree_CompositesAreShownWithNiceNames()
[TestCase("MyControls (2)", "MyNamespace", "", "MyNamespace.MyControls2")]
[TestCase("MyControls (2)", "MyNamespace", "MyClassName", "MyNamespace.MyClassName")]
[TestCase("MyControls", "", "MyClassName", "MyClassName")]
[TestCase("interface", "", "class", "class")] // Make sure we can deal with C# reserved keywords.
public void Editor_CanGenerateCodeWrapperForInputAsset(string assetName, string namespaceName, string className, string typeName)
{
var map1 = new InputActionMap("set1");
map1.AddAction("action1", binding: "/gamepad/leftStick");
map1.AddAction("action2", binding: "/gamepad/rightStick");
var map2 = new InputActionMap("set2");
map2.AddAction("action1", binding: "/gamepad/buttonSouth");
// Add an action that has a C# reserved keyword name.
map2.AddAction("return");
var asset = ScriptableObject.CreateInstance<InputActionAsset>();
asset.AddActionMap(map1);
asset.AddActionMap(map2);
Expand Down
1 change: 1 addition & 0 deletions Packages/com.unity.inputsystem/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ however, it has to be formatted properly to pass verification tests.
#### Actions

- Fixed missing keyboard bindings in `DefaultInputActions.inputactions` for navigation in UI.
- Fixed using C# reserved names in .inputactions assets leading to compile errors in generated C# classes (case 1189861).
- Assigning a new `InputActionAsset` to a `InputSystemUIInputModule` will no longer look up action names globally but rather only look for actions that are located in action maps with the same name.
* Previously, if you e.g. switched from one asset where the `point` action was bound to `UI/Point` to an asset that had no `UI` action map but did have an action called `Point` somewhere else, it would erroneously pick the most likely unrelated `Point` action for use by the UI.
- Fixed missing custom editors for `AxisDeadzoneProcessor` and `StickDeadzoneProcessor` that link `min` and `max` values to input settings.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,13 +82,13 @@ public static string GenerateWrapperCode(InputActionAsset asset, Options options
}

// Begin class.
writer.WriteLine($"public class {options.className} : IInputActionCollection, IDisposable");
writer.WriteLine($"public class @{options.className} : IInputActionCollection, IDisposable");
writer.BeginBlock();

writer.WriteLine($"private InputActionAsset asset;");

// Default constructor.
writer.WriteLine($"public {options.className}()");
writer.WriteLine($"public @{options.className}()");
writer.BeginBlock();
writer.WriteLine($"asset = InputActionAsset.FromJson(@\"{asset.ToJson().Replace("\"", "\"\"")}\");");

Expand Down Expand Up @@ -186,8 +186,8 @@ public static string GenerateWrapperCode(InputActionAsset asset, Options options
writer.BeginBlock();

// Constructor.
writer.WriteLine($"private {options.className} m_Wrapper;");
writer.WriteLine($"public {mapTypeName}({options.className} wrapper) {{ m_Wrapper = wrapper; }}");
writer.WriteLine($"private @{options.className} m_Wrapper;");
writer.WriteLine($"public {mapTypeName}(@{options.className} wrapper) {{ m_Wrapper = wrapper; }}");

// Getter for each action.
foreach (var action in map.actions)
Expand Down Expand Up @@ -223,9 +223,9 @@ public static string GenerateWrapperCode(InputActionAsset asset, Options options
var actionName = CSharpCodeHelpers.MakeIdentifier(action.name);
var actionTypeName = CSharpCodeHelpers.MakeTypeName(action.name);

writer.WriteLine($"{actionName}.started -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
writer.WriteLine($"{actionName}.performed -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
writer.WriteLine($"{actionName}.canceled -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
writer.WriteLine($"@{actionName}.started -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
writer.WriteLine($"@{actionName}.performed -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
writer.WriteLine($"@{actionName}.canceled -= m_Wrapper.m_{mapTypeName}CallbackInterface.On{actionTypeName};");
}
writer.EndBlock();

Expand All @@ -238,9 +238,9 @@ public static string GenerateWrapperCode(InputActionAsset asset, Options options
var actionName = CSharpCodeHelpers.MakeIdentifier(action.name);
var actionTypeName = CSharpCodeHelpers.MakeTypeName(action.name);

writer.WriteLine($"{actionName}.started += instance.On{actionTypeName};");
writer.WriteLine($"{actionName}.performed += instance.On{actionTypeName};");
writer.WriteLine($"{actionName}.canceled += instance.On{actionTypeName};");
writer.WriteLine($"@{actionName}.started += instance.On{actionTypeName};");
writer.WriteLine($"@{actionName}.performed += instance.On{actionTypeName};");
writer.WriteLine($"@{actionName}.canceled += instance.On{actionTypeName};");
}
writer.EndBlock();
writer.EndBlock();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace UnityEngine.InputSystem.Editor
[ScriptedImporter(kVersion, InputActionAsset.Extension)]
internal class InputActionImporter : ScriptedImporter
{
private const int kVersion = 7;
private const int kVersion = 8;

private const string kActionIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputAction.png";
private const string kAssetIcon = "Packages/com.unity.inputsystem/InputSystem/Editor/Icons/InputActionAsset.png";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,11 @@ public static bool IsEmptyOrProperNamespaceName(string name)
return name.Split('.').All(IsProperIdentifier);
}

////TODO: this one should add the @escape automatically so no other code has to worry
public static string MakeIdentifier(string name, string suffix = "")
{
if (string.IsNullOrEmpty(name))
throw new ArgumentNullException("name");
throw new ArgumentNullException(nameof(name));

if (char.IsDigit(name[0]))
name = "_" + name;
Expand Down