#if RUKHANKA_WITH_NETCODE using Unity.Collections; using Unity.Entities; using Unity.NetCode; using Unity.Burst; using UnityEngine; namespace Rukhanka.Samples { public struct GoInGameRequest : IRpcCommand {} ///////////////////////////////////////////////////////////////////////////////////////////////////// [BurstCompile] [WorldSystemFilter(WorldSystemFilterFlags.ClientSimulation | WorldSystemFilterFlags.ThinClientSimulation)] public partial struct GoInGameClientSystem : ISystem { [BurstCompile] public void OnCreate(ref SystemState state) { var builder = new EntityQueryBuilder(Allocator.Temp) .WithAll() .WithNone(); state.RequireForUpdate(state.GetEntityQuery(builder)); } [BurstCompile] public void OnUpdate(ref SystemState state) { var commandBuffer = new EntityCommandBuffer(Allocator.Temp); foreach (var (id, entity) in SystemAPI.Query>().WithEntityAccess().WithNone()) { commandBuffer.AddComponent(entity); var req = commandBuffer.CreateEntity(); commandBuffer.AddComponent(req); commandBuffer.AddComponent(req, new SendRpcCommandRequest { TargetConnection = entity }); } commandBuffer.Playback(state.EntityManager); } } ///////////////////////////////////////////////////////////////////////////////////////////////////// [BurstCompile] [WorldSystemFilter(WorldSystemFilterFlags.ServerSimulation)] public partial struct GoInGameServerSystem : ISystem { private ComponentLookup networkIdFromEntity; [BurstCompile] public void OnCreate(ref SystemState state) { var builder = new EntityQueryBuilder(Allocator.Temp) .WithAll() .WithAll(); state.RequireForUpdate(state.GetEntityQuery(builder)); networkIdFromEntity = state.GetComponentLookup(true); } [BurstCompile] public void OnUpdate(ref SystemState state) { var worldName = state.WorldUnmanaged.Name; var commandBuffer = new EntityCommandBuffer(Allocator.Temp); networkIdFromEntity.Update(ref state); foreach (var (reqSrc, reqEntity) in SystemAPI.Query>().WithAll().WithEntityAccess()) { commandBuffer.AddComponent(reqSrc.ValueRO.SourceConnection); var networkId = networkIdFromEntity[reqSrc.ValueRO.SourceConnection]; Debug.Log($"'{worldName}' setting connection '{networkId.Value}' to in game"); commandBuffer.DestroyEntity(reqEntity); } commandBuffer.Playback(state.EntityManager); } } } #endif