forked from Unity-Technologies/EntityComponentSystemSamples
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkManager.cs
More file actions
38 lines (32 loc) · 1.26 KB
/
Copy pathNetworkManager.cs
File metadata and controls
38 lines (32 loc) · 1.26 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
35
36
37
38
using Unity.Entities;
using Unity.NetCode;
using Unity.Networking.Transport;
using UnityEngine;
public struct LevelSync_InitializedConnection : IComponentData
{
}
[RequireMatchingQueriesForUpdate]
[WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)]
public partial class LevelSync_ServerConnectionSystem : SystemBase
{
private BeginSimulationEntityCommandBufferSystem m_CommandBuffer;
protected override void OnCreate()
{
#if !UNITY_DOTSRUNTIME
var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
if (!(sceneName.Contains("LevelSync") || sceneName.Contains("JumpOff")))
Enabled = false;
#endif
m_CommandBuffer = World.GetOrCreateSystemManaged<BeginSimulationEntityCommandBufferSystem>();
}
protected override void OnUpdate()
{
var commandBuffer = m_CommandBuffer.CreateCommandBuffer();
Entities.WithNone<LevelSync_InitializedConnection>().ForEach((Entity entity, ref NetworkStreamConnection state) =>
{
commandBuffer.AddComponent(entity, new LevelSync_InitializedConnection());
Debug.Log($"New connection accepted: {state.Value.ToFixedString()}");
}).Schedule();
m_CommandBuffer.AddJobHandleForProducer(Dependency);
}
}