61 lines
1.5 KiB
C#
61 lines
1.5 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class InputManager: IManager
|
|
{
|
|
public Action KeyAction = null;
|
|
public Action<Define.MouseEvent> MouseAction = null;
|
|
|
|
bool _pressed = false;
|
|
float _pressedTime = 0.0f;
|
|
|
|
public void OnUpdate()
|
|
{
|
|
// UI 위에 마우스 있으면 리턴
|
|
if(EventSystem.current.IsPointerOverGameObject()) return;
|
|
|
|
KeyboardInput();
|
|
|
|
|
|
if (MouseAction != null)
|
|
{
|
|
if (Mouse.current.leftButton.isPressed)
|
|
{
|
|
if (!_pressed)
|
|
{
|
|
MouseAction.Invoke(Define.MouseEvent.Down);
|
|
_pressedTime = Time.time;
|
|
}
|
|
MouseAction.Invoke(Define.MouseEvent.Press);
|
|
_pressed = true;
|
|
}
|
|
else
|
|
{
|
|
if (_pressed)
|
|
{
|
|
if (Time.time - _pressedTime < 0.2f)
|
|
MouseAction.Invoke(Define.MouseEvent.Click);
|
|
else
|
|
{
|
|
MouseAction.Invoke(Define.MouseEvent.Up);
|
|
}
|
|
}
|
|
_pressed = false;
|
|
_pressedTime = 0.0f;
|
|
}
|
|
}
|
|
}
|
|
|
|
void KeyboardInput()
|
|
{
|
|
if (Keyboard.current.aKey.wasPressedThisFrame && KeyAction != null) KeyAction.Invoke();
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
KeyAction = null;
|
|
MouseAction = null;
|
|
}
|
|
} |