protected override void OnUpdate() { var physicsWorld = World.GetOrCreateSystem <BuildPhysicsWorld>().PhysicsWorld; var simulation = World.GetOrCreateSystem <StepPhysicsWorld>().Simulation; Entities.ForEach((DynamicBuffer <CollisionBuffer> collisions) => { collisions.Clear(); }).Run(); // POPULATE TO NOT RETURN NULL var collisionJobHandle = new CollisionSystemJob() { collisions = GetBufferFromEntity <CollisionBuffer>() }.Schedule(simulation, ref physicsWorld, this.Dependency); collisionJobHandle.Complete(); // Entities.ForEach((DynamicBuffer <TriggerBuffer> triggers) => { triggers.Clear(); }).Run(); // var triggerJobHandle = new TriggerSystemJob() { triggers = GetBufferFromEntity <TriggerBuffer>() }.Schedule(simulation, ref physicsWorld, this.Dependency); triggerJobHandle.Complete(); }
protected override void OnUpdate() { // References for collision and triggers var pw = World.GetOrCreateSystem <BuildPhysicsWorld>().PhysicsWorld; var sim = World.GetOrCreateSystem <StepPhysicsWorld>().Simulation; // Handle Collsions Entities.ForEach((DynamicBuffer <CollisionBuffer> collisions) => { collisions.Clear(); }).Run(); var colJobHandle = new CollisionSystemJob() { collisions = GetBufferFromEntity <CollisionBuffer>() } .Schedule(sim, ref pw, this.Dependency); colJobHandle.Complete(); // Handle Triggers Entities.ForEach((DynamicBuffer <TriggerBuffer> triggers) => { triggers.Clear(); }).Run(); var trigJobHandle = new TriggerSystemJob() { triggers = GetBufferFromEntity <TriggerBuffer>() } .Schedule(sim, ref pw, this.Dependency); trigJobHandle.Complete(); }
//protected override void OnCreate() //{ // } //protected override void OnDestroy() //{ //} protected override void OnUpdate() { // Assign values to local variables captured in your job here, so that it has // everything it needs to do its work when it runs later. // For example, // float deltaTime = Time.DeltaTime; // This declares a new kind of job, which is a unit of work to do. // The job is declared as an Entities.ForEach with the target components as parameters, // meaning it will process all entities in the world that have both // Translation and Rotation components. Change it to process the component // types you want. //Entities.ForEach((ref Translation translation, in Rotation rotation) => { // // Implement the work to perform for each entity here. // // You should only access data that is local or that is a // // field on this job. Note that the 'rotation' parameter is // // marked as 'in', which means it cannot be modified, // // but allows this job to run in parallel with other jobs // // that want to read Rotation component data. // // For example, // // translation.Value += math.mul(rotation.Value, new float3(0, 0, 1)) * deltaTime; //}).Schedule(); var pw = World.GetOrCreateSystem <BuildPhysicsWorld>().PhysicsWorld; var sim = World.GetOrCreateSystem <StepPhysicsWorld>().Simulation; /////////////////////// collisions Entities.ForEach((DynamicBuffer <CollisionBufferData> buffer) => //get all entities that have a collisionData buffer and clear it { buffer.Clear(); }).ScheduleParallel(); var colJobHandle = new CollisionSystemJob() //create a new custom collision job (see struct defined above) { collisions = GetBufferFromEntity <CollisionBufferData>() } .Schedule(sim, ref pw, this.Dependency); //Job.WithCode(() => //{ // //ensure colJob finishes // colJobHandle.Complete(); // }).Run(); ////////////////////// triggers Entities.ForEach((DynamicBuffer <TriggerBuffer> buffer) => { buffer.Clear(); }).ScheduleParallel(); var trigJobHandle = new TriggerSystemJob() { triggers = GetBufferFromEntity <TriggerBuffer>() } .Schedule(sim, ref pw, this.Dependency); Job.WithCode(() => { // //ensure colJob finishes colJobHandle.Complete(); //ensure trigJob finishes trigJobHandle.Complete(); }).Run(); }