protected override void OnUpdate() { if (m_Query.CalculateEntityCount() == 0) { return; } Entities .WithName("ClearTriggerEventDynamicBuffersJobParallel") .WithBurst() .WithNone <StatefulTriggerEventExclude>() .ForEach((ref DynamicBuffer <StatefulTriggerEvent> buffer) => { buffer.Clear(); }).ScheduleParallel(); m_StateFulEventBuffers.SwapBuffers(); var currentEvents = m_StateFulEventBuffers.Current; var previousEvents = m_StateFulEventBuffers.Previous; var eventExcludes = GetComponentDataFromEntity <StatefulTriggerEventExclude>(true); var eventBuffers = GetBufferFromEntity <StatefulTriggerEvent>(); Dependency = new StatefulEventCollectionJobs.CollectTriggerEvents { TriggerEvents = currentEvents }.Schedule(m_StepPhysicsWorld.Simulation, Dependency); Job .WithName("ConvertTriggerEventStreamToDynamicBufferJob") .WithBurst() .WithReadOnly(eventExcludes) .WithCode(() => { var statefulEvents = new NativeList <StatefulTriggerEvent>(currentEvents.Length, Allocator.Temp); StatefulSimulationEventBuffers <StatefulTriggerEvent> .GetStatefulEvents(previousEvents, currentEvents, statefulEvents, true); for (int i = 0; i < statefulEvents.Length; i++) { var statefulEvent = statefulEvents[i]; // Only add if the Entity has the Buffer and is not excluded var addToEntityA = eventBuffers.HasComponent(statefulEvent.EntityA) && !eventExcludes.HasComponent(statefulEvent.EntityA); var addToEntityB = eventBuffers.HasComponent(statefulEvent.EntityB) && !eventExcludes.HasComponent(statefulEvent.EntityB); if (addToEntityA) { eventBuffers[statefulEvent.EntityA].Add(statefulEvent); } if (addToEntityB) { eventBuffers[statefulEvent.EntityB].Add(statefulEvent); } } }).Schedule(); }
protected override void OnUpdate() { if (m_Query.CalculateEntityCount() == 0) { return; } Entities .WithName("ClearCollisionEventDynamicBuffersJobParallel") .WithBurst() .ForEach((ref DynamicBuffer <StatefulCollisionEvent> buffer) => { buffer.Clear(); }).ScheduleParallel(); m_StateFulEventBuffers.SwapBuffers(); var currentEvents = m_StateFulEventBuffers.Current; var previousEvents = m_StateFulEventBuffers.Previous; var eventDetails = GetComponentDataFromEntity <StatefulCollisionEventDetails>(true); var eventBuffers = GetBufferFromEntity <StatefulCollisionEvent>(); Dependency = new StatefulEventCollectionJobs.CollectCollisionEventsWithDetails { CollisionEvents = currentEvents, PhysicsWorld = m_BuildPhysicsWorld.PhysicsWorld, EventDetails = eventDetails }.Schedule(m_StepPhysicsWorld.Simulation, Dependency); Job .WithName("ConvertCollisionEventStreamToDynamicBufferJob") .WithBurst() .WithCode(() => { var statefulEvents = new NativeList <StatefulCollisionEvent>(currentEvents.Length, Allocator.Temp); StatefulSimulationEventBuffers <StatefulCollisionEvent> .GetStatefulEvents(previousEvents, currentEvents, statefulEvents); for (int i = 0; i < statefulEvents.Length; i++) { var statefulEvent = statefulEvents[i]; var addToEntityA = eventBuffers.HasComponent(statefulEvent.EntityA); var addToEntityB = eventBuffers.HasComponent(statefulEvent.EntityB); if (addToEntityA) { eventBuffers[statefulEvent.EntityA].Add(statefulEvent); } if (addToEntityB) { eventBuffers[statefulEvent.EntityB].Add(statefulEvent); } } }).Schedule(); }
protected override void OnCreate() { m_StepPhysicsWorld = World.GetOrCreateSystem <StepPhysicsWorld>(); m_BuildPhysicsWorld = World.GetOrCreateSystem <BuildPhysicsWorld>(); m_Query = GetEntityQuery(new EntityQueryDesc { All = new ComponentType[] { typeof(StatefulCollisionEvent) } }); m_StateFulEventBuffers = new StatefulSimulationEventBuffers <StatefulCollisionEvent>(); }