Skip to content

Commit 6a586f6

Browse files
authored
Merge pull request #8 from angusmf/master
Allow pasing array of objects to CreatePool, such as from a sceneobje…
2 parents 4071ebd + 77c6a85 commit 6a586f6

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

MLAPI/Data/NetworkPool.cs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,20 @@ internal NetworkPool(GameObject prefab, uint size, string name)
2121
}
2222
}
2323

24+
internal NetworkPool(GameObject[] prefabs, string name)
25+
{
26+
objects = prefabs;
27+
poolName = name;
28+
int size = prefabs.Length;
29+
30+
for (int i = 0; i < size; i++)
31+
{
32+
prefabs[i].name = "Pool " + poolName + " #" + i;
33+
prefabs[i].SetActive(false);
34+
}
35+
36+
}
37+
2438
internal GameObject SpawnObject(Vector3 position, Quaternion rotation)
2539
{
2640
for (int i = 0; i < objects.Length; i++)

MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,24 @@ public static void CreatePool(string poolName, GameObject poolPrefab, uint size
3131
Pools.Add(poolName, new NetworkPool(poolPrefab, size, poolName));
3232
}
3333

34+
35+
public static void CreatePool(string poolName, GameObject[] poolPrefabs)
36+
{
37+
if (Pools.ContainsKey(poolName))
38+
{
39+
Debug.LogWarning("MLAPI: A pool with the name " + poolName + " already exists");
40+
return;
41+
}
42+
else if (poolPrefabs == null)
43+
{
44+
Debug.LogWarning("MLAPI: A pool prefab array is required");
45+
}
46+
PoolIndexToPoolName.Add(PoolIndex, poolName);
47+
PoolNamesToIndexes.Add(poolName, PoolIndex);
48+
PoolIndex++;
49+
Pools.Add(poolName, new NetworkPool(poolPrefabs, poolName));
50+
}
51+
3452
public static GameObject SpawnPoolObject(string poolName, Vector3 position, Quaternion rotation)
3553
{
3654
if(NetworkingManager.singleton.isServer)

0 commit comments

Comments
 (0)