public static void InitEmitterBoxSource(EntityManager mgr, Entity emitter, NativeArray <Entity> particles) { var source = mgr.GetComponentData <EmitterBoxSource>(emitter); foreach (var particle in particles) { var pos = ParticlesUtil.RandomPointInRect(source.rect); // center the box at the origin. // TODO: we could precompute the proper source rect (basically move the origin x/y by half) and // stash it somewhere to avoid division here pos.x -= source.rect.width / 2.0f; pos.y -= source.rect.height / 2.0f; var Translation = mgr.GetComponentData <Translation>(particle); Translation.Value += new float3(pos.x, pos.y, 0.0f); mgr.SetComponentData(particle, Translation); } }