Пример #1
0
        public void Execute(int i)
        {
            var outerEntity = Entities[i];

            for (int j = i + 1; j < Colliders.Length; j++)
            {
                var innerEntity = Entities[j];

                if (PhysicsUtility.DoCirclesOverlap
                    (
                        Translations[i].Value, Colliders[i].Radius,
                        Translations[j].Value, Colliders[j].Radius,
                        OverlapError, out float overlapAmount
                    ))
                {
                    CommandBuffer.AppendToBuffer(i, outerEntity, new CollisionInfoElementData
                                                 (
                                                     innerEntity,
                                                     Translations[j].Value,
                                                     Colliders[j].Group,
                                                     overlapAmount,
                                                     math.normalize(Translations[i].Value - Translations[j].Value)
                                                 ));

                    CommandBuffer.AppendToBuffer(i, innerEntity, new CollisionInfoElementData
                                                 (
                                                     outerEntity,
                                                     Translations[i].Value,
                                                     Colliders[i].Group,
                                                     overlapAmount,
                                                     math.normalize(Translations[j].Value - Translations[i].Value)
                                                 ));

                    if (Colliders[i].Group == CollisionLayer.Obstacle ||
                        Colliders[j].Group == CollisionLayer.Obstacle ||
                        Colliders[j].Group == Colliders[i].Group)
                    {
                        CommandBuffer.AddComponent <HandleCollisionWithBounceTag>(i, outerEntity);
                        CommandBuffer.AddComponent <RigidbodyCollisionTag>(i, outerEntity);

                        CommandBuffer.AddComponent <HandleCollisionWithBounceTag>(i, innerEntity);
                        CommandBuffer.AddComponent <RigidbodyCollisionTag>(i, innerEntity);
                    }
                    else
                    {
                        CommandBuffer.AddComponent <HaveBattleTag>(i, outerEntity);
                        CommandBuffer.AddComponent <HaveBattleTag>(i, innerEntity);
                    }
                }
            }
        }
            public void Execute(int jobIndex)
            {
                var circleRadius      = CircleColliders[jobIndex].Radius;
                var circleTranslation = CircleTranslations[jobIndex].Value;
                var circleEntity      = CircleEntities[jobIndex];

                for (int i = 0; i < AABBColliders.Length; i++)
                {
                    if (PhysicsUtility.DoCirclesAndAABBOverlap
                        (
                            circleTranslation, circleRadius,
                            AABBTranslations[i].Value, AABBColliders[i].Size,
                            OverlapError, out float3 closestPoint, out float overlapAmount
                        ))
                    {
                        var normal = PhysicsUtility.GetAABBNormalFromPoint
                                     (
                            AABBTranslations[i].Value,
                            AABBColliders[i].Size,
                            circleTranslation
                                     );

                        CommandBuffer.AppendToBuffer(jobIndex, circleEntity, new CollisionInfoElementData
                                                     (
                                                         AABBEntities[i],
                                                         closestPoint,
                                                         CollisionLayer.Obstacle,
                                                         overlapAmount,
                                                         normal
                                                     ));

                        CommandBuffer.AddComponent <HandleCollisionWithBounceTag>(jobIndex, circleEntity);
                        CommandBuffer.AddComponent <RigidbodyCollisionTag>(jobIndex, circleEntity);
                    }
                }
            }