Skip to content

Commit 4ad74c7

Browse files
committed
Removed list of spawned object ids
1 parent bde2f0f commit 4ad74c7

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ public Dictionary<uint, NetworkedObject> SpawnedObjects
4848
return spawnedObjects;
4949
}
5050
}
51-
public List<uint> spawnedObjectIds;
5251
private Stack<uint> releasedNetworkObjectIds;
5352
private uint networkObjectIdCounter;
5453
private uint GetNetworkObjectId()
@@ -98,7 +97,6 @@ internal GameObject SpawnObject(int spawnablePrefabIndex, uint networkId, int ow
9897
}
9998
netObject.OwnerClientId = ownerId;
10099

101-
singleton.spawnedObjectIds.Add(netObject.NetworkId);
102100
singleton.spawnedObjects.Add(netObject.NetworkId, netObject);
103101
return go;
104102
}
@@ -123,7 +121,6 @@ internal GameObject SpawnPlayerObject(int clientId, uint networkId)
123121
}
124122
netObject.IsPlayerObject = true;
125123
connectedClients[clientId].PlayerObject = go;
126-
singleton.spawnedObjectIds.Add(netObject.NetworkId);
127124
singleton.spawnedObjects.Add(netObject.NetworkId, netObject);
128125
return go;
129126
}
@@ -221,7 +218,6 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
221218
messageHandlerCounter = new Dictionary<ushort, int>();
222219
releasedMessageHandlerCounters = new Dictionary<ushort, Stack<int>>();
223220
spawnedObjects = new Dictionary<uint, NetworkedObject>();
224-
spawnedObjectIds = new List<uint>();
225221
releasedNetworkObjectIds = new Stack<uint>();
226222
if (NetworkConfig.HandleObjectSpawning)
227223
{
@@ -230,7 +226,6 @@ private ConnectionConfig Init(NetworkingConfiguration netConfig)
230226
{
231227
uint networkId = GetNetworkObjectId();
232228
spawnedObjects.Add(networkId, sceneObjects[i]);
233-
spawnedObjectIds.Add(networkId);
234229
}
235230
}
236231

@@ -806,22 +801,28 @@ private void HandleApproval(int clientId, bool approved)
806801
if (NetworkConfig.HandleObjectSpawning)
807802
{
808803
int amountOfObjectsToSend = 0;
809-
for (int i = 0; i < spawnedObjectIds.Count; i++)
804+
foreach (KeyValuePair<uint, NetworkedObject> pair in spawnedObjects)
810805
{
811-
if (spawnedObjects[spawnedObjectIds[i]].ServerOnly)
806+
if (pair.Value.ServerOnly)
812807
continue;
813808
else
814809
amountOfObjectsToSend++;
815810
}
816811
writer.Write(amountOfObjectsToSend);
817-
for (int i = 0; i < spawnedObjectIds.Count; i++)
812+
813+
foreach (KeyValuePair<uint, NetworkedObject> pair in spawnedObjects)
818814
{
819-
if (spawnedObjects[spawnedObjectIds[i]].ServerOnly)
815+
if (pair.Value.ServerOnly)
816+
continue;
817+
else
818+
amountOfObjectsToSend++;
819+
820+
if (pair.Value.ServerOnly)
820821
continue;
821-
writer.Write(spawnedObjects[spawnedObjectIds[i]].IsPlayerObject);
822-
writer.Write(spawnedObjects[spawnedObjectIds[i]].NetworkId);
823-
writer.Write(spawnedObjects[spawnedObjectIds[i]].OwnerClientId);
824-
writer.Write(spawnedObjects[spawnedObjectIds[i]].SpawnablePrefabId);
822+
writer.Write(pair.Value.IsPlayerObject);
823+
writer.Write(pair.Value.NetworkId);
824+
writer.Write(pair.Value.OwnerClientId);
825+
writer.Write(pair.Value.SpawnablePrefabId);
825826
}
826827
}
827828
}

0 commit comments

Comments
 (0)