Skip to content

Commit aa10528

Browse files
committed
Split up NetworkingManager to NetworkingManagerComponents
1 parent 44a8765 commit aa10528

File tree

7 files changed

+317
-278
lines changed

7 files changed

+317
-278
lines changed

MLAPI/Data/NetworkingConfiguration.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System;
22
using System.Collections.Generic;
33
using System.IO;
4-
using System.Linq;
54
using System.Net;
65
using System.Security.Cryptography;
76
using UnityEngine.Networking;

MLAPI/MLAPI.csproj

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,8 @@
5656
<Compile Include="MonoBehaviours\Core\NetworkedObject.cs" />
5757
<Compile Include="Data\NetworkingConfiguration.cs" />
5858
<Compile Include="MonoBehaviours\Core\NetworkingManager.cs" />
59+
<Compile Include="NetworkingManagerComponents\MessageManager.cs" />
60+
<Compile Include="NetworkingManagerComponents\SpawnManager.cs" />
5961
<Compile Include="Properties\AssemblyInfo.cs" />
6062
</ItemGroup>
6163
<ItemGroup>

MLAPI/MonoBehaviours/Core/NetworkedBehaviour.cs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
using System;
22
using System.Collections.Generic;
3-
using System.IO;
43
using UnityEngine;
5-
using System.Linq;
4+
using MLAPI.NetworkingManagerComponents;
65

76
namespace MLAPI
87
{
@@ -29,6 +28,13 @@ protected bool isClient
2928
return NetworkingManager.singleton.isClient;
3029
}
3130
}
31+
protected bool isHost
32+
{
33+
get
34+
{
35+
return NetworkingManager.singleton.isHost;
36+
}
37+
}
3238
protected NetworkedObject networkedObject
3339
{
3440
get
@@ -62,14 +68,14 @@ public int ownerClientId
6268

6369
public int RegisterMessageHandler(string name, Action<int, byte[]> action)
6470
{
65-
int counter = NetworkingManager.singleton.AddIncomingMessageHandler(name, action);
71+
int counter = MessageManager.AddIncomingMessageHandler(name, action);
6672
registeredMessageHandlers.Add(name, counter);
6773
return counter;
6874
}
6975

7076
public void DeregisterMessageHandler(string name, int counter)
7177
{
72-
NetworkingManager.singleton.RemoveIncomingMessageHandler(name, counter);
78+
MessageManager.RemoveIncomingMessageHandler(name, counter);
7379
}
7480

7581
private void OnDestroy()
@@ -84,7 +90,7 @@ public void SendToServer(string messageType, string channelName, byte[] data)
8490
{
8591
if (isServer)
8692
{
87-
NetworkingManager.singleton.InvokeMessageHandlers(messageType, data, -1);
93+
MessageManager.InvokeMessageHandlers(messageType, data, -1);
8894
}
8995
else
9096
{
@@ -154,7 +160,7 @@ public void SendToClients(string messageType, string channelName, byte[] data)
154160

155161
public NetworkedObject GetNetworkedObject(uint networkId)
156162
{
157-
return NetworkingManager.singleton.SpawnedObjects[networkId];
163+
return SpawnManager.spawnedObjects[networkId];
158164
}
159165
}
160166
}

MLAPI/MonoBehaviours/Core/NetworkedObject.cs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
using UnityEngine;
1+
using MLAPI.NetworkingManagerComponents;
2+
using UnityEngine;
23

34
namespace MLAPI
45
{
@@ -31,19 +32,19 @@ public bool IsOwner
3132

3233
private void OnDestroy()
3334
{
34-
NetworkingManager.singleton.OnDestroyObject(NetworkId, false);
35+
SpawnManager.OnDestroyObject(NetworkId, false);
3536
}
3637

3738
internal bool isSpawned = false;
3839

3940
public void Spawn()
4041
{
41-
NetworkingManager.singleton.OnSpawnObject(this);
42+
SpawnManager.OnSpawnObject(this);
4243
}
4344

4445
public void SpawnWithOwnership(int clientId)
4546
{
46-
NetworkingManager.singleton.OnSpawnObject(this, clientId);
47+
SpawnManager.OnSpawnObject(this, clientId);
4748
}
4849
}
4950
}

0 commit comments

Comments
 (0)