Second commit

This commit is contained in:
ThomasCharester committed 2026-09-20 15:26:03 +03:00
commit 36840f3ad4
999 files changed
+61364

No files matched your search

+64
View File
@@ -0,0 +1,64 @@
using Code.D.Cleaning.CleanTools;
using Code.Infrastructure.Camera;
using Code.Infrastructure.Input;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.D.Player
{
public class PlayerInteractor : MonoBehaviour
{
private IInputService _inputService;
private LayerMask _cleanToolInteractableMask;
private Transform _cameraTransform;
private CleanToolInteractable _lastCleanToolInteractable;
[SerializeField] private float interactionDistance = 5f;
[SerializeField] private PlayerEquipment playerEquipment;
private void Awake()
{
_cleanToolInteractableMask = LayerMask.GetMask("CleanToolInteractable");
}
[Inject]
private void Construct(IInputService inputService, CameraStateMachine cameraStateMachine)
{
_cameraTransform = cameraStateMachine.Camera.transform;
_inputService = inputService;
inputService.BindActionPerformed((int)ActionMappings.Cleaning, (int)CleaningActions.Interact, TryInteract);
}
private void OnDestroy()
{
_inputService.UnbindActionPerformed((int)ActionMappings.Cleaning, (int)CleaningActions.Interact,
TryInteract);
}
private void TryInteract(InputAction.CallbackContext obj)
{
if (!Physics.Raycast(
_cameraTransform.position,
_cameraTransform.forward,
out var info,
interactionDistance,
layerMask: _cleanToolInteractableMask)) return;
CleanToolInteractable interactable;
if (_lastCleanToolInteractable is not null &&
info.collider.GetEntityId() == _lastCleanToolInteractable.GetEntityId())
{
interactable = _lastCleanToolInteractable;
}
else
{
interactable = info.collider.gameObject.GetComponent<CleanToolInteractable>();
_lastCleanToolInteractable = interactable;
}
interactable.Use(playerEquipment.CurrentTool);
}
}
}