protected override void OnUpdate()
        {
            ClearMapsIfCreated();

            if (!m_ColliderGroup.IsEmptyIgnoreFilter)
            {
                new PartitionJob
                {
                    EntityType        = GetEntityTypeHandle(),
                    BoundsType        = GetComponentTypeHandle <Bounds2D>(true),
                    ShapeType         = GetComponentTypeHandle <ColliderShape>(true),
                    LargeColliderType = GetComponentTypeHandle <LargeCollider>(true),
                    ParentType        = GetComponentTypeHandle <Parent2D>(true),
                    TagType           = GetComponentTypeHandle <ColliderTag>(true),
                    ColliderTargetMap = TargetMap.AsParallelWriter(),
                    ColliderSourceMap = ColliderMap.AsParallelWriter(),
                    LargeColliders    = LargeColliders.AsParallelWriter(),
                }.Schedule(m_ColliderGroup);
            }

            // Save the final handle for other systems to use
            PartitionJobHandle = Dependency;
        }
示例#2
0
        protected override void OnUpdate()
        {
            // Every frame we switch the previous frame's currentCollisions to this frame's
            // previous collisions. Then we clear the previous frame's previousCollisions and
            // make it this frame's fresh currentCollisions table.
            var currentCollisions  = m_MapSwitch ? m_FrameCollisions0 : m_FrameCollisions1;
            var previousCollisions = m_MapSwitch ? m_FrameCollisions1 : m_FrameCollisions0;

            m_MapSwitch = !m_MapSwitch;
            currentCollisions.Clear();
            m_PossibleCollisions.Clear();

            // Despite having UpdateAfter(SpatialPartitionSystem) as attribute we still need to
            // combine the dependencies between them to ensure public native collection is ready
            // UpdateAfter attribute only handles the IComponentData dependencies and not public native
            // collections.
            var partitionHandle = JobHandle.CombineDependencies(Dependency, m_PartitionSystem.PartitionJobHandle);

            var broadPhase = new BroadPhaseJob
            {
                PossibleCollisions = m_PossibleCollisions.AsParallelWriter(),
                TargetMap          = m_PartitionSystem.TargetMap,
            }.Schedule(m_PartitionSystem.ColliderMap, 1, partitionHandle);

            var narrowPhase = new NarrowPhaseJob
            {
                CurrentFrameCollisions   = currentCollisions.AsParallelWriter(),
                PreviousFrameCollisions  = previousCollisions,
                ColliderNormalFromEntity = GetBufferFromEntity <EdgeNormal>(true),
                ColliderVertexFromEntity = GetBufferFromEntity <ColliderVertex>(true),
                Positions = GetComponentDataFromEntity <Position2D>(true),
                CircleColliderFromEntity  = GetComponentDataFromEntity <CircleCollider>(true),
                CollisionBufferFromEntity = GetBufferFromEntity <CollisionBuffer>(false),
            }.Schedule(m_PossibleCollisions, 1, broadPhase);

            CollisionJobHandle = narrowPhase;
        }