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:
parent
4071ebda1b
commit
77c6a85988
MLAPI
@ -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)
|
internal GameObject SpawnObject(Vector3 position, Quaternion rotation)
|
||||||
{
|
{
|
||||||
for (int i = 0; i < objects.Length; i++)
|
for (int i = 0; i < objects.Length; i++)
|
||||||
|
@ -31,6 +31,24 @@ namespace MLAPI.NetworkingManagerComponents
|
|||||||
Pools.Add(poolName, new NetworkPool(poolPrefab, size, poolName));
|
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)
|
public static GameObject SpawnPoolObject(string poolName, Vector3 position, Quaternion rotation)
|
||||||
{
|
{
|
||||||
if(NetworkingManager.singleton.isServer)
|
if(NetworkingManager.singleton.isServer)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user