Allow pasing array of objects to CreatePool, such as from a sceneobject. This is to allow the use of scene objects containing such an array of prefabs, which is supposed to be quicker to create than calling instantiate.

This commit is contained in:
DESKTOP-4BMTUHM\Jim 2018-03-04 15:23:12 -07:00
parent 4071ebda1b
commit 77c6a85988
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)