Merge pull request #8 from angusmf/master

Allow pasing array of objects to CreatePool, such as from a sceneobje…
This commit is contained in:
Albin Corén 2018-03-05 07:12:06 +01:00 committed by GitHub
commit 6a586f68b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 32 additions and 0 deletions

View File

@ -21,6 +21,20 @@ namespace MLAPI.Data
}
}
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++)

View File

@ -31,6 +31,24 @@ namespace MLAPI.NetworkingManagerComponents
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)