-
Notifications
You must be signed in to change notification settings - Fork 95
Expand file tree
/
Copy pathSetupPlayerInfoSystem.cs
More file actions
60 lines (52 loc) · 1.99 KB
/
SetupPlayerInfoSystem.cs
File metadata and controls
60 lines (52 loc) · 1.99 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using Unity.Burst;
using Unity.Collections;
using Unity.Entities;
using Unity.NetCode;
using Unity.Services.Samples;
using static Unity.Entities.SystemAPI;
namespace Unity.Megacity.Gameplay
{
public struct SetPlayerInfoRequest : IRpcCommand
{
public FixedString64Bytes Name;
public FixedString64Bytes UASId;
public bool IsClient;
}
public struct NameAssigned : IComponentData{}
/// <summary>
/// Send Client information when the Connection is setup
/// </summary>
[BurstCompile]
[WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)]
public partial struct SendPlayerInfoSystem : ISystem
{
public void OnCreate(ref SystemState state)
{
state.RequireForUpdate<NetworkStreamInGame>();
}
public void OnUpdate(ref SystemState state)
{
if (PlayerInfoController.Instance == null)
return;
var commandBuffer = new EntityCommandBuffer(Allocator.Temp);
foreach (var (streaming, entity) in Query<RefRO<NetworkStreamInGame>>().WithNone<NameAssigned>().WithEntityAccess())
{
var requestEntity = commandBuffer.CreateEntity();
var requestData = new SetPlayerInfoRequest
{
Name = PlayerInfoController.Instance.PlayerName,
//This returns [True] if the requester is not a Thin Client
IsClient = !state.World.IsThinClient(),
};
if (requestData.IsClient)
{
requestData.UASId = PlayerAuthentication.PlayerId;
}
commandBuffer.AddComponent<SendRpcCommandRequest>(requestEntity);
commandBuffer.AddComponent(requestEntity, requestData);
commandBuffer.AddComponent(entity, new NameAssigned());
}
commandBuffer.Playback(state.EntityManager);
}
}
}