using Unity.Burst;
using Unity.Entities;
using Unity.Physics;
using Unity.Physics.Systems;
using static Unity.Entities.SystemAPI;
namespace Unity.MegaCity.Gameplay
{
///
/// System to handle the player vehicle collision.
///
[BurstCompile]
[UpdateInGroup(typeof(AfterPhysicsSystemGroup))]
partial struct PlayerVehicleCollisionSystem : ISystem
{
private ComponentLookup _physicsVelocities;
private ComponentLookup _vehicleThrust;
[BurstCompile]
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate();
state.RequireForUpdate();
_physicsVelocities = state.GetComponentLookup(true);
_vehicleThrust = state.GetComponentLookup();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var physicsWorldSingleton = GetSingleton();
var simulationSingleton = GetSingleton();
_physicsVelocities.Update(ref state);
_vehicleThrust.Update(ref state);
state.Dependency = new PlayerVehicleCollisionJob
{
SimulateLookup = SystemAPI.GetComponentLookup(true),
Bodies = physicsWorldSingleton.Bodies,
PhysicsVelocities = _physicsVelocities,
VehicleThrusts = _vehicleThrust
}.Schedule(simulationSingleton, state.Dependency);
}
}
}