private void SpawnRemotePlayer(Peer peer) { var go = Instantiate(m_playerGo); NetworkedObject nobj = go.GetComponent <NetworkedObject>(); nobj.ServerInitialize(this, peer); m_buffer.AddEntityHeader(peer, OpCodes.Spawn); m_buffer.AddInitialState(nobj); Packet spawnPlayerPacket = m_buffer.GetPacketFromBuffer(PacketFlags.Reliable); var spawnPlayerCommand = GameCommandPool.GetGameCommand(); spawnPlayerCommand.Type = CommandType.Send; spawnPlayerCommand.Target = peer; spawnPlayerCommand.Channel = 0; spawnPlayerCommand.Packet = spawnPlayerPacket; m_commandQueue.Enqueue(spawnPlayerCommand); var spawnPlayerForOthersCommand = GameCommandPool.GetGameCommand(); spawnPlayerForOthersCommand.Type = CommandType.BroadcastOthers; spawnPlayerForOthersCommand.Source = peer; spawnPlayerForOthersCommand.Channel = 1; spawnPlayerForOthersCommand.Packet = spawnPlayerPacket; m_commandQueue.Enqueue(spawnPlayerForOthersCommand); int packetSize = 0; // individual packets /* * // must send all of the old data * for (int i = 0; i < m_entities.Count; i++) * { * if (m_entities[i].Peer.ID == peer.ID) * continue; * * m_buffer.AddEntityHeader(m_entities[i].Peer, OpCodes.Spawn); * m_buffer.AddVector3(m_entities[i].gameObject.transform.position, SharedStuff.Instance.Range); * m_buffer.AddFloat(m_entities[i].gameObject.transform.eulerAngles.y); * m_buffer.AddEntitySyncData(m_entities[i]); * var spawnOthersPacket = m_buffer.GetPacketFromBuffer(PacketFlags.Reliable); * * var spawnOthersCommand = GameCommandPool.GetGameCommand(); * spawnOthersCommand.Type = CommandType.Send; * spawnOthersCommand.Packet = spawnOthersPacket; * spawnOthersCommand.Channel = 1; * spawnOthersCommand.Target = peer; * * packetSize += spawnOthersPacket.Length; * * m_commandQueue.Enqueue(spawnOthersCommand); * } */ // one large packet m_buffer.AddEntityHeader(peer, OpCodes.BulkSpawn); m_buffer.AddInt(m_peers.Count); for (int i = 0; i < m_peers.Count; i++) { if (m_peers[i].Peer.ID == peer.ID) { continue; } m_buffer.AddEntityHeader(m_peers[i].Peer, OpCodes.Spawn, false); m_buffer.AddInitialState(m_peers[i]); } var spawnOthersPacket = m_buffer.GetPacketFromBuffer(PacketFlags.Reliable); var spawnOthersCommand = GameCommandPool.GetGameCommand(); spawnOthersCommand.Type = CommandType.Send; spawnOthersCommand.Packet = spawnOthersPacket; spawnOthersCommand.Channel = 1; spawnOthersCommand.Target = peer; packetSize += spawnOthersPacket.Length; m_commandQueue.Enqueue(spawnOthersCommand); m_peers.Add(peer.ID, nobj); Debug.Log($"Sent SpawnOthersPacket of size {packetSize.ToString()}"); }