Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using _InputTest.Scripts;
using _InputTest.Scripts;
using _InputTest.Scripts.Monobehaviours.Commands;
using UnityEngine;
using UnityEngine.InputSystem;
Expand All @@ -13,17 +12,16 @@ public class CharacterInput : MonoBehaviour, IInteractInput, IMoveInput, IRotati
public Command analogRotationInput;
public Command mouseRotationInput;
public Command skillInput;


private PlayerInputActions _inputActions;




public Vector3 MoveDirection { get; private set; }
public Vector3 RotationDirection { get; set; }
public bool IsUsingSkill { get; private set; }
public bool IsPressingInteract { get; private set; }

private void Awake()
{
_inputActions = new PlayerInputActions();
Expand All @@ -32,23 +30,23 @@ private void Awake()
private void OnEnable()
{
_inputActions.Enable();

if (movementInput)
_inputActions.Player.Movement.performed += OnMoveInput;

_inputActions.Player.Interact.performed += OnInteractButton;

if (analogRotationInput)
_inputActions.Player.AnalogAim.performed += OnAnalogAimInput;

if (mouseRotationInput)
_inputActions.Player.MouseAim.performed += OnMouseAimInput;

if (skillInput)
_inputActions.Player.Skill.performed += OnSkillButton;
}


private void OnMoveInput(InputAction.CallbackContext context)
{
var value = context.ReadValue<Vector2>();
Expand All @@ -63,8 +61,8 @@ private void OnAnalogAimInput(InputAction.CallbackContext context)
RotationDirection = new Vector3(value.x, 0, value.y);
if (analogRotationInput != null)
analogRotationInput.Execute();
}
}

private void OnMouseAimInput(InputAction.CallbackContext context)
{
var value = context.ReadValue<Vector2>();
Expand All @@ -77,25 +75,28 @@ private void OnInteractButton(InputAction.CallbackContext context)
{
var value = context.ReadValue<float>();
IsPressingInteract = value >= 0.15f;
if(interactInput != null && IsPressingInteract)
if (interactInput != null && IsPressingInteract)
interactInput.Execute();
}


private void OnSkillButton(InputAction.CallbackContext context)
{
var value = context.ReadValue<float>();
IsUsingSkill = value >= 0.15f;
if (skillInput != null && IsUsingSkill)
skillInput.Execute();
}





private void OnDisable()
{
_inputActions.Player.Movement.performed -= OnMoveInput;
_inputActions.Player.Interact.performed -= OnInteractButton;

_inputActions.Player.AnalogAim.performed -= OnAnalogAimInput;
_inputActions.Player.MouseAim.performed -= OnMouseAimInput;
_inputActions.Player.Skill.performed -= OnSkillButton;

_inputActions.Disable();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace _InputTest.WorldObjects.Chest.Scripts.Monobehaviours
{
public class TreasureChest : MonoBehaviour, IOpenenable, IInteractable
public class TreasureChest : MonoBehaviour, IOpenable, IInteractable
{
[SerializeField] private float force;
[SerializeField] private GameObject lootPrefab;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace _InputTest.WorldObjects.Scripts
{
public interface IOpenenable
public interface IOpenable
{
bool Opened { get; set; }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

namespace _InputTest.WorldObjects.Chest.Scripts.Monobehaviours
{
public class TreasureChest : MonoBehaviour, IOpenenable, IInteractable
public class TreasureChest : MonoBehaviour, IOpenable, IInteractable
{
[SerializeField] private float force;
[SerializeField] private GameObject lootPrefab;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
namespace _InputTest.WorldObjects.Scripts
{
public interface IOpenenable
public interface IOpenable
{
bool Opened { get; set; }

Expand Down