2024-06-03 18:26:03 +00:00
|
|
|
using System;
|
|
|
|
using BlueWater.Uis;
|
2024-06-16 21:29:06 +00:00
|
|
|
using Sirenix.OdinInspector;
|
2024-06-03 18:26:03 +00:00
|
|
|
using UnityEngine;
|
|
|
|
using UnityEngine.InputSystem;
|
|
|
|
|
|
|
|
namespace BlueWater.Players.Combat
|
|
|
|
{
|
|
|
|
public class CombatInput : MonoBehaviour
|
|
|
|
{
|
|
|
|
// variables
|
|
|
|
#region variables
|
|
|
|
|
|
|
|
// Components
|
2024-06-16 21:29:06 +00:00
|
|
|
[SerializeField]
|
2024-06-03 18:26:03 +00:00
|
|
|
private PlayerInput _playerInput;
|
|
|
|
|
|
|
|
// Events
|
|
|
|
public event Action<Vector2> OnMoveInputReceived;
|
|
|
|
public event Action OnDashInputReceived;
|
|
|
|
public event Action<bool> OnAttackInputReceived;
|
2024-06-16 21:29:06 +00:00
|
|
|
public event Action<string> OnActivateMainSkillInputReceived;
|
2024-06-03 18:26:03 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitializeComponents();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Start()
|
|
|
|
{
|
|
|
|
Initialize();
|
|
|
|
}
|
|
|
|
|
2024-06-03 18:26:03 +00:00
|
|
|
// Initialize methods
|
|
|
|
#region Initialize methods
|
|
|
|
|
2024-06-16 21:29:06 +00:00
|
|
|
[Button("컴포넌트 초기화")]
|
|
|
|
private void InitializeComponents()
|
|
|
|
{
|
|
|
|
_playerInput = GetComponent<PlayerInput>();
|
|
|
|
}
|
|
|
|
|
|
|
|
private void Initialize()
|
2024-06-03 18:26:03 +00:00
|
|
|
{
|
2024-06-04 13:15:14 +00:00
|
|
|
_playerInput.enabled = true;
|
2024-06-03 18:26:03 +00:00
|
|
|
PlayerInputKeyManager.Instance.SetCurrentPlayerInput(_playerInput);
|
|
|
|
PlayerInputKeyManager.Instance.SwitchCurrentActionMap(InputActionMaps.Combat);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
// Player input methods
|
|
|
|
#region Player input methods
|
|
|
|
|
|
|
|
public void OnMove(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
var movementInput = context.ReadValue<Vector2>();
|
|
|
|
OnMoveInputReceived?.Invoke(movementInput);
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnDash(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
|
|
|
OnDashInputReceived?.Invoke();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnAttack(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
|
|
|
var device = context.control.device;
|
|
|
|
bool usedMouse;
|
|
|
|
|
|
|
|
switch (device)
|
|
|
|
{
|
|
|
|
case Keyboard:
|
|
|
|
usedMouse = false;
|
|
|
|
break;
|
|
|
|
case Mouse:
|
|
|
|
usedMouse = true;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
OnAttackInputReceived?.Invoke(usedMouse);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnActivateMainSkill(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
2024-06-16 21:29:06 +00:00
|
|
|
OnActivateMainSkillInputReceived?.Invoke(null);
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnOpenItemInventory(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
2024-06-07 17:31:08 +00:00
|
|
|
CombatUiManager.Instance.CombatItemInventoryUi.Open(CombatUiManager.Instance.PopupUiList);
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnCloseItemInventory(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
|
|
|
if (!CombatUiManager.Instance.CombatItemInventoryUi.gameObject.activeSelf) return;
|
|
|
|
|
|
|
|
CombatUiManager.Instance.CombatItemInventoryUi.Close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnOpenMenu(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
2024-06-07 17:31:08 +00:00
|
|
|
CombatUiManager.Instance.CombatMenuPopupUi.Open(CombatUiManager.Instance.PopupUiList);
|
2024-06-03 18:26:03 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnCancel(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
|
|
|
CombatUiManager.Instance.CloseLastPopup();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnInteractionUi(InputAction.CallbackContext context)
|
|
|
|
{
|
|
|
|
if (context.performed)
|
|
|
|
{
|
|
|
|
if (CombatUiManager.Instance.CombatTutorialUi.CurrentTutorialState == TutorialState.First)
|
|
|
|
{
|
|
|
|
CombatUiManager.Instance.CombatTutorialUi.SecondFirstTutorialUi();
|
|
|
|
}
|
|
|
|
else if (CombatUiManager.Instance.CombatTutorialUi.CurrentTutorialState == TutorialState.Second)
|
|
|
|
{
|
|
|
|
CombatUiManager.Instance.CombatTutorialUi.EndTutorialUi();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|