Skip to content

Allow pasing array of objects to CreatePool, such as from a sceneobje… #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 5, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions MLAPI/Data/NetworkPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ internal NetworkPool(GameObject prefab, uint size, string name)
}
}

internal NetworkPool(GameObject[] prefabs, string name)
{
objects = prefabs;
poolName = name;
int size = prefabs.Length;

for (int i = 0; i < size; i++)
{
prefabs[i].name = "Pool " + poolName + " #" + i;
prefabs[i].SetActive(false);
}

}

internal GameObject SpawnObject(Vector3 position, Quaternion rotation)
{
for (int i = 0; i < objects.Length; i++)
Expand Down
18 changes: 18 additions & 0 deletions MLAPI/NetworkingManagerComponents/NetworkPoolManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,24 @@ public static void CreatePool(string poolName, GameObject poolPrefab, uint size
Pools.Add(poolName, new NetworkPool(poolPrefab, size, poolName));
}


public static void CreatePool(string poolName, GameObject[] poolPrefabs)
{
if (Pools.ContainsKey(poolName))
{
Debug.LogWarning("MLAPI: A pool with the name " + poolName + " already exists");
return;
}
else if (poolPrefabs == null)
{
Debug.LogWarning("MLAPI: A pool prefab array is required");
}
PoolIndexToPoolName.Add(PoolIndex, poolName);
PoolNamesToIndexes.Add(poolName, PoolIndex);
PoolIndex++;
Pools.Add(poolName, new NetworkPool(poolPrefabs, poolName));
}

public static GameObject SpawnPoolObject(string poolName, Vector3 position, Quaternion rotation)
{
if(NetworkingManager.singleton.isServer)
Expand Down