using Unity.Burst; using Unity.Collections; using Unity.Entities; using Unity.NetCode; namespace EE2Clone.NetCode { /// /// RPC sent by the client to request going in-game. /// public struct GoInGameRequest : IRpcCommand { } /// /// Client-side system: when a connection is established and the streaming is done, /// send a GoInGameRequest RPC to the server. /// [BurstCompile] [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)] public partial struct GoInGameClientSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { state.RequireForUpdate(); } [BurstCompile] public void OnUpdate(ref SystemState state) { var ecb = new EntityCommandBuffer(Allocator.Temp); foreach (var (networkId, entity) in SystemAPI.Query>() .WithNone() .WithEntityAccess()) { ecb.AddComponent(entity); var requestEntity = ecb.CreateEntity(); ecb.AddComponent(requestEntity, new GoInGameRequest()); ecb.AddComponent(requestEntity, new SendRpcCommandRequest { TargetConnection = entity }); UnityEngine.Debug.Log($"[Client] Sending GoInGame request (NetworkId={networkId.ValueRO.Value})"); } ecb.Playback(state.EntityManager); ecb.Dispose(); } } }