forked from Unity-Technologies/com.unity.netcode.gameobjects
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathNetworkPool.cs
More file actions
42 lines (39 loc) · 1.53 KB
/
Copy pathNetworkPool.cs
File metadata and controls
42 lines (39 loc) · 1.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using MLAPI.Logging;
using UnityEngine;
namespace MLAPI.Internal
{
internal class NetworkPool
{
internal NetworkedObject[] objects;
internal ushort poolId;
internal NetworkPool(int prefabId, uint size, ushort poolIndex)
{
objects = new NetworkedObject[size];
poolId = poolIndex;
for (int i = 0; i < size; i++)
{
GameObject go = MonoBehaviour.Instantiate(NetworkingManager.singleton.NetworkConfig.NetworkedPrefabs[prefabId].prefab, Vector3.zero, Quaternion.identity) as GameObject;
go.GetComponent<NetworkedObject>().isPooledObject = true;
go.GetComponent<NetworkedObject>().PoolId = poolId;
go.GetComponent<NetworkedObject>().Spawn();
go.name = "Pool Id: " + poolId + " #" + i;
go.SetActive(false);
}
}
internal NetworkedObject SpawnObject(Vector3 position, Quaternion rotation)
{
for (int i = 0; i < objects.Length; i++)
{
if (objects[i].gameObject.activeInHierarchy)
{
GameObject go = objects[i].gameObject;
go.transform.position = position;
go.transform.rotation = rotation;
go.SetActive(true);
}
}
if (LogHelper.CurrentLogLevel <= LogLevel.Normal) LogHelper.LogWarning("The pool " + poolId + " has ran out of space");
return null;
}
}
}