1. 조이스틱 동작
1.1. 플레이어 컨트롤러 연동
1.2. 자연스러운 방향 전환 추가
2. 베이스씬 작업
2.1. 게임 씬 추가
2.2. 조이스틱 UI 추가
Todo
1. 카메라를 캐릭터한테 붙이기
2. 다른 UI 작업도 추가하기
3. 몬스터 AI 작업도 할 수 있으면 해보기
97 lines
2.4 KiB
C#
97 lines
2.4 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 VirtualJoystick JoyStick { 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.UI.Disable();
|
|
InputAction = null;
|
|
PointAction = null;
|
|
|
|
MoveAction = null;
|
|
JoyStick = null;
|
|
}
|
|
} |