예제 #1
0
        protected override void OnUpdate()
        {
            if (!HasSingleton <GhostPrefabCollectionComponent>())
            {
                return;
            }
            Entities.WithNone <SendRpcCommandRequestComponent>().ForEach((Entity reqEnt, ref LobbyServerInGameRequest req, ref ReceiveRpcCommandRequestComponent reqSrc) =>
            {
                PostUpdateCommands.AddComponent <NetworkStreamInGame>(reqSrc.SourceConnection);
                UnityEngine.Debug.Log(
                    $"Server setting connection {EntityManager.GetComponentData<NetworkIdComponent>(reqSrc.SourceConnection).Value} to in game");
                var ghostCollection = GetSingleton <GhostPrefabCollectionComponent>();
                var ghostId         = SentryGhostSerializerCollection.FindGhostType <LobbyConnectionGhostSnapshotData>();
                var prefab          = EntityManager.GetBuffer <GhostPrefabBuffer>(ghostCollection.serverPrefabs)[ghostId].Value;
                var player          = EntityManager.Instantiate(prefab);

                EntityManager.SetComponentData(player, new LobbyClientConnection()
                {
                    ConnectionId = EntityManager.GetComponentData <NetworkIdComponent>(reqSrc.SourceConnection).Value
                });

                PostUpdateCommands.SetComponent(reqSrc.SourceConnection, new CommandTargetComponent {
                    targetEntity = player
                });

                PostUpdateCommands.DestroyEntity(reqEnt);
            });
        }
예제 #2
0
        protected override JobHandle OnUpdate(JobHandle inputDeps)
        {
            if (!HasSingleton <GhostPrefabCollectionComponent>())
            {
                return(inputDeps);
            }
            if (prefab == Entity.Null)
            {
                var prefabs       = GetSingleton <GhostPrefabCollectionComponent>();
                var serverPrefabs = EntityManager.GetBuffer <GhostPrefabBuffer>(prefabs.serverPrefabs);
                prefab = serverPrefabs[SentryGhostSerializerCollection.FindGhostType <GameInfoSnapshotData>()].Value;
            }

            var commandBuffer = bufferSystem.CreateCommandBuffer()
                                .ToConcurrent();

            var newIds = new NativeArray <int>(required.CalculateEntityCount(), Allocator.TempJob);

            inputDeps = new GetNewGameIds
            {
                Ids   = newIds,
                Infos = gamesQuery.ToComponentDataArrayAsync <GameInfoComponent>(Allocator.TempJob, out JobHandle jh1)
            }.Schedule(JobHandle.CombineDependencies(inputDeps, jh1));