-
Notifications
You must be signed in to change notification settings - Fork 168
/
ClientInGame.cs
47 lines (40 loc) · 1.71 KB
/
ClientInGame.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
41
42
43
44
45
46
47
using Unity.Collections;
using Unity.Entities;
using Unity.MegacityMetro.Gameplay;
using Unity.NetCode;
using Unity.Transforms;
namespace Unity.MegacityMetro
{
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
[UpdateInGroup(typeof(InitializationSystemGroup))]
public partial struct ClientInGame : ISystem
{
private bool m_HasRegisteredSmoothingAction;
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<PlayerSpawner>();
// Client-side optimizations:
var ghostSendSystemData = new GhostSendSystemData {MinSendImportance = 2};
state.EntityManager.CreateSingleton(ghostSendSystemData);
RateSettings.ApplyFrameRate();
}
public void OnUpdate(ref SystemState state)
{
if (!m_HasRegisteredSmoothingAction &&
SystemAPI.TryGetSingletonRW<GhostPredictionSmoothing>(out var ghostPredictionSmoothing))
{
m_HasRegisteredSmoothingAction = true;
ghostPredictionSmoothing.ValueRW.RegisterSmoothingAction<LocalTransform>(state.EntityManager,
MegacityMetroSmoothingAction.Action);
}
var cmdBuffer = new EntityCommandBuffer(Allocator.Temp);
foreach (var (_, entity) in SystemAPI.Query<RefRO<NetworkId>>().WithNone<NetworkStreamInGame>()
.WithEntityAccess())
{
cmdBuffer.AddComponent<NetworkStreamInGame>(entity);
cmdBuffer.AddComponent<ConnectionState>(entity);
}
cmdBuffer.Playback(state.EntityManager);
}
}
}