Skip to content

Commit 63d98d5

Browse files
committed
Added custom spawn and destroy handlers and removed built in pooling support
1 parent 5628aee commit 63d98d5

File tree

9 files changed

+148
-226
lines changed

9 files changed

+148
-226
lines changed

MLAPI/Data/MLAPIConstants.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ public static class MLAPIConstants
1717
public const byte MLAPI_DESTROY_OBJECT = 6;
1818
public const byte MLAPI_SWITCH_SCENE = 7;
1919
public const byte MLAPI_CLIENT_SWITCH_SCENE_COMPLETED = 8;
20-
public const byte MLAPI_SPAWN_POOL_OBJECT = 9;
21-
public const byte MLAPI_DESTROY_POOL_OBJECT = 10;
2220
public const byte MLAPI_CHANGE_OWNER = 11;
2321
public const byte MLAPI_ADD_OBJECTS = 12;
2422
public const byte MLAPI_TIME_SYNC = 13;

MLAPI/Data/NetworkPool.cs

Lines changed: 0 additions & 44 deletions
This file was deleted.

MLAPI/MLAPI.csproj

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@
9898
<Compile Include="Data\Transports\NetEventType.cs" />
9999
<Compile Include="Data\NetworkConfig.cs" />
100100
<Compile Include="Data\NetworkedPrefab.cs" />
101-
<Compile Include="Data\NetworkPool.cs" />
102101
<Compile Include="Data\TrackedPointData.cs" />
103102
<Compile Include="Data\Transports\UNET\RelayedTransport.cs" />
104103
<Compile Include="Data\Transports\UNET\RelayTransport.cs" />
@@ -135,7 +134,6 @@
135134
<Compile Include="MonoBehaviours\Core\TrackedObject.cs" />
136135
<Compile Include="MonoBehaviours\Prototyping\NetworkedTransform.cs" />
137136
<Compile Include="NetworkingManagerComponents\Core\MessageManager.cs" />
138-
<Compile Include="NetworkingManagerComponents\Core\NetworkPoolManager.cs" />
139137
<Compile Include="NetworkingManagerComponents\Core\NetworkSceneManager.cs" />
140138
<Compile Include="NetworkingManagerComponents\Core\SpawnManager.cs" />
141139
<Compile Include="Properties\AssemblyInfo.cs" />

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -67,16 +67,6 @@ internal set
6767
/// Gets if this object is a player object
6868
/// </summary>
6969
public bool IsPlayerObject { get; internal set; }
70-
[Obsolete("Use IsPooledObject instead", false)]
71-
public bool isPooledObject => IsPooledObject;
72-
/// <summary>
73-
/// Gets if this object is part of a pool
74-
/// </summary>
75-
public bool IsPooledObject { get; internal set; }
76-
/// <summary>
77-
/// Gets the poolId this object is part of
78-
/// </summary>
79-
public ushort PoolId { get; internal set; }
8070
[Obsolete("Use IsLocalPlayer instead", false)]
8171
public bool isLocalPlayer => IsLocalPlayer;
8272
/// <summary>

MLAPI/MonoBehaviours/Core/NetworkingManager.cs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -269,8 +269,6 @@ private object Init(bool server)
269269
SpawnManager.SpawnedObjectsList.Clear();
270270
SpawnManager.releasedNetworkObjectIds.Clear();
271271
SpawnManager.PendingSpawnObjects.Clear();
272-
NetworkPoolManager.Pools.Clear();
273-
NetworkPoolManager.PoolNamesToIndexes.Clear();
274272
NetworkSceneManager.registeredSceneNames.Clear();
275273
NetworkSceneManager.sceneIndexToString.Clear();
276274
NetworkSceneManager.sceneNameToIndex.Clear();
@@ -879,13 +877,6 @@ private void HandleIncomingData(uint clientId, byte[] data, int channelId, int t
879877
case MLAPIConstants.MLAPI_SWITCH_SCENE:
880878
if (IsClient) InternalMessageHandler.HandleSwitchScene(clientId, messageStream, channelId);
881879
break;
882-
case MLAPIConstants.MLAPI_SPAWN_POOL_OBJECT:
883-
if (IsClient) InternalMessageHandler.HandleSpawnPoolObject(clientId, messageStream, channelId);
884-
break;
885-
case MLAPIConstants.MLAPI_DESTROY_POOL_OBJECT:
886-
if (IsClient)
887-
InternalMessageHandler.HandleDestroyPoolObject(clientId, messageStream, channelId);
888-
break;
889880
case MLAPIConstants.MLAPI_CHANGE_OWNER:
890881
if (IsClient) InternalMessageHandler.HandleChangeOwner(clientId, messageStream, channelId);
891882
break;
@@ -981,15 +972,33 @@ internal void OnClientDisconnectFromServer(uint clientId)
981972
if (IsServer)
982973
{
983974
if (ConnectedClients[clientId].PlayerObject != null)
984-
Destroy(ConnectedClients[clientId].PlayerObject.gameObject);
975+
{
976+
if (SpawnManager.customDestroyHandlers.ContainsKey(ConnectedClients[clientId].PlayerObject.NetworkedPrefabHash))
977+
{
978+
SpawnManager.customDestroyHandlers[ConnectedClients[clientId].PlayerObject.NetworkedPrefabHash](ConnectedClients[clientId].PlayerObject);
979+
SpawnManager.OnDestroyObject(ConnectedClients[clientId].PlayerObject.NetworkId, false);
980+
}
981+
else
982+
{
983+
Destroy(ConnectedClients[clientId].PlayerObject.gameObject);
984+
}
985+
}
985986

986987
for (int i = 0; i < ConnectedClients[clientId].OwnedObjects.Count; i++)
987988
{
988989
if (ConnectedClients[clientId].OwnedObjects[i] != null)
989990
{
990991
if (!ConnectedClients[clientId].OwnedObjects[i].DontDestroyWithOwner)
991992
{
992-
Destroy(ConnectedClients[clientId].OwnedObjects[i].gameObject);
993+
if (SpawnManager.customDestroyHandlers.ContainsKey(ConnectedClients[clientId].OwnedObjects[i].NetworkedPrefabHash))
994+
{
995+
SpawnManager.customDestroyHandlers[ConnectedClients[clientId].OwnedObjects[i].NetworkedPrefabHash](ConnectedClients[clientId].OwnedObjects[i]);
996+
SpawnManager.OnDestroyObject(ConnectedClients[clientId].OwnedObjects[i].NetworkId, false);
997+
}
998+
else
999+
{
1000+
Destroy(ConnectedClients[clientId].OwnedObjects[i].gameObject);
1001+
}
9931002
}
9941003
else
9951004
{

MLAPI/NetworkingManagerComponents/Core/InternalMessageHandler.Receive.cs

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -305,35 +305,6 @@ internal static void HandleClientSwitchSceneCompleted(uint clientId, Stream stre
305305
}
306306
}
307307

308-
internal static void HandleSpawnPoolObject(uint clientId, Stream stream, int channelId)
309-
{
310-
using (PooledBitReader reader = PooledBitReader.Get(stream))
311-
{
312-
uint netId = reader.ReadUInt32Packed();
313-
314-
float xPos = reader.ReadSinglePacked();
315-
float yPos = reader.ReadSinglePacked();
316-
float zPos = reader.ReadSinglePacked();
317-
318-
float xRot = reader.ReadSinglePacked();
319-
float yRot = reader.ReadSinglePacked();
320-
float zRot = reader.ReadSinglePacked();
321-
322-
SpawnManager.SpawnedObjects[netId].transform.position = new Vector3(xPos, yPos, zPos);
323-
SpawnManager.SpawnedObjects[netId].transform.rotation = Quaternion.Euler(xRot, yRot, zRot);
324-
SpawnManager.SpawnedObjects[netId].gameObject.SetActive(true);
325-
}
326-
}
327-
328-
internal static void HandleDestroyPoolObject(uint clientId, Stream stream, int channelId)
329-
{
330-
using (PooledBitReader reader = PooledBitReader.Get(stream))
331-
{
332-
uint netId = reader.ReadUInt32Packed();
333-
SpawnManager.SpawnedObjects[netId].gameObject.SetActive(false);
334-
}
335-
}
336-
337308
internal static void HandleChangeOwner(uint clientId, Stream stream, int channelId)
338309
{
339310
using (PooledBitReader reader = PooledBitReader.Get(stream))

MLAPI/NetworkingManagerComponents/Core/NetworkPoolManager.cs

Lines changed: 0 additions & 114 deletions
This file was deleted.

MLAPI/NetworkingManagerComponents/Core/NetworkSceneManager.cs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,17 @@ private static void OnSceneUnload(AsyncOperation operation, Guid switchSceneGuid
159159
for (int i = 0; i < netObjects.Length; i++)
160160
{
161161
if (netObjects[i].destroyWithScene == null)
162-
MonoBehaviour.Destroy(netObjects[i].gameObject);
162+
{
163+
if (SpawnManager.customDestroyHandlers.ContainsKey(netObjects[i].NetworkedPrefabHash))
164+
{
165+
SpawnManager.customDestroyHandlers[netObjects[i].NetworkedPrefabHash](netObjects[i]);
166+
SpawnManager.OnDestroyObject(netObjects[i].NetworkId, false);
167+
}
168+
else
169+
{
170+
MonoBehaviour.Destroy(netObjects[i].gameObject);
171+
}
172+
}
163173
}
164174
}
165175

0 commit comments

Comments
 (0)