// Schedule the job to apply gravity to all dynamic bodies and copy input velocities internal static JobHandle ScheduleApplyGravityAndCopyInputVelocitiesJob( ref DynamicsWorld world, NativeArray <PhysicsVelocity> inputVelocities, float2 gravityAcceleration, JobHandle inputDeps, int threadCountHint = 0) { if (threadCountHint <= 0) { var job = new ApplyGravityAndCopyInputVelocitiesJob { BodyMotionData = world.BodyMotionData, BodyMotionVelocity = world.BodyMotionVelocity, InputVelocities = inputVelocities, GravityAcceleration = gravityAcceleration }; return(job.Schedule(inputDeps)); } else { var job = new ParallelApplyGravityAndCopyInputVelocitiesJob { BodyMotionData = world.BodyMotionData, BodyMotionVelocity = world.BodyMotionVelocity, InputVelocities = inputVelocities, GravityAcceleration = gravityAcceleration }; return(job.Schedule(world.BodyMotionCount, 64, inputDeps)); } }
// Apply gravity to all dynamic bodies and copy input velocities internal static void ApplyGravityAndCopyInputVelocities( NativeArray <PhysicsBody.MotionData> bodyMotionData, NativeArray <PhysicsBody.MotionVelocity> bodyMotionVelocity, NativeArray <PhysicsVelocity> inputVelocities, float2 gravity) { for (var i = 0; i < bodyMotionData.Length; i++) { ParallelApplyGravityAndCopyInputVelocitiesJob.Execute(i, gravity, bodyMotionData, bodyMotionVelocity, inputVelocities); } }