Interactable Entities

This commit is contained in:
ThomasCharester committed 2026-10-12 21:06:46 +03:00
1 parent efb5e1c2e8
commit e05cf28266
142 files changed
+46900 -8796

No files matched your search

+3
View File
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: d8163006a91f414e821415c8470b7ed4
timeCreated: 1791816782
@@ -0,0 +1,9 @@
using UnityEngine;
namespace Code.Game.OfficeGame.Entities
{
public abstract class InteractableEntity : MonoBehaviour
{
public abstract void Interact();
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: a6941805e9fe4e9c9c1fd749e5b1bd10
timeCreated: 1791817565
@@ -0,0 +1,16 @@
using TinyGoose.Tremble;
using UnityEngine;
namespace Code.Game.OfficeGame.Entities
{
[PrefabEntity]
public class TestInteractableEntity : InteractableEntity
{
[SerializeField] private string testText = "Interaction";
public override void Interact()
{
Debug.Log(testText);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 688448f9ab7f4aa1bbce28a75f154984
timeCreated: 1791816884
@@ -0,0 +1,57 @@
using System;
using Code.Game.OfficeGame.Entities;
using Code.Infrastructure.Input;
using Reflex.Attributes;
using UnityEngine;
using UnityEngine.InputSystem;
namespace Code.OfficeGame.Player
{
public class PlayerInteractor : MonoBehaviour
{
private LayerMask _layerMask;
private IInputService _inputService;
private void Awake()
{
_layerMask = LayerMask.GetMask("Interactable");
}
[Inject]
private void Construct(IInputService inputService)
{
_inputService = inputService;
_inputService.BindActionPerformed(
(int)ActionMappings.OpenMovement,
(int)OpenMovementActions.Interact,
Interact);
}
private RaycastHit[] _hitBuffer = new RaycastHit[3];
[SerializeField] private float _maxDistance = 2f;
private void Interact(InputAction.CallbackContext obj)
{
var count = Physics.RaycastNonAlloc(
transform.position,
transform.forward,
_hitBuffer,
_maxDistance,
_layerMask);
if (count == 0) return;
var hit = _hitBuffer[0].transform.GetComponent<InteractableEntity>();
hit.Interact();
}
private void OnDestroy()
{
_inputService.UnbindActionPerformed(
(int)ActionMappings.OpenMovement,
(int)OpenMovementActions.Interact,
Interact);
}
}
}
@@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 4fa129a0134f4e56821c1d166d3b85f3
timeCreated: 1791817123