protected override void OnUpdate() { var endCommandBuffer = endBarrier.CreateCommandBuffer(); Entities .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsSphereCastAll, OnPhysicsCallMessage>() .WithNone <OnDestroyMessage>() .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsSphereCastAll sphereCastAll) => { int numFound = Physics.SphereCastNonAlloc(sphereCastAll.ray, sphereCastAll.radius, results, sphereCastAll.distance, sphereCastAll.layerMask); if (numFound > 0) { var rs = results .Take(numFound) .Where(x => x.rigidbody != null); if (sphereCastAll.distinctDisable == false) { rs = rs.Distinct(raycastHitCompareByRigidbody); } foreach (var hitInfo in rs) { if (EntityBehaviour.getEntity(hitInfo.rigidbody, out var entity, World)) { raycastResults.Add(new PhysicsRaycastResults { entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance }); } } } }); }
protected virtual void onTrigger(Collider other, TriggerResultState state) { if (entityManager == null) { return; } if (entityManager.Exists(entity) == false) { return; } if (EntityBehaviour.getEntity(other.attachedRigidbody, out Entity transformEntity, entityManager.World)) { entityManager.GetBuffer <PhysicsTriggerResults>(entity).Add(new PhysicsTriggerResults { state = state, entity = transformEntity }); }
protected override void OnUpdate() { var endCommandBuffer = endBarrier.CreateCommandBuffer(); Entities .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsRaycast, OnPhysicsCallMessage>() .WithNone <OnDestroyMessage>() .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsRaycast raycast) => { if (Physics.Raycast(raycast.ray, out RaycastHit hitInfo, raycast.distance, raycast.layerMask)) { if (EntityBehaviour.getEntity(hitInfo.rigidbody, out var entity, World)) { raycastResults.Add(new PhysicsRaycastResults { entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance }); } } }); }
protected override void OnUpdate() { var endCommandBuffer = endBarrier.CreateCommandBuffer(); Entities .WithAll <PhysicsRaycastResults>().WithAllReadOnly <PhysicsLinecast, OnPhysicsCallMessage>() .WithNone <OnDestroyMessage>() .ForEach((DynamicBuffer <PhysicsRaycastResults> raycastResults, ref PhysicsLinecast linecast) => { //Debug.DrawLine(linecast.start, linecast.end, Color.white, 0.25f); if (Physics.Linecast(linecast.start, linecast.end, out var hitInfo, linecast.layerMask)) { if (EntityBehaviour.getEntity(hitInfo.rigidbody, out Entity entity, World)) { raycastResults.Add(new PhysicsRaycastResults { entity = entity, point = hitInfo.point, normal = hitInfo.normal, distance = hitInfo.distance }); } } }); }
protected override void OnUpdate() { var endCommandBuffer = endBarrier.CreateCommandBuffer(); /*Entities * .WithAll<Translation, OnPhysicsCallMessage, PhysicsOverlapSphere, PhysicsColliderResults>() * .ForEach((Entity entity, DynamicBuffer<PhysicsColliderResults> overlapResults, ref Translation translation, ref PhysicsOverlapSphere overlapSphere) => * { * int numFound = Physics.OverlapSphereNonAlloc(translation.Value, overlapSphere.radius, results, overlapSphere.layerMask); * if (numFound > 0) * { * for (int i = 0; i < numFound; i++) * { * if (GOEntity.getEntity(results[i], out Entity colliderEntity, World) == false) * continue; * overlapResults.Add(new PhysicsColliderResults { colliderEntity = colliderEntity }); * } * } * });*/ Entities .WithAll <PhysicsResults>().WithAllReadOnly <Translation, PhysicsOverlapSphere, OnPhysicsCallMessage>() .WithNone <OnDestroyMessage>() .ForEach((Entity entity, DynamicBuffer <PhysicsResults> rigidbodyResults, ref Translation translation, ref PhysicsOverlapSphere overlapSphere) => { int numFound = Physics.OverlapSphereNonAlloc(translation.Value, overlapSphere.radius, results, overlapSphere.layerMask); if (numFound > 0) { var rs = results .Take(numFound) .Where(x => x.attachedRigidbody != null); if (overlapSphere.distinctDisable == false) { rs = rs.Distinct(colliderCompareByRigidbody); } DynamicBuffer <PhysicsOverlapHitPoints> physicsOverlapHitPoints = default; var hasPhysicsOverlapHitPoints = false; if (EntityManager.HasComponent <PhysicsOverlapHitPoints>(entity)) { hasPhysicsOverlapHitPoints = true; physicsOverlapHitPoints = EntityManager.GetBuffer <PhysicsOverlapHitPoints>(entity); } foreach (var collider in rs) { var rigidbody = collider.attachedRigidbody; if (EntityBehaviour.getEntity(rigidbody, out var rigidbodyEntity, World) == false /* || entity == rigidbodyEntity*/) { continue; } Debug.Assert(entity != rigidbodyEntity, $"entity != rigidbodyEntity rigidbody={rigidbody}", rigidbody); if (overlapSphere.linecastFilter) { var start = translation.Value; var end = rigidbody.position; if (Physics.Linecast(start, end, out var hitInfo, overlapSphere.layerMask)) { if (hitInfo.rigidbody != rigidbody) { continue; } } else { hitInfo.point = start; } if (hasPhysicsOverlapHitPoints) { physicsOverlapHitPoints.Add(new PhysicsOverlapHitPoints { value = hitInfo.point }); } } rigidbodyResults.Add(new PhysicsResults { entity = rigidbodyEntity }); } ; } });