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
45 lines (39 loc) · 1.42 KB
/
Copy pathNetworkManager.cs
File metadata and controls
45 lines (39 loc) · 1.42 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
39
40
41
42
43
44
45
using Unity.Entities;
using Unity.NetCode;
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()
{
var sceneName = UnityEngine.SceneManagement.SceneManager.GetActiveScene().name;
if (!(sceneName.Contains("LevelSync") || sceneName.Contains("JumpOff")))
Enabled = false;
m_CommandBuffer = World.GetOrCreateSystemManaged<BeginSimulationEntityCommandBufferSystem>();
}
[WithNone(typeof(LevelSync_InitializedConnection))]
partial struct ConnectionJob : IJobEntity
{
public EntityCommandBuffer commandBuffer;
void Execute(Entity entity, ref NetworkStreamConnection state)
{
commandBuffer.AddComponent(entity, new LevelSync_InitializedConnection());
Debug.Log($"New connection accepted: {state.Value.ToFixedString()}");
}
}
protected override void OnUpdate()
{
var ecb = m_CommandBuffer.CreateCommandBuffer();
var job = new ConnectionJob()
{
commandBuffer = ecb
};
Dependency = job.Schedule(this.Dependency);
m_CommandBuffer.AddJobHandleForProducer(Dependency);
}
}