Keyboardnavigation

main
marcgauch 2023-12-03 21:28:35 +01:00
parent 9e28eac7ea
commit de7c044c06
3 changed files with 662 additions and 0 deletions

View File

@ -28,6 +28,8 @@ public class CameraScript : MonoBehaviour
cameraStartingPosition = transform.position;
cameraStartingRotation = transform.rotation;
// Gamepad (normal)
controls.Gameplay.Move.performed += ctx => moveInput = ctx.ReadValue<Vector2>();
controls.Gameplay.Move.canceled += ctx => moveInput = Vector2.zero;
@ -50,6 +52,29 @@ public class CameraScript : MonoBehaviour
controls.Gameplay.resetCameraPosition.performed += ctx => ResetCameraPosition();
controls.Gameplay.resetCameraRotation.performed += ctx => ResetCameraRotation();
//keyboard (afterthought)
controls.Keyboard.Move.performed += ctx => moveInput = ctx.ReadValue<Vector2>();
controls.Keyboard.Move.canceled += ctx => moveInput = Vector2.zero;
controls.Keyboard.Rotate.performed += ctx => rotateInput = ctx.ReadValue<Vector2>();
controls.Keyboard.Rotate.canceled += ctx => rotateInput = Vector2.zero;
controls.Keyboard.Up.performed += ctx => heightChange = 1f;
controls.Keyboard.Up.canceled += ctx => heightChange = 0f;
controls.Keyboard.Down.performed += ctx => heightChange = -1f;
controls.Keyboard.Down.canceled += ctx => heightChange = 0f;
controls.Keyboard.CameraRotationLeft.performed += ctx => rollChange = 1f;
controls.Keyboard.CameraRotationLeft.canceled += ctx => rollChange = 0f;
controls.Keyboard.CameraRotationRight.performed += ctx => rollChange = -1f;
controls.Keyboard.CameraRotationRight.canceled += ctx => rollChange = 0f;
controls.Keyboard.resetCameraPosition.performed += ctx => ResetCameraPosition();
controls.Keyboard.resetCameraRotation.performed += ctx => ResetCameraRotation();
}
void Update()
@ -81,10 +106,12 @@ public class CameraScript : MonoBehaviour
void OnEnable()
{
controls.Gameplay.Enable();
controls.Keyboard.Enable();
}
void OnDisable()
{
controls.Gameplay.Disable();
controls.Keyboard.Disable();
}
}

View File

@ -190,6 +190,262 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
""isPartOfComposite"": false
}
]
},
{
""name"": ""Keyboard"",
""id"": ""d1d13f5d-cc2c-41b4-bf98-a94c1da66ec4"",
""actions"": [
{
""name"": ""Up"",
""type"": ""Button"",
""id"": ""3bad37c0-698e-48c0-bca0-1887300c7b4e"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Down"",
""type"": ""Button"",
""id"": ""6936409f-598b-4068-b4ea-1a0c0c5a64f0"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""Move"",
""type"": ""Value"",
""id"": ""2cc8ef3d-9d44-4c5e-b0cc-946f0bee10f3"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""Rotate"",
""type"": ""Value"",
""id"": ""04044668-ddd0-4c5a-befd-2919b2ef9a24"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": true
},
{
""name"": ""CameraRotationLeft"",
""type"": ""Button"",
""id"": ""3ecf28ce-f10f-46f6-b042-2257f251c796"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""CameraRotationRight"",
""type"": ""Button"",
""id"": ""fc4e86a0-5335-4e44-8865-381b8bb81494"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""resetCameraRotation"",
""type"": ""Button"",
""id"": ""02a70c2c-d05d-4422-8c2e-537c2f88e31a"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
},
{
""name"": ""resetCameraPosition"",
""type"": ""Button"",
""id"": ""1ce47bd0-af0a-45ad-9611-ae93948fc2ca"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """",
""initialStateCheck"": false
}
],
""bindings"": [
{
""name"": """",
""id"": ""2f152022-0b7f-4b8d-b0a2-e3a9c9995293"",
""path"": ""<Keyboard>/e"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Up"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""f02a1f20-ef67-438a-861d-1922ebb0c543"",
""path"": ""<Keyboard>/q"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Down"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""08ba3909-69fd-435e-b753-2a6a297af997"",
""path"": ""<Keyboard>/u"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""CameraRotationLeft"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""0cedf9a8-862b-44ad-9805-2ef6e94ace79"",
""path"": ""<Keyboard>/o"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""CameraRotationRight"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""7c92afda-eba1-486a-8a24-8dc1154f65b8"",
""path"": ""<Keyboard>/f"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""resetCameraRotation"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": """",
""id"": ""e11754bb-3de5-4201-a5cf-219f479be62b"",
""path"": ""<Keyboard>/r"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""resetCameraPosition"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": ""2D Vector"",
""id"": ""1b1a2df7-7506-49b1-8e24-c504780625f1"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""46f3d938-8b8b-4020-aa70-96309e0b081d"",
""path"": ""<Keyboard>/w"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""15719f55-d175-45a0-9b13-e658aa86beca"",
""path"": ""<Keyboard>/s"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""c0bde04a-d4d2-41be-8c91-55b6ed993c87"",
""path"": ""<Keyboard>/a"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""6d50caf9-5e92-4373-9b2b-bf0ff7f63055"",
""path"": ""<Keyboard>/d"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Move"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""2D Vector"",
""id"": ""80c2fd5d-95e1-4a32-bccb-4d3a41256de6"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""name"": ""up"",
""id"": ""cb33b76d-b4d0-4d95-9ff7-1020a8cad99c"",
""path"": ""<Keyboard>/i"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""61cad153-4798-46a6-9457-b88e48682da5"",
""path"": ""<Keyboard>/k"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""left"",
""id"": ""fd712bc4-3cb7-4014-abaf-496ed5f1981d"",
""path"": ""<Keyboard>/j"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""right"",
""id"": ""8b4756cc-966a-469d-97f3-f564f1d9a727"",
""path"": ""<Keyboard>/l"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""Rotate"",
""isComposite"": false,
""isPartOfComposite"": true
}
]
}
],
""controlSchemes"": []
@ -204,6 +460,16 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
m_Gameplay_CameraRotationRight = m_Gameplay.FindAction("CameraRotationRight", throwIfNotFound: true);
m_Gameplay_resetCameraRotation = m_Gameplay.FindAction("resetCameraRotation", throwIfNotFound: true);
m_Gameplay_resetCameraPosition = m_Gameplay.FindAction("resetCameraPosition", throwIfNotFound: true);
// Keyboard
m_Keyboard = asset.FindActionMap("Keyboard", throwIfNotFound: true);
m_Keyboard_Up = m_Keyboard.FindAction("Up", throwIfNotFound: true);
m_Keyboard_Down = m_Keyboard.FindAction("Down", throwIfNotFound: true);
m_Keyboard_Move = m_Keyboard.FindAction("Move", throwIfNotFound: true);
m_Keyboard_Rotate = m_Keyboard.FindAction("Rotate", throwIfNotFound: true);
m_Keyboard_CameraRotationLeft = m_Keyboard.FindAction("CameraRotationLeft", throwIfNotFound: true);
m_Keyboard_CameraRotationRight = m_Keyboard.FindAction("CameraRotationRight", throwIfNotFound: true);
m_Keyboard_resetCameraRotation = m_Keyboard.FindAction("resetCameraRotation", throwIfNotFound: true);
m_Keyboard_resetCameraPosition = m_Keyboard.FindAction("resetCameraPosition", throwIfNotFound: true);
}
public void Dispose()
@ -363,6 +629,108 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
}
}
public GameplayActions @Gameplay => new GameplayActions(this);
// Keyboard
private readonly InputActionMap m_Keyboard;
private List<IKeyboardActions> m_KeyboardActionsCallbackInterfaces = new List<IKeyboardActions>();
private readonly InputAction m_Keyboard_Up;
private readonly InputAction m_Keyboard_Down;
private readonly InputAction m_Keyboard_Move;
private readonly InputAction m_Keyboard_Rotate;
private readonly InputAction m_Keyboard_CameraRotationLeft;
private readonly InputAction m_Keyboard_CameraRotationRight;
private readonly InputAction m_Keyboard_resetCameraRotation;
private readonly InputAction m_Keyboard_resetCameraPosition;
public struct KeyboardActions
{
private @PlayerControls m_Wrapper;
public KeyboardActions(@PlayerControls wrapper) { m_Wrapper = wrapper; }
public InputAction @Up => m_Wrapper.m_Keyboard_Up;
public InputAction @Down => m_Wrapper.m_Keyboard_Down;
public InputAction @Move => m_Wrapper.m_Keyboard_Move;
public InputAction @Rotate => m_Wrapper.m_Keyboard_Rotate;
public InputAction @CameraRotationLeft => m_Wrapper.m_Keyboard_CameraRotationLeft;
public InputAction @CameraRotationRight => m_Wrapper.m_Keyboard_CameraRotationRight;
public InputAction @resetCameraRotation => m_Wrapper.m_Keyboard_resetCameraRotation;
public InputAction @resetCameraPosition => m_Wrapper.m_Keyboard_resetCameraPosition;
public InputActionMap Get() { return m_Wrapper.m_Keyboard; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(KeyboardActions set) { return set.Get(); }
public void AddCallbacks(IKeyboardActions instance)
{
if (instance == null || m_Wrapper.m_KeyboardActionsCallbackInterfaces.Contains(instance)) return;
m_Wrapper.m_KeyboardActionsCallbackInterfaces.Add(instance);
@Up.started += instance.OnUp;
@Up.performed += instance.OnUp;
@Up.canceled += instance.OnUp;
@Down.started += instance.OnDown;
@Down.performed += instance.OnDown;
@Down.canceled += instance.OnDown;
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Rotate.started += instance.OnRotate;
@Rotate.performed += instance.OnRotate;
@Rotate.canceled += instance.OnRotate;
@CameraRotationLeft.started += instance.OnCameraRotationLeft;
@CameraRotationLeft.performed += instance.OnCameraRotationLeft;
@CameraRotationLeft.canceled += instance.OnCameraRotationLeft;
@CameraRotationRight.started += instance.OnCameraRotationRight;
@CameraRotationRight.performed += instance.OnCameraRotationRight;
@CameraRotationRight.canceled += instance.OnCameraRotationRight;
@resetCameraRotation.started += instance.OnResetCameraRotation;
@resetCameraRotation.performed += instance.OnResetCameraRotation;
@resetCameraRotation.canceled += instance.OnResetCameraRotation;
@resetCameraPosition.started += instance.OnResetCameraPosition;
@resetCameraPosition.performed += instance.OnResetCameraPosition;
@resetCameraPosition.canceled += instance.OnResetCameraPosition;
}
private void UnregisterCallbacks(IKeyboardActions instance)
{
@Up.started -= instance.OnUp;
@Up.performed -= instance.OnUp;
@Up.canceled -= instance.OnUp;
@Down.started -= instance.OnDown;
@Down.performed -= instance.OnDown;
@Down.canceled -= instance.OnDown;
@Move.started -= instance.OnMove;
@Move.performed -= instance.OnMove;
@Move.canceled -= instance.OnMove;
@Rotate.started -= instance.OnRotate;
@Rotate.performed -= instance.OnRotate;
@Rotate.canceled -= instance.OnRotate;
@CameraRotationLeft.started -= instance.OnCameraRotationLeft;
@CameraRotationLeft.performed -= instance.OnCameraRotationLeft;
@CameraRotationLeft.canceled -= instance.OnCameraRotationLeft;
@CameraRotationRight.started -= instance.OnCameraRotationRight;
@CameraRotationRight.performed -= instance.OnCameraRotationRight;
@CameraRotationRight.canceled -= instance.OnCameraRotationRight;
@resetCameraRotation.started -= instance.OnResetCameraRotation;
@resetCameraRotation.performed -= instance.OnResetCameraRotation;
@resetCameraRotation.canceled -= instance.OnResetCameraRotation;
@resetCameraPosition.started -= instance.OnResetCameraPosition;
@resetCameraPosition.performed -= instance.OnResetCameraPosition;
@resetCameraPosition.canceled -= instance.OnResetCameraPosition;
}
public void RemoveCallbacks(IKeyboardActions instance)
{
if (m_Wrapper.m_KeyboardActionsCallbackInterfaces.Remove(instance))
UnregisterCallbacks(instance);
}
public void SetCallbacks(IKeyboardActions instance)
{
foreach (var item in m_Wrapper.m_KeyboardActionsCallbackInterfaces)
UnregisterCallbacks(item);
m_Wrapper.m_KeyboardActionsCallbackInterfaces.Clear();
AddCallbacks(instance);
}
}
public KeyboardActions @Keyboard => new KeyboardActions(this);
public interface IGameplayActions
{
void OnUp(InputAction.CallbackContext context);
@ -374,4 +742,15 @@ public partial class @PlayerControls: IInputActionCollection2, IDisposable
void OnResetCameraRotation(InputAction.CallbackContext context);
void OnResetCameraPosition(InputAction.CallbackContext context);
}
public interface IKeyboardActions
{
void OnUp(InputAction.CallbackContext context);
void OnDown(InputAction.CallbackContext context);
void OnMove(InputAction.CallbackContext context);
void OnRotate(InputAction.CallbackContext context);
void OnCameraRotationLeft(InputAction.CallbackContext context);
void OnCameraRotationRight(InputAction.CallbackContext context);
void OnResetCameraRotation(InputAction.CallbackContext context);
void OnResetCameraPosition(InputAction.CallbackContext context);
}
}

View File

@ -168,6 +168,262 @@
"isPartOfComposite": false
}
]
},
{
"name": "Keyboard",
"id": "d1d13f5d-cc2c-41b4-bf98-a94c1da66ec4",
"actions": [
{
"name": "Up",
"type": "Button",
"id": "3bad37c0-698e-48c0-bca0-1887300c7b4e",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Down",
"type": "Button",
"id": "6936409f-598b-4068-b4ea-1a0c0c5a64f0",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "Move",
"type": "Value",
"id": "2cc8ef3d-9d44-4c5e-b0cc-946f0bee10f3",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "Rotate",
"type": "Value",
"id": "04044668-ddd0-4c5a-befd-2919b2ef9a24",
"expectedControlType": "Vector2",
"processors": "",
"interactions": "",
"initialStateCheck": true
},
{
"name": "CameraRotationLeft",
"type": "Button",
"id": "3ecf28ce-f10f-46f6-b042-2257f251c796",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "CameraRotationRight",
"type": "Button",
"id": "fc4e86a0-5335-4e44-8865-381b8bb81494",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "resetCameraRotation",
"type": "Button",
"id": "02a70c2c-d05d-4422-8c2e-537c2f88e31a",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
},
{
"name": "resetCameraPosition",
"type": "Button",
"id": "1ce47bd0-af0a-45ad-9611-ae93948fc2ca",
"expectedControlType": "Button",
"processors": "",
"interactions": "",
"initialStateCheck": false
}
],
"bindings": [
{
"name": "",
"id": "2f152022-0b7f-4b8d-b0a2-e3a9c9995293",
"path": "<Keyboard>/e",
"interactions": "",
"processors": "",
"groups": "",
"action": "Up",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "f02a1f20-ef67-438a-861d-1922ebb0c543",
"path": "<Keyboard>/q",
"interactions": "",
"processors": "",
"groups": "",
"action": "Down",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "08ba3909-69fd-435e-b753-2a6a297af997",
"path": "<Keyboard>/u",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotationLeft",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "0cedf9a8-862b-44ad-9805-2ef6e94ace79",
"path": "<Keyboard>/o",
"interactions": "",
"processors": "",
"groups": "",
"action": "CameraRotationRight",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "7c92afda-eba1-486a-8a24-8dc1154f65b8",
"path": "<Keyboard>/f",
"interactions": "",
"processors": "",
"groups": "",
"action": "resetCameraRotation",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "",
"id": "e11754bb-3de5-4201-a5cf-219f479be62b",
"path": "<Keyboard>/r",
"interactions": "",
"processors": "",
"groups": "",
"action": "resetCameraPosition",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "2D Vector",
"id": "1b1a2df7-7506-49b1-8e24-c504780625f1",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "46f3d938-8b8b-4020-aa70-96309e0b081d",
"path": "<Keyboard>/w",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "15719f55-d175-45a0-9b13-e658aa86beca",
"path": "<Keyboard>/s",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "c0bde04a-d4d2-41be-8c91-55b6ed993c87",
"path": "<Keyboard>/a",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "6d50caf9-5e92-4373-9b2b-bf0ff7f63055",
"path": "<Keyboard>/d",
"interactions": "",
"processors": "",
"groups": "",
"action": "Move",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "2D Vector",
"id": "80c2fd5d-95e1-4a32-bccb-4d3a41256de6",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": true,
"isPartOfComposite": false
},
{
"name": "up",
"id": "cb33b76d-b4d0-4d95-9ff7-1020a8cad99c",
"path": "<Keyboard>/i",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "61cad153-4798-46a6-9457-b88e48682da5",
"path": "<Keyboard>/k",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "left",
"id": "fd712bc4-3cb7-4014-abaf-496ed5f1981d",
"path": "<Keyboard>/j",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "right",
"id": "8b4756cc-966a-469d-97f3-f564f1d9a727",
"path": "<Keyboard>/l",
"interactions": "",
"processors": "",
"groups": "",
"action": "Rotate",
"isComposite": false,
"isPartOfComposite": true
}
]
}
],
"controlSchemes": []