浏览代码

Simple mouse based camera controls (#146)

* changed input phase check to match best practices

* simple solution

* simple camera mouse movement

- implemented system where right button hold enables mouse to control camera
- added a 'speed' setting to the camera manager to modify rotation speed
- updated .inputactions asset
  - to contain a mouse binding for "RotateCamera" action
  - added "EnableMouseCameraRotation" action
  - added scale vector 2 processors for different rotation devices to
    get a similar speed out of each of them
- updated input reader to handle new bindings + action
- updated CameraManager to handle new method of camera manipulation
- found bug with old rotate camera binding (did not work on my gamepad)
  deleted old binding, remade it.  now works on my setup

* added speed preset to camera system prefab.  some code housekeeping / syntax changes

* renamed for clarity

* Better naming for variables

Co-authored-by: Unknown <amel.negra...
/main
GitHub 4 年前
当前提交
cc670c90
共有 5 个文件被更改,包括 334 次插入282 次删除
  1. 1
      UOP1_Project/Assets/Prefabs/GameplayEssentials/CameraSystem.prefab
  2. 40
      UOP1_Project/Assets/Scripts/CameraManager.cs
  3. 454
      UOP1_Project/Assets/Scripts/Input/GameInput.cs
  4. 32
      UOP1_Project/Assets/Scripts/Input/InputReader.cs
  5. 89
      UOP1_Project/Assets/Settings/Input/GameInput.inputactions

1
UOP1_Project/Assets/Prefabs/GameplayEssentials/CameraSystem.prefab


inputReader: {fileID: 11400000, guid: 945ec0365077176418488737deed54be, type: 2}
mainCamera: {fileID: 8745341642014614481}
freeLookVCam: {fileID: 8745341641394998849}
speed: 2
--- !u!1 &8745341640754005580
GameObject:
m_ObjectHideFlags: 0

40
UOP1_Project/Assets/Scripts/CameraManager.cs


using UnityEngine;
using System;
using UnityEngine;
using Cinemachine;
public class CameraManager : MonoBehaviour

public CinemachineFreeLook freeLookVCam;
private bool _isRMBPressed;
[SerializeField, Range(1f, 5f)]
private float speed;
public void SetupProtagonistVirtualCamera(Transform target)
{

private void OnEnable()
{
inputReader.cameraMoveEvent += OnCameraMove;
inputReader.enableMouseControlCameraEvent += OnEnableMouseControlCamera;
inputReader.disableMouseControlCameraEvent += OnDisableMouseControlCamera;
inputReader.enableMouseControlCameraEvent -= OnEnableMouseControlCamera;
inputReader.disableMouseControlCameraEvent -= OnDisableMouseControlCamera;
private void OnCameraMove(Vector2 cameraMovement)
private void OnEnableMouseControlCamera()
freeLookVCam.m_XAxis.m_InputAxisValue = cameraMovement.x * Time.smoothDeltaTime;
freeLookVCam.m_YAxis.m_InputAxisValue = cameraMovement.y * Time.smoothDeltaTime;
_isRMBPressed = true;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
private void OnDisableMouseControlCamera()
{
_isRMBPressed = false;
Cursor.lockState = CursorLockMode.None;
Cursor.visible = true;
// when mouse control is disabled, the input needs to be cleared
// or the last frame's input will 'stick' until the action is invoked again
freeLookVCam.m_XAxis.m_InputAxisValue = 0;
freeLookVCam.m_YAxis.m_InputAxisValue = 0;
}
private void OnCameraMove(Vector2 cameraMovement, bool isDeviceMouse)
{
if (isDeviceMouse && !_isRMBPressed) return;
freeLookVCam.m_XAxis.m_InputAxisValue = cameraMovement.x * Time.smoothDeltaTime * speed;
freeLookVCam.m_YAxis.m_InputAxisValue = cameraMovement.y * Time.smoothDeltaTime * speed;
}
}

454
UOP1_Project/Assets/Scripts/Input/GameInput.cs


public class @GameInput : IInputActionCollection, IDisposable
{
public InputActionAsset asset { get; }
public @GameInput()
{
asset = InputActionAsset.FromJson(@"{
public InputActionAsset asset { get; }
public @GameInput()
{
asset = InputActionAsset.FromJson(@"{
""name"": ""GameInput"",
""maps"": [
{

""type"": ""Value"",
""id"": ""1c4a88b5-2474-4e49-8f10-f987bde2dee0"",
""expectedControlType"": ""Vector2"",
""processors"": """",
""interactions"": """"
},
{
""name"": ""MouseControlCamera"",
""type"": ""Button"",
""id"": ""3172ea7f-84a3-4236-b03d-2beae11fa2e0"",
""expectedControlType"": ""Button"",
""processors"": """",
""interactions"": """"
}

""isPartOfComposite"": false
},
{
""name"": ""Gamepad Right Stick"",
""id"": ""e79b614b-8728-470d-91bc-53102c8434f5"",
""path"": ""2DVector(mode=2)"",
""name"": """",
""id"": ""2b832572-50ef-4dba-aaeb-964ed1c854bb"",
""path"": ""<Gamepad>/rightStick"",
""interactions"": """",
""processors"": ""ScaleVector2(x=2,y=2)"",
""groups"": ""KeyboardOrGamepad"",
""action"": ""RotateCamera"",
""isComposite"": false,
""isPartOfComposite"": false
},
{
""name"": ""Keyboard TFGH"",
""id"": ""8e17360e-f036-4963-93f6-05d14787dfb5"",
""path"": ""2DVector"",
""processors"": """",
""processors"": ""ScaleVector2(x=2,y=2)"",
""groups"": """",
""action"": ""RotateCamera"",
""isComposite"": true,

""name"": ""up"",
""id"": ""4e483eb2-4460-4dc1-af9f-9bcb31ebe837"",
""path"": ""<Gamepad>/rightStick/up"",
""id"": ""9a4ec3f5-78bf-4f42-b7d7-f1edd7ce12dc"",
""path"": ""<Keyboard>/t"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",

},
{
""name"": ""down"",
""id"": ""edb40e4a-ef86-4338-904b-522590bc3cb0"",
""path"": ""<Gamepad>/rightStick/down"",
""id"": ""5d82874e-55d8-4d54-84f5-c4d59dc3b39c"",
""path"": ""<Keyboard>/g"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",

},
{
""name"": ""left"",
""id"": ""398710b9-e1a8-4e26-8651-8e3ae6eb3b6e"",
""path"": ""<Gamepad>/rightStick/left"",
""id"": ""13a13bd5-f4ec-4f5b-9a8e-ef1165cc9f5f"",
""path"": ""<Keyboard>/f"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",

},
{
""name"": ""right"",
""id"": ""597d020e-c169-4232-a603-7e5e35ce0c55"",
""path"": ""<Gamepad>/rightStick/right"",
""id"": ""78626b57-196b-4f24-9a3f-af2477d3633b"",
""path"": ""<Keyboard>/h"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",

},
{
""name"": ""Keyboard TFGH"",
""id"": ""8e17360e-f036-4963-93f6-05d14787dfb5"",
""path"": ""2DVector"",
""interactions"": """",
""processors"": """",
""groups"": """",
""action"": ""RotateCamera"",
""isComposite"": true,
""isPartOfComposite"": false
},
{
""id"": ""9a4ec3f5-78bf-4f42-b7d7-f1edd7ce12dc"",
""path"": ""<Keyboard>/t"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",
""action"": ""RotateCamera"",
""isComposite"": false,
""isPartOfComposite"": true
},
{
""name"": ""down"",
""id"": ""5d82874e-55d8-4d54-84f5-c4d59dc3b39c"",
""path"": ""<Keyboard>/g"",
""id"": ""4e483eb2-4460-4dc1-af9f-9bcb31ebe837"",
""path"": ""<Gamepad>/rightStick/up"",
""interactions"": """",
""processors"": """",
""groups"": ""KeyboardOrGamepad"",

},
{
""name"": ""left"",
""id"": ""13a13bd5-f4ec-4f5b-9a8e-ef1165cc9f5f"",
""path"": ""<Keyboard>/f"",
""name"": """",
""id"": ""88e5a69d-cf1d-43ce-b5ab-9db67f819255"",
""path"": ""<Mouse>/delta"",
""processors"": """",
""processors"": ""ScaleVector2"",
""isPartOfComposite"": true
""isPartOfComposite"": false
""name"": ""right"",
""id"": ""78626b57-196b-4f24-9a3f-af2477d3633b"",
""path"": ""<Keyboard>/h"",
""name"": """",
""id"": ""55713f13-8452-439f-b87e-76d9f2839d7e"",
""path"": ""<Mouse>/rightButton"",
""action"": ""RotateCamera"",
""action"": ""MouseControlCamera"",
""isPartOfComposite"": true
""isPartOfComposite"": false
}
]
},

}
]
}");
// Gameplay
m_Gameplay = asset.FindActionMap("Gameplay", throwIfNotFound: true);
m_Gameplay_Move = m_Gameplay.FindAction("Move", throwIfNotFound: true);
m_Gameplay_Jump = m_Gameplay.FindAction("Jump", throwIfNotFound: true);
m_Gameplay_Attack = m_Gameplay.FindAction("Attack", throwIfNotFound: true);
m_Gameplay_Interact = m_Gameplay.FindAction("Interact", throwIfNotFound: true);
m_Gameplay_Pause = m_Gameplay.FindAction("Pause", throwIfNotFound: true);
m_Gameplay_ExtraAction = m_Gameplay.FindAction("ExtraAction", throwIfNotFound: true);
m_Gameplay_RotateCamera = m_Gameplay.FindAction("RotateCamera", throwIfNotFound: true);
// Menus
m_Menus = asset.FindActionMap("Menus", throwIfNotFound: true);
}
// Gameplay
m_Gameplay = asset.FindActionMap("Gameplay", throwIfNotFound: true);
m_Gameplay_Move = m_Gameplay.FindAction("Move", throwIfNotFound: true);
m_Gameplay_Jump = m_Gameplay.FindAction("Jump", throwIfNotFound: true);
m_Gameplay_Attack = m_Gameplay.FindAction("Attack", throwIfNotFound: true);
m_Gameplay_Interact = m_Gameplay.FindAction("Interact", throwIfNotFound: true);
m_Gameplay_Pause = m_Gameplay.FindAction("Pause", throwIfNotFound: true);
m_Gameplay_ExtraAction = m_Gameplay.FindAction("ExtraAction", throwIfNotFound: true);
m_Gameplay_RotateCamera = m_Gameplay.FindAction("RotateCamera", throwIfNotFound: true);
m_Gameplay_MouseControlCamera = m_Gameplay.FindAction("MouseControlCamera", throwIfNotFound: true);
// Menus
m_Menus = asset.FindActionMap("Menus", throwIfNotFound: true);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public void Dispose()
{
UnityEngine.Object.Destroy(asset);
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public InputBinding? bindingMask
{
get => asset.bindingMask;
set => asset.bindingMask = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputDevice>? devices
{
get => asset.devices;
set => asset.devices = value;
}
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public ReadOnlyArray<InputControlScheme> controlSchemes => asset.controlSchemes;
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public bool Contains(InputAction action)
{
return asset.Contains(action);
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
public IEnumerator<InputAction> GetEnumerator()
{
return asset.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
public void Enable()
{
asset.Enable();
}
public void Enable()
{
asset.Enable();
}
public void Disable()
{
asset.Disable();
}
public void Disable()
{
asset.Disable();
}
// Gameplay
private readonly InputActionMap m_Gameplay;
private IGameplayActions m_GameplayActionsCallbackInterface;
private readonly InputAction m_Gameplay_Move;
private readonly InputAction m_Gameplay_Jump;
private readonly InputAction m_Gameplay_Attack;
private readonly InputAction m_Gameplay_Interact;
private readonly InputAction m_Gameplay_Pause;
private readonly InputAction m_Gameplay_ExtraAction;
private readonly InputAction m_Gameplay_RotateCamera;
public struct GameplayActions
{
private @GameInput m_Wrapper;
public GameplayActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Gameplay_Move;
public InputAction @Jump => m_Wrapper.m_Gameplay_Jump;
public InputAction @Attack => m_Wrapper.m_Gameplay_Attack;
public InputAction @Interact => m_Wrapper.m_Gameplay_Interact;
public InputAction @Pause => m_Wrapper.m_Gameplay_Pause;
public InputAction @ExtraAction => m_Wrapper.m_Gameplay_ExtraAction;
public InputAction @RotateCamera => m_Wrapper.m_Gameplay_RotateCamera;
public InputActionMap Get() { return m_Wrapper.m_Gameplay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
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;
@Jump.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Attack.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Interact.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Pause.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@ExtraAction.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@RotateCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
}
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
@Attack.started += instance.OnAttack;
@Attack.performed += instance.OnAttack;
@Attack.canceled += instance.OnAttack;
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@Pause.started += instance.OnPause;
@Pause.performed += instance.OnPause;
@Pause.canceled += instance.OnPause;
@ExtraAction.started += instance.OnExtraAction;
@ExtraAction.performed += instance.OnExtraAction;
@ExtraAction.canceled += instance.OnExtraAction;
@RotateCamera.started += instance.OnRotateCamera;
@RotateCamera.performed += instance.OnRotateCamera;
@RotateCamera.canceled += instance.OnRotateCamera;
}
}
}
public GameplayActions @Gameplay => new GameplayActions(this);
// Gameplay
private readonly InputActionMap m_Gameplay;
private IGameplayActions m_GameplayActionsCallbackInterface;
private readonly InputAction m_Gameplay_Move;
private readonly InputAction m_Gameplay_Jump;
private readonly InputAction m_Gameplay_Attack;
private readonly InputAction m_Gameplay_Interact;
private readonly InputAction m_Gameplay_Pause;
private readonly InputAction m_Gameplay_ExtraAction;
private readonly InputAction m_Gameplay_RotateCamera;
private readonly InputAction m_Gameplay_MouseControlCamera;
public struct GameplayActions
{
private @GameInput m_Wrapper;
public GameplayActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputAction @Move => m_Wrapper.m_Gameplay_Move;
public InputAction @Jump => m_Wrapper.m_Gameplay_Jump;
public InputAction @Attack => m_Wrapper.m_Gameplay_Attack;
public InputAction @Interact => m_Wrapper.m_Gameplay_Interact;
public InputAction @Pause => m_Wrapper.m_Gameplay_Pause;
public InputAction @ExtraAction => m_Wrapper.m_Gameplay_ExtraAction;
public InputAction @RotateCamera => m_Wrapper.m_Gameplay_RotateCamera;
public InputAction @MouseControlCamera => m_Wrapper.m_Gameplay_MouseControlCamera;
public InputActionMap Get() { return m_Wrapper.m_Gameplay; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(GameplayActions set) { return set.Get(); }
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;
@Jump.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Jump.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnJump;
@Attack.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Attack.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnAttack;
@Interact.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Interact.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnInteract;
@Pause.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@Pause.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnPause;
@ExtraAction.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@ExtraAction.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnExtraAction;
@RotateCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@RotateCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnRotateCamera;
@MouseControlCamera.started -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.performed -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
@MouseControlCamera.canceled -= m_Wrapper.m_GameplayActionsCallbackInterface.OnMouseControlCamera;
}
m_Wrapper.m_GameplayActionsCallbackInterface = instance;
if (instance != null)
{
@Move.started += instance.OnMove;
@Move.performed += instance.OnMove;
@Move.canceled += instance.OnMove;
@Jump.started += instance.OnJump;
@Jump.performed += instance.OnJump;
@Jump.canceled += instance.OnJump;
@Attack.started += instance.OnAttack;
@Attack.performed += instance.OnAttack;
@Attack.canceled += instance.OnAttack;
@Interact.started += instance.OnInteract;
@Interact.performed += instance.OnInteract;
@Interact.canceled += instance.OnInteract;
@Pause.started += instance.OnPause;
@Pause.performed += instance.OnPause;
@Pause.canceled += instance.OnPause;
@ExtraAction.started += instance.OnExtraAction;
@ExtraAction.performed += instance.OnExtraAction;
@ExtraAction.canceled += instance.OnExtraAction;
@RotateCamera.started += instance.OnRotateCamera;
@RotateCamera.performed += instance.OnRotateCamera;
@RotateCamera.canceled += instance.OnRotateCamera;
@MouseControlCamera.started += instance.OnMouseControlCamera;
@MouseControlCamera.performed += instance.OnMouseControlCamera;
@MouseControlCamera.canceled += instance.OnMouseControlCamera;
}
}
}
public GameplayActions @Gameplay => new GameplayActions(this);
// Menus
private readonly InputActionMap m_Menus;
private IMenusActions m_MenusActionsCallbackInterface;
public struct MenusActions
{
private @GameInput m_Wrapper;
public MenusActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputActionMap Get() { return m_Wrapper.m_Menus; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(MenusActions set) { return set.Get(); }
public void SetCallbacks(IMenusActions instance)
{
if (m_Wrapper.m_MenusActionsCallbackInterface != null)
{
}
m_Wrapper.m_MenusActionsCallbackInterface = instance;
if (instance != null)
{
}
}
}
public MenusActions @Menus => new MenusActions(this);
private int m_KeyboardOrGamepadSchemeIndex = -1;
public InputControlScheme KeyboardOrGamepadScheme
{
get
{
if (m_KeyboardOrGamepadSchemeIndex == -1)
m_KeyboardOrGamepadSchemeIndex = asset.FindControlSchemeIndex("KeyboardOrGamepad");
return asset.controlSchemes[m_KeyboardOrGamepadSchemeIndex];
}
}
public interface IGameplayActions
{
void OnMove(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnAttack(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnPause(InputAction.CallbackContext context);
void OnExtraAction(InputAction.CallbackContext context);
void OnRotateCamera(InputAction.CallbackContext context);
}
public interface IMenusActions
{
}
// Menus
private readonly InputActionMap m_Menus;
private IMenusActions m_MenusActionsCallbackInterface;
public struct MenusActions
{
private @GameInput m_Wrapper;
public MenusActions(@GameInput wrapper) { m_Wrapper = wrapper; }
public InputActionMap Get() { return m_Wrapper.m_Menus; }
public void Enable() { Get().Enable(); }
public void Disable() { Get().Disable(); }
public bool enabled => Get().enabled;
public static implicit operator InputActionMap(MenusActions set) { return set.Get(); }
public void SetCallbacks(IMenusActions instance)
{
if (m_Wrapper.m_MenusActionsCallbackInterface != null)
{
}
m_Wrapper.m_MenusActionsCallbackInterface = instance;
if (instance != null)
{
}
}
}
public MenusActions @Menus => new MenusActions(this);
private int m_KeyboardOrGamepadSchemeIndex = -1;
public InputControlScheme KeyboardOrGamepadScheme
{
get
{
if (m_KeyboardOrGamepadSchemeIndex == -1) m_KeyboardOrGamepadSchemeIndex = asset.FindControlSchemeIndex("KeyboardOrGamepad");
return asset.controlSchemes[m_KeyboardOrGamepadSchemeIndex];
}
}
public interface IGameplayActions
{
void OnMove(InputAction.CallbackContext context);
void OnJump(InputAction.CallbackContext context);
void OnAttack(InputAction.CallbackContext context);
void OnInteract(InputAction.CallbackContext context);
void OnPause(InputAction.CallbackContext context);
void OnExtraAction(InputAction.CallbackContext context);
void OnRotateCamera(InputAction.CallbackContext context);
void OnMouseControlCamera(InputAction.CallbackContext context);
}
public interface IMenusActions
{
}
}

32
UOP1_Project/Assets/Scripts/Input/InputReader.cs


public event UnityAction extraActionEvent;
public event UnityAction pauseEvent;
public event UnityAction<Vector2> moveEvent;
public event UnityAction<Vector2> cameraMoveEvent;
public event UnityAction<Vector2, bool> cameraMoveEvent;
public event UnityAction enableMouseControlCameraEvent;
public event UnityAction disableMouseControlCameraEvent;
GameInput gameInput;

gameInput = new GameInput();
gameInput.Gameplay.SetCallbacks(this);
}
gameInput.Gameplay.Enable();
}

public void OnAttack(InputAction.CallbackContext context)
{
if (attackEvent != null
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
attackEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
extraActionEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
interactEvent.Invoke();
}

&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Canceled)
&& context.phase == InputActionPhase.Canceled)
jumpCanceledEvent.Invoke();
}

public void OnPause(InputAction.CallbackContext context)
{
if (pauseEvent != null
&& context.phase == InputActionPhase.Performed)
&& context.phase == InputActionPhase.Performed)
pauseEvent.Invoke();
}

{
cameraMoveEvent.Invoke(context.ReadValue<Vector2>());
cameraMoveEvent.Invoke(context.ReadValue<Vector2>(), IsDeviceMouse(context));
public void OnMouseControlCamera(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
enableMouseControlCameraEvent?.Invoke();
if (context.phase == InputActionPhase.Canceled)
disableMouseControlCameraEvent?.Invoke();
}
private bool IsDeviceMouse(InputAction.CallbackContext context) => context.control.device.name == "Mouse";
}

89
UOP1_Project/Assets/Settings/Input/GameInput.inputactions


"expectedControlType": "Vector2",
"processors": "",
"interactions": ""
},
{
"name": "MouseControlCamera",
"type": "Button",
"id": "3172ea7f-84a3-4236-b03d-2beae11fa2e0",
"expectedControlType": "Button",
"processors": "",
"interactions": ""
}
],
"bindings": [

"isPartOfComposite": false
},
{
"name": "Gamepad Right Stick",
"id": "e79b614b-8728-470d-91bc-53102c8434f5",
"path": "2DVector(mode=2)",
"name": "",
"id": "2b832572-50ef-4dba-aaeb-964ed1c854bb",
"path": "<Gamepad>/rightStick",
"interactions": "",
"processors": "ScaleVector2(x=2,y=2)",
"groups": "KeyboardOrGamepad",
"action": "RotateCamera",
"isComposite": false,
"isPartOfComposite": false
},
{
"name": "Keyboard TFGH",
"id": "8e17360e-f036-4963-93f6-05d14787dfb5",
"path": "2DVector",
"processors": "",
"processors": "ScaleVector2(x=2,y=2)",
"groups": "",
"action": "RotateCamera",
"isComposite": true,

"name": "up",
"id": "4e483eb2-4460-4dc1-af9f-9bcb31ebe837",
"path": "<Gamepad>/rightStick/up",
"id": "9a4ec3f5-78bf-4f42-b7d7-f1edd7ce12dc",
"path": "<Keyboard>/t",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",

},
{
"name": "down",
"id": "edb40e4a-ef86-4338-904b-522590bc3cb0",
"path": "<Gamepad>/rightStick/down",
"id": "5d82874e-55d8-4d54-84f5-c4d59dc3b39c",
"path": "<Keyboard>/g",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",

},
{
"name": "left",
"id": "398710b9-e1a8-4e26-8651-8e3ae6eb3b6e",
"path": "<Gamepad>/rightStick/left",
"id": "13a13bd5-f4ec-4f5b-9a8e-ef1165cc9f5f",
"path": "<Keyboard>/f",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",

},
{
"name": "right",
"id": "597d020e-c169-4232-a603-7e5e35ce0c55",
"path": "<Gamepad>/rightStick/right",
"id": "78626b57-196b-4f24-9a3f-af2477d3633b",
"path": "<Keyboard>/h",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",

},
{
"name": "Keyboard TFGH",
"id": "8e17360e-f036-4963-93f6-05d14787dfb5",
"path": "2DVector",
"interactions": "",
"processors": "",
"groups": "",
"action": "RotateCamera",
"isComposite": true,
"isPartOfComposite": false
},
{
"id": "9a4ec3f5-78bf-4f42-b7d7-f1edd7ce12dc",
"path": "<Keyboard>/t",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",
"action": "RotateCamera",
"isComposite": false,
"isPartOfComposite": true
},
{
"name": "down",
"id": "5d82874e-55d8-4d54-84f5-c4d59dc3b39c",
"path": "<Keyboard>/g",
"id": "4e483eb2-4460-4dc1-af9f-9bcb31ebe837",
"path": "<Gamepad>/rightStick/up",
"interactions": "",
"processors": "",
"groups": "KeyboardOrGamepad",

},
{
"name": "left",
"id": "13a13bd5-f4ec-4f5b-9a8e-ef1165cc9f5f",
"path": "<Keyboard>/f",
"name": "",
"id": "88e5a69d-cf1d-43ce-b5ab-9db67f819255",
"path": "<Mouse>/delta",
"processors": "",
"processors": "ScaleVector2",
"isPartOfComposite": true
"isPartOfComposite": false
"name": "right",
"id": "78626b57-196b-4f24-9a3f-af2477d3633b",
"path": "<Keyboard>/h",
"name": "",
"id": "55713f13-8452-439f-b87e-76d9f2839d7e",
"path": "<Mouse>/rightButton",
"action": "RotateCamera",
"action": "MouseControlCamera",
"isPartOfComposite": true
"isPartOfComposite": false
}
]
},

正在加载...
取消
保存