浏览代码

updates

/main
kgc00 4 年前
当前提交
801e2d62
共有 5 个文件被更改,包括 78 次插入77 次删除
  1. 43
      UOP1_Project/Assets/Scripts/Input/InputReader.cs
  2. 10
      UOP1_Project/Assets/Scripts/Menu/MenuInput.cs
  3. 45
      UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs
  4. 46
      UOP1_Project/Assets/Scripts/Input/MenuInputReader.cs
  5. 11
      UOP1_Project/Assets/Scripts/Input/MenuInputReader.cs.meta

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


using UnityEngine.Events;
[CreateAssetMenu(fileName = "InputReader", menuName = "Game/Input Reader")]
public class InputReader : ScriptableObject, GameInput.IGameplayActions, GameInput.IMenusActions
public class InputReader : ScriptableObject, GameInput.IGameplayActions
{
public event UnityAction jumpEvent;
public event UnityAction jumpCanceledEvent;

public event UnityAction enableMouseControlCameraEvent;
public event UnityAction disableMouseControlCameraEvent;
// MenuEvents
public event UnityAction<Vector2> MoveSelectionMenuEvent = delegate { };
public event UnityAction MouseMoveMenuEvent = delegate { };
public event UnityAction ConfirmMenuEvent = delegate { };
public event UnityAction CancelMenuEvent = delegate { };
public event UnityAction CloseMenuEvent = delegate { };
public MenuInputReader Menu { get; private set; }
private void OnEnable()
{

Menu = new MenuInputReader(gameInput);
gameInput.Menus.SetCallbacks(this);
}
EnableGameplayInput();

}
private bool IsDeviceMouse(InputAction.CallbackContext context) => context.control.device.name == "Mouse";
public void OnMoveSelection(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MoveSelectionMenuEvent(context.ReadValue<Vector2>());
}
public void OnConfirm(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
ConfirmMenuEvent();
}
public void OnCancel(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
CancelMenuEvent();
}
public void OnMouseMove(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MouseMoveMenuEvent();
}
public void OnCloseMenu(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
CloseMenuEvent();
}
public void EnableMenuInput()
{

10
UOP1_Project/Assets/Scripts/Menu/MenuInput.cs


public bool IsMouseActive { get; private set; }
private void OnEnable()
{
_inputReader.MouseMoveMenuEvent += HandleMoveCursor;
_inputReader.MoveSelectionMenuEvent += HandleMoveSelection;
_inputReader.Menu.MouseMoveMenuEvent += HandleMoveCursor;
_inputReader.Menu.MoveSelectionMenuEvent += HandleMoveSelection;
_inputReader.MouseMoveMenuEvent -= HandleMoveCursor;
_inputReader.MoveSelectionMenuEvent -= HandleMoveSelection;
_inputReader.Menu.MouseMoveMenuEvent -= HandleMoveCursor;
_inputReader.Menu.MoveSelectionMenuEvent -= HandleMoveSelection;
private void HandleMoveSelection(Vector2 dir)
private void HandleMoveSelection()
{
DisableCursor();

45
UOP1_Project/Assets/Scripts/Menu/SelectableUIElement.cs


using UnityEngine;
using UnityEngine.EventSystems;
namespace Menus
public class SelectableUIElement : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
public class SelectableUIElement : MonoBehaviour, IPointerEnterHandler, IPointerExitHandler
private MenuInput _menuInput;
private void Awake()
private MenuInput _menuInput;
[SerializeField] private InputReader _inputReader;
_menuInput = transform.root.gameObject.GetComponentInChildren<MenuInput>();
}
private void Awake()
{
_menuInput = transform.root.gameObject.GetComponentInChildren<MenuInput>();
}
public void OnPointerEnter(PointerEventData eventData)
{
_menuInput.HandleMouseEnter(gameObject);
}
private void OnEnable()
{
// _inputReader.MoveSelectionMenuEvent += InputReaderOnMoveSelectionMenuEvent;
}
private void OnDisable()
{
// _inputReader.MoveSelectionMenuEvent -= InputReaderOnMoveSelectionMenuEvent;
}
private void InputReaderOnMoveSelectionMenuEvent(Vector2 arg0)
{
_menuInput.HandleMouseExit(gameObject);
}
public void OnPointerEnter(PointerEventData eventData)
{
_menuInput.HandleMouseEnter(gameObject);
}
public void OnPointerExit(PointerEventData eventData)
{
_menuInput.HandleMouseExit(gameObject);
}
public void OnPointerExit(PointerEventData eventData)
{
_menuInput.HandleMouseExit(gameObject);
}
}

46
UOP1_Project/Assets/Scripts/Input/MenuInputReader.cs


using UnityEngine.Events;
using UnityEngine.InputSystem;
public class MenuInputReader: GameInput.IMenusActions
{
public MenuInputReader(GameInput gameInput)
{
gameInput.Menus.SetCallbacks(this);
}
// MenuEvents
public event UnityAction MoveSelectionMenuEvent = delegate { };
public event UnityAction MouseMoveMenuEvent = delegate { };
public event UnityAction ConfirmMenuEvent = delegate { };
public event UnityAction CancelMenuEvent = delegate { };
public event UnityAction CloseMenuEvent = delegate { };
public void OnMoveSelection(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MoveSelectionMenuEvent();
}
public void OnConfirm(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
ConfirmMenuEvent();
}
public void OnCancel(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
CancelMenuEvent();
}
public void OnMouseMove(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
MouseMoveMenuEvent();
}
public void OnCloseMenu(InputAction.CallbackContext context)
{
if (context.phase == InputActionPhase.Performed)
CloseMenuEvent();
}
}

11
UOP1_Project/Assets/Scripts/Input/MenuInputReader.cs.meta


fileFormatVersion: 2
guid: 028af03e2ac34463b1c2b1ba0ee23809
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存