forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGoInGameSystem.cs
More file actions
34 lines (31 loc) · 1.39 KB
/
Copy pathGoInGameSystem.cs
File metadata and controls
34 lines (31 loc) · 1.39 KB
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
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
namespace Samples.HelloNetcode
{
// Place any established network connection in-game so ghost snapshot sync can start
[UpdateInGroup(typeof(HelloNetcodeSystemGroup))]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ServerSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial class GoInGameSystem : SystemBase
{
private EntityQuery m_NewConnections;
protected override void OnCreate()
{
RequireForUpdate<EnableGoInGame>();
RequireForUpdate(m_NewConnections);
}
protected override void OnUpdate()
{
var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
FixedString32Bytes worldName = World.Name;
// Go in game as soon as we have a connection set up (connection network ID has been set)
Entities.WithName("NewConnectionsGoInGame").WithStoreEntityQueryInField(ref m_NewConnections).WithNone<NetworkStreamInGame>().ForEach(
(Entity ent, in NetworkId id) =>
{
UnityEngine.Debug.Log($"[{worldName}] Go in game connection {id.Value}");
commandBuffer.AddComponent<NetworkStreamInGame>(ent);
}).Run();
commandBuffer.Playback(EntityManager);
}
}
}