using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.MegaCity.UI; using Unity.NetCode; using static Unity.Entities.SystemAPI; namespace Unity.MegaCity.Gameplay { public struct SetPlayerInfoRequest : IRpcCommand { public FixedString64Bytes Name; public FixedString64Bytes PlayerId; public bool IsClient; } public struct NameAssigned : IComponentData{} /// /// Send Client information when the Connection is setup /// [BurstCompile] [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)] public partial struct SendPlayerInfoSystem : ISystem { public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } public void OnUpdate(ref SystemState state) { if (PlayerInfoController.Instance == null) return; var commandBuffer = new EntityCommandBuffer(Allocator.Temp); foreach (var (streaming, entity) in Query>().WithNone().WithEntityAccess()) { var requestEntity = commandBuffer.CreateEntity(); var requestData = new SetPlayerInfoRequest { Name = PlayerInfoController.Instance.Name, // This returns [True] if the requester is not a Thin Client IsClient = !state.World.IsThinClient(), }; if (requestData.IsClient) { requestData.PlayerId = MultiverseRoomAPI.Instance.PlayerID; // requestData.PlayerId = PlayerAuthentication.PlayerId; } commandBuffer.AddComponent(requestEntity); commandBuffer.AddComponent(requestEntity, requestData); commandBuffer.AddComponent(entity, new NameAssigned()); } commandBuffer.Playback(state.EntityManager); } } }