I literally just started looking at Entitas last night so there may be better solutions, but you could do something like the following:
Create a component to store the collisions
[UniquePrefix("has")]
public class Collisions : IComponent
{
public List<GameObject> list;
public bool isInitialized;
}
Create a MonoBehaviour that forwards the relevant physics events to the entity
public class CollisionReporter : MonoBehaviour
{
public GameEntity Entity;
private void OnCollisionEnter(Collision other)
{
Entity.collisions.list.Add(other.gameObject);
}
}
Create a system that links collisions entities to gameobjects with the MonoBehaviour above and responds to the collisions
public class CollisionSystem : ReactiveSystem<GameEntity>
{
private readonly IContext<GameEntity> _context;
public CollisionSystem(IContext<GameEntity> context) : base(context)
{
_context = context;
}
protected override ICollector<GameEntity> GetTrigger(IContext<GameEntity> context)
{
return context.CreateCollector(GameMatcher.Collisions);
}
protected override bool Filter(GameEntity entity)
{
return entity.hasCollisions;
}
protected override void Execute(List<GameEntity> entities)
{
foreach (var e in entities)
{
if (!e.collisions.isInitialized)
{
var go = new GameObject();
go.Link(e, _context);
// Add and configure RigidBody, Collider, etc.
var collisionReporter = go.AddComponent<CollisionReporter>();
collisionReporter.Entity = e;
e.collisions.isInitialized = true;
}
foreach (var other in e.collisions.list)
{
// Do whatever collision response you need...
}
e.collisions.list.Clear();
}
}
}