Practice_Unity/Assets/Scripts/Managers/InputManager.cs
SEAN-59 ee2026017f 작업
1. 리소스 메니저 생성
2. 풀 매니저 생성
3. 조이스틱 생성 - 조이스틱 이미지 잘 움직이는것도 확인 함

To-Do
1. 조이스틱과 플레이어 캐릭터를 연결하는 로직
2. 몬스터 이동 로직을 고민해서 구현해보기
2025-09-21 23:55:29 +09:00

60 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;
}
}