forked from Unity-Technologies/Megacity-2019
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShootingSystem.cs
40 lines (37 loc) · 1.27 KB
/
ShootingSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
using Unity.Burst;
using Unity.Entities;
using Unity.NetCode;
using Unity.Physics;
using static Unity.Entities.SystemAPI;
namespace Unity.Megacity.Gameplay
{
/// <summary>
/// Handles shooting
/// </summary>
[UpdateInGroup(typeof(PredictedSimulationSystemGroup))]
public partial struct ShootingSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkTime>();
state.RequireForUpdate<PhysicsWorldHistorySingleton>();
state.RequireForUpdate<PhysicsWorldSingleton>();
}
[BurstCompile]
public void OnUpdate(ref SystemState state)
{
var netTime = GetSingleton<NetworkTime>();
if (!netTime.IsFirstTimeFullyPredictingTick)
return;
var laserJob = new LaserJob
{
CollisionHistory = GetSingleton<PhysicsWorldHistorySingleton>(),
PhysicsWorld = GetSingleton<PhysicsWorldSingleton>().PhysicsWorld,
DeltaTime = Time.DeltaTime,
PredictingTick = netTime.ServerTick,
healthLookup = GetComponentLookup<VehicleHealth>()
};
state.Dependency = laserJob.ScheduleParallel(state.Dependency);
}
}
}