mirror of
https://github.com/Bragin-Stepan/project-entity.git
synced 2026-03-05 07:41:10 +00:00
feat: add sensors
This commit is contained in:
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6859effc3b144554aef3ab59218b3d6e
|
||||
timeCreated: 1771526800
|
||||
@@ -0,0 +1,15 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors
|
||||
{
|
||||
public class CapsuleColliderRegistratorEntityRegistrator : MonoEntityRegistrator
|
||||
{
|
||||
[SerializeField] private CapsuleCollider _collider;
|
||||
|
||||
public override void Register(Entity entity)
|
||||
{
|
||||
entity.AddCapsuleCollider(_collider);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72015d8dc01449c1b86801cc47ccd4a1
|
||||
timeCreated: 1771527211
|
||||
@@ -0,0 +1,21 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using _Project.Develop.Runtime.Utils.ReactiveManagement;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors
|
||||
{
|
||||
public class CapsuleColliderComponent : IEntityComponent { public CapsuleCollider Value; }
|
||||
|
||||
public class ContactsDetectingMask : IEntityComponent { public LayerMask Value; }
|
||||
|
||||
public class ContactCollidersBuffer : IEntityComponent { public Buffer<Collider> Value; }
|
||||
|
||||
public class ContactEntitiesBuffer : IEntityComponent { public Buffer<Entity> Value; }
|
||||
|
||||
public class DeathMask : IEntityComponent { public LayerMask Value; }
|
||||
|
||||
public class IsTouchDeathMask : IEntityComponent { public ReactiveVariable<bool> Value; }
|
||||
|
||||
public class IsTouchAnotherTeam : IEntityComponent { public ReactiveVariable<bool> Value; }
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 97c125dd14164d1abb97f7b6e9491ffb
|
||||
timeCreated: 1771526845
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b6ed068a8dd402780ef9c958b1e62e8
|
||||
timeCreated: 1771526830
|
||||
@@ -0,0 +1,58 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems
|
||||
{
|
||||
public class BodyContactsDetectingSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Buffer<Collider> _contacts;
|
||||
private LayerMask _mask;
|
||||
|
||||
private CapsuleCollider _body;
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_contacts = entity.ContactCollidersBuffer;
|
||||
_mask = entity.ContactsDetectingMask;
|
||||
|
||||
_body = entity.CapsuleCollider;
|
||||
}
|
||||
|
||||
// потом перенести в fixed
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_contacts.Count = Physics.OverlapCapsuleNonAlloc(
|
||||
_body.bounds.min,
|
||||
_body.bounds.max,
|
||||
_body.radius,
|
||||
_contacts.Items,
|
||||
_mask,
|
||||
QueryTriggerInteraction.Ignore);
|
||||
|
||||
RemoveSelfFromContacts();
|
||||
}
|
||||
|
||||
private void RemoveSelfFromContacts()
|
||||
{
|
||||
int indexToRemove = -1;
|
||||
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
{
|
||||
if (_contacts.Items[i] == _body)
|
||||
{
|
||||
indexToRemove = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (indexToRemove >= 0)
|
||||
{
|
||||
for (int i = indexToRemove; i < _contacts.Count - 1; i++)
|
||||
_contacts.Items[i] = _contacts.Items[i + 1];
|
||||
|
||||
_contacts.Count--;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 49c5315e5a484456b5f0544204cd73ef
|
||||
timeCreated: 1771527550
|
||||
@@ -0,0 +1,43 @@
|
||||
using _Project.Develop.Runtime.Entities;
|
||||
using _Project.Develop.Runtime.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace _Project.Develop.Runtime.Logic.Gameplay.Features.Sensors.Systems
|
||||
{
|
||||
public class BodyContactsEntitiesFilterSystem : IInitializableSystem, IUpdatableSystem
|
||||
{
|
||||
private Buffer<Collider> _contacts;
|
||||
private Buffer<Entity> _contactsEntities;
|
||||
|
||||
private readonly CollidersRegistryService _collidersRegistryService;
|
||||
|
||||
public BodyContactsEntitiesFilterSystem(CollidersRegistryService collidersRegistryService)
|
||||
{
|
||||
_collidersRegistryService = collidersRegistryService;
|
||||
}
|
||||
|
||||
public void OnInit(Entity entity)
|
||||
{
|
||||
_contacts = entity.ContactCollidersBuffer;
|
||||
_contactsEntities = entity.ContactEntitiesBuffer;
|
||||
}
|
||||
|
||||
public void OnUpdate(float deltaTime)
|
||||
{
|
||||
_contactsEntities.Count = 0;
|
||||
|
||||
for (int i = 0; i < _contacts.Count; i++)
|
||||
{
|
||||
Collider collider = _contacts.Items[i];
|
||||
|
||||
Entity contactEntity = _collidersRegistryService.GetBy(collider);
|
||||
|
||||
if(contactEntity != null)
|
||||
{
|
||||
_contactsEntities.Items[_contactsEntities.Count] = contactEntity;
|
||||
_contactsEntities.Count++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0b49c1d778ab446ebc5f01f15fb97d41
|
||||
timeCreated: 1771527927
|
||||
Reference in New Issue
Block a user