1. 버튼 설정은 했음 - 근데 이걸 이제 플레이어라든가 다른데 연결 시키는거 인풋매니저랑 연결시킨다든가 하는걸 해야 할 것 같음 - 기존에는 공격 버튼은 공격버튼으로 만 사용되어서 인풋매니저에서 관리해서 독점적인 관리가 가능했는데 UIButton으로 뺌으로 인해서 이러한 독점 관리가 아니게 되었으므로 이에 대한 처리가 필요로 하다.
102 lines
2.7 KiB
C#
102 lines
2.7 KiB
C#
using System;
|
|
using UnityEngine;
|
|
using UnityEngine.EventSystems;
|
|
using UnityEngine.InputSystem;
|
|
|
|
public class InputManager: IManager
|
|
{
|
|
// 화면 터치를 어떻게 받아올건지에 대한 액션
|
|
public Action<Define.InputEvent> InputAction = null;
|
|
// 화면의 터치하는 실시간 좌표를 사용하는 기능을 위한 액션
|
|
public Action<Vector2> PointAction = null;
|
|
// 조이스틱의 이동을 담당하는 액션
|
|
public Action<Vector2> MoveAction = null;
|
|
|
|
public Joystick JoyStick { get; set; }
|
|
// public Button_Action Buttons { get; set; }
|
|
|
|
private InputActions _action;
|
|
|
|
bool _pressed = false;
|
|
float _pressedTime = 0.0f;
|
|
public void Init()
|
|
{
|
|
_action = new InputActions();
|
|
_action.UI.Enable();
|
|
}
|
|
|
|
public void OnUpdate()
|
|
{
|
|
JoystickInput();
|
|
AnyInput();
|
|
}
|
|
|
|
void JoystickInput()
|
|
{
|
|
if (JoyStick == null)
|
|
return;
|
|
|
|
Vector2 dir = new Vector2(JoyStick.Horizontal, JoyStick.Vertical);
|
|
MoveAction?.Invoke(dir);
|
|
}
|
|
|
|
|
|
void AnyInput()
|
|
{
|
|
PointAction?.Invoke(_action.UI.Point.ReadValue<Vector2>());
|
|
|
|
if (InputAction != null)
|
|
{
|
|
// UI 위에 마우스(손가락)가 올라가 있는지 체크
|
|
if (EventSystem.current.IsPointerOverGameObject())
|
|
{
|
|
if (_pressed)
|
|
{
|
|
InputAction.Invoke(Time.time - _pressedTime < 0.2f
|
|
? Define.InputEvent.Click
|
|
: Define.InputEvent.Up);
|
|
}
|
|
|
|
_pressed = false;
|
|
_pressedTime = 0.0f;
|
|
return;
|
|
}
|
|
|
|
if (_action.UI.Touch.IsPressed())
|
|
{
|
|
// Touch를 누르고 있는 상태
|
|
if (!_pressed)
|
|
{
|
|
InputAction.Invoke(Define.InputEvent.Down);
|
|
_pressedTime = Time.time;
|
|
}
|
|
|
|
InputAction.Invoke(Define.InputEvent.Press);
|
|
_pressed = true;
|
|
}
|
|
else
|
|
{
|
|
if (_pressed)
|
|
{
|
|
if (Time.time - _pressedTime < 0.2f)
|
|
InputAction.Invoke(Define.InputEvent.Click);
|
|
else
|
|
InputAction.Invoke(Define.InputEvent.Up);
|
|
|
|
_pressed = false;
|
|
_pressedTime = 0.0f;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Clear()
|
|
{
|
|
_action.Dispose();
|
|
InputAction = null;
|
|
PointAction = null;
|
|
|
|
MoveAction = null;
|
|
JoyStick = null;
|
|
}
|
|
} |