Move to new input system
This commit is contained in:
parent
27fd68c1c2
commit
4a2f04bc03
5 changed files with 323 additions and 18 deletions
211
Assets/PlayerInputActions.cs
Normal file
211
Assets/PlayerInputActions.cs
Normal file
|
@ -0,0 +1,211 @@
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
// <auto-generated>
|
||||||
|
// This code was auto-generated by com.unity.inputsystem:InputActionCodeGenerator
|
||||||
|
// version 1.5.0
|
||||||
|
// from Assets/PlayerInputActions.inputactions
|
||||||
|
//
|
||||||
|
// Changes to this file may cause incorrect behavior and will be lost if
|
||||||
|
// the code is regenerated.
|
||||||
|
// </auto-generated>
|
||||||
|
//------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine.InputSystem;
|
||||||
|
using UnityEngine.InputSystem.Utilities;
|
||||||
|
|
||||||
|
public partial class @PlayerInputActions: IInputActionCollection2, IDisposable
|
||||||
|
{
|
||||||
|
public InputActionAsset asset { get; }
|
||||||
|
public @PlayerInputActions()
|
||||||
|
{
|
||||||
|
asset = InputActionAsset.FromJson(@"{
|
||||||
|
""name"": ""PlayerInputActions"",
|
||||||
|
""maps"": [
|
||||||
|
{
|
||||||
|
""name"": ""Player"",
|
||||||
|
""id"": ""f8e0b637-f75b-461a-9bb5-2d30dff139f5"",
|
||||||
|
""actions"": [
|
||||||
|
{
|
||||||
|
""name"": ""Move"",
|
||||||
|
""type"": ""Value"",
|
||||||
|
""id"": ""cbd84e00-2ff4-4f1a-aba7-e70ef32df0dd"",
|
||||||
|
""expectedControlType"": ""Vector2"",
|
||||||
|
""processors"": """",
|
||||||
|
""interactions"": """",
|
||||||
|
""initialStateCheck"": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
""bindings"": [
|
||||||
|
{
|
||||||
|
""name"": ""WASD"",
|
||||||
|
""id"": ""88272aa4-9de4-4969-bf34-a8cf0ed36447"",
|
||||||
|
""path"": ""2DVector"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""Move"",
|
||||||
|
""isComposite"": true,
|
||||||
|
""isPartOfComposite"": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""up"",
|
||||||
|
""id"": ""79392300-286e-4514-9d4d-80dcf0228dde"",
|
||||||
|
""path"": ""<Keyboard>/w"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""Move"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""down"",
|
||||||
|
""id"": ""2b3f2378-274e-4c40-a504-6f8a9acecee6"",
|
||||||
|
""path"": ""<Keyboard>/s"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""Move"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""left"",
|
||||||
|
""id"": ""fe756558-4d52-48da-8920-d4d0cda44f93"",
|
||||||
|
""path"": ""<Keyboard>/a"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""Move"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
""name"": ""right"",
|
||||||
|
""id"": ""fdfbd92c-6699-4560-a60e-bd40d65c4130"",
|
||||||
|
""path"": ""<Keyboard>/d"",
|
||||||
|
""interactions"": """",
|
||||||
|
""processors"": """",
|
||||||
|
""groups"": """",
|
||||||
|
""action"": ""Move"",
|
||||||
|
""isComposite"": false,
|
||||||
|
""isPartOfComposite"": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
""controlSchemes"": []
|
||||||
|
}");
|
||||||
|
// Player
|
||||||
|
m_Player = asset.FindActionMap("Player", throwIfNotFound: true);
|
||||||
|
m_Player_Move = m_Player.FindAction("Move", throwIfNotFound: true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Dispose()
|
||||||
|
{
|
||||||
|
UnityEngine.Object.Destroy(asset);
|
||||||
|
}
|
||||||
|
|
||||||
|
public InputBinding? bindingMask
|
||||||
|
{
|
||||||
|
get => asset.bindingMask;
|
||||||
|
set => asset.bindingMask = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyArray<InputDevice>? devices
|
||||||
|
{
|
||||||
|
get => asset.devices;
|
||||||
|
set => asset.devices = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
|
||||||
|
|
||||||
|
public bool Contains(InputAction action)
|
||||||
|
{
|
||||||
|
return asset.Contains(action);
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerator<InputAction> GetEnumerator()
|
||||||
|
{
|
||||||
|
return asset.GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
IEnumerator IEnumerable.GetEnumerator()
|
||||||
|
{
|
||||||
|
return GetEnumerator();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Enable()
|
||||||
|
{
|
||||||
|
asset.Enable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Disable()
|
||||||
|
{
|
||||||
|
asset.Disable();
|
||||||
|
}
|
||||||
|
|
||||||
|
public IEnumerable<InputBinding> bindings => asset.bindings;
|
||||||
|
|
||||||
|
public InputAction FindAction(string actionNameOrId, bool throwIfNotFound = false)
|
||||||
|
{
|
||||||
|
return asset.FindAction(actionNameOrId, throwIfNotFound);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int FindBinding(InputBinding bindingMask, out InputAction action)
|
||||||
|
{
|
||||||
|
return asset.FindBinding(bindingMask, out action);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Player
|
||||||
|
private readonly InputActionMap m_Player;
|
||||||
|
private List<IPlayerActions> m_PlayerActionsCallbackInterfaces = new List<IPlayerActions>();
|
||||||
|
private readonly InputAction m_Player_Move;
|
||||||
|
public struct PlayerActions
|
||||||
|
{
|
||||||
|
private @PlayerInputActions m_Wrapper;
|
||||||
|
public PlayerActions(@PlayerInputActions wrapper) { m_Wrapper = wrapper; }
|
||||||
|
public InputAction @Move => m_Wrapper.m_Player_Move;
|
||||||
|
public InputActionMap Get() { return m_Wrapper.m_Player; }
|
||||||
|
public void Enable() { Get().Enable(); }
|
||||||
|
public void Disable() { Get().Disable(); }
|
||||||
|
public bool enabled => Get().enabled;
|
||||||
|
public static implicit operator InputActionMap(PlayerActions set) { return set.Get(); }
|
||||||
|
public void AddCallbacks(IPlayerActions instance)
|
||||||
|
{
|
||||||
|
if (instance == null || m_Wrapper.m_PlayerActionsCallbackInterfaces.Contains(instance)) return;
|
||||||
|
m_Wrapper.m_PlayerActionsCallbackInterfaces.Add(instance);
|
||||||
|
@Move.started += instance.OnMove;
|
||||||
|
@Move.performed += instance.OnMove;
|
||||||
|
@Move.canceled += instance.OnMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void UnregisterCallbacks(IPlayerActions instance)
|
||||||
|
{
|
||||||
|
@Move.started -= instance.OnMove;
|
||||||
|
@Move.performed -= instance.OnMove;
|
||||||
|
@Move.canceled -= instance.OnMove;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void RemoveCallbacks(IPlayerActions instance)
|
||||||
|
{
|
||||||
|
if (m_Wrapper.m_PlayerActionsCallbackInterfaces.Remove(instance))
|
||||||
|
UnregisterCallbacks(instance);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void SetCallbacks(IPlayerActions instance)
|
||||||
|
{
|
||||||
|
foreach (var item in m_Wrapper.m_PlayerActionsCallbackInterfaces)
|
||||||
|
UnregisterCallbacks(item);
|
||||||
|
m_Wrapper.m_PlayerActionsCallbackInterfaces.Clear();
|
||||||
|
AddCallbacks(instance);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
public PlayerActions @Player => new PlayerActions(this);
|
||||||
|
public interface IPlayerActions
|
||||||
|
{
|
||||||
|
void OnMove(InputAction.CallbackContext context);
|
||||||
|
}
|
||||||
|
}
|
11
Assets/PlayerInputActions.cs.meta
Normal file
11
Assets/PlayerInputActions.cs.meta
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 1e57aba2789be6d4492072a4cd75c6a6
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
78
Assets/PlayerInputActions.inputactions
Normal file
78
Assets/PlayerInputActions.inputactions
Normal file
|
@ -0,0 +1,78 @@
|
||||||
|
{
|
||||||
|
"name": "PlayerInputActions",
|
||||||
|
"maps": [
|
||||||
|
{
|
||||||
|
"name": "Player",
|
||||||
|
"id": "f8e0b637-f75b-461a-9bb5-2d30dff139f5",
|
||||||
|
"actions": [
|
||||||
|
{
|
||||||
|
"name": "Move",
|
||||||
|
"type": "Value",
|
||||||
|
"id": "cbd84e00-2ff4-4f1a-aba7-e70ef32df0dd",
|
||||||
|
"expectedControlType": "Vector2",
|
||||||
|
"processors": "",
|
||||||
|
"interactions": "",
|
||||||
|
"initialStateCheck": true
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"bindings": [
|
||||||
|
{
|
||||||
|
"name": "WASD",
|
||||||
|
"id": "88272aa4-9de4-4969-bf34-a8cf0ed36447",
|
||||||
|
"path": "2DVector",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "Move",
|
||||||
|
"isComposite": true,
|
||||||
|
"isPartOfComposite": false
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "up",
|
||||||
|
"id": "79392300-286e-4514-9d4d-80dcf0228dde",
|
||||||
|
"path": "<Keyboard>/w",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "Move",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "down",
|
||||||
|
"id": "2b3f2378-274e-4c40-a504-6f8a9acecee6",
|
||||||
|
"path": "<Keyboard>/s",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "Move",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "left",
|
||||||
|
"id": "fe756558-4d52-48da-8920-d4d0cda44f93",
|
||||||
|
"path": "<Keyboard>/a",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "Move",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "right",
|
||||||
|
"id": "fdfbd92c-6699-4560-a60e-bd40d65c4130",
|
||||||
|
"path": "<Keyboard>/d",
|
||||||
|
"interactions": "",
|
||||||
|
"processors": "",
|
||||||
|
"groups": "",
|
||||||
|
"action": "Move",
|
||||||
|
"isComposite": false,
|
||||||
|
"isPartOfComposite": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"controlSchemes": []
|
||||||
|
}
|
14
Assets/PlayerInputActions.inputactions.meta
Normal file
14
Assets/PlayerInputActions.inputactions.meta
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 2cc88895124e29e43bcdf35cd0025738
|
||||||
|
ScriptedImporter:
|
||||||
|
internalIDToNameTable: []
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
|
script: {fileID: 11500000, guid: 8404be70184654265930450def6a9037, type: 3}
|
||||||
|
generateWrapperCode: 1
|
||||||
|
wrapperCodePath:
|
||||||
|
wrapperClassName:
|
||||||
|
wrapperCodeNamespace:
|
|
@ -4,26 +4,17 @@ using UnityEngine;
|
||||||
|
|
||||||
public class GameInput : MonoBehaviour
|
public class GameInput : MonoBehaviour
|
||||||
{
|
{
|
||||||
|
|
||||||
|
private PlayerInputActions playerInputActions;
|
||||||
|
|
||||||
|
private void Awake()
|
||||||
|
{
|
||||||
|
playerInputActions = new PlayerInputActions();
|
||||||
|
playerInputActions.Player.Enable();
|
||||||
|
}
|
||||||
public Vector2 GetMovementVectorNormalized()
|
public Vector2 GetMovementVectorNormalized()
|
||||||
{
|
{
|
||||||
Vector2 inputVector = new Vector2(0, 0);
|
Vector2 inputVector = playerInputActions.Player.Move.ReadValue<Vector2>();
|
||||||
|
|
||||||
if (Input.GetKey(KeyCode.W))
|
|
||||||
{
|
|
||||||
inputVector.y = +1;
|
|
||||||
}
|
|
||||||
if (Input.GetKey(KeyCode.S))
|
|
||||||
{
|
|
||||||
inputVector.y = -1;
|
|
||||||
}
|
|
||||||
if (Input.GetKey(KeyCode.A))
|
|
||||||
{
|
|
||||||
inputVector.x = -1;
|
|
||||||
}
|
|
||||||
if (Input.GetKey(KeyCode.D))
|
|
||||||
{
|
|
||||||
inputVector.x = +1;
|
|
||||||
}
|
|
||||||
|
|
||||||
inputVector = inputVector.normalized;
|
inputVector = inputVector.normalized;
|
||||||
|
|
||||||
|
|
Reference in a new issue