Esempio n. 1
0
        protected override void OnHandleVerifiedPacket(INetworkPeer sender, WorldUpdatePacket incomingPacket)
        {
            foreach (var spawn in incomingPacket.Spawns)
            {
                var spawnType = Type.GetType(spawn.Type);
                if (spawnType == null)
                {
                    m_Logger.LogWarning("Could not resolve entity type: " + spawn.Type);
                    continue;
                }

                m_TaskScheduler.RunOnMainThread(this, () => m_EntityManager.Spawn(spawn.Id, spawnType), "EntitySpawn[" + spawnType.Name + "]@" + spawn.Id);
            }

            m_TaskScheduler.RunOnMainThread(this, () =>
            {
                foreach (var statePair in incomingPacket.EntityStates.Where(d =>
                                                                            incomingPacket.Spawns.All(e => e.Id != d.Key)))
                {
                    var entity = m_EntityManager.GetEntitiy(statePair.Key);
                    if (entity == null)
                    {
                        return;
                    }

                    var state = statePair.Value;

                    Span <byte> stateSpan = new Span <byte>(state);
                    entity.Read(stateSpan);
                }
            }, "UpdateEntities");

            foreach (var despawnId in incomingPacket.Despawns)
            {
                m_EntityManager.Despawn(despawnId);
            }
        }