Added scene cleanup & checks for already running instances
This commit is contained in:
parent
6ad088e46e
commit
4b8b88d550
@ -365,6 +365,12 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
||||||
public void StartServer()
|
public void StartServer()
|
||||||
{
|
{
|
||||||
|
if (isServer || isClient)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("MLAPI: Cannot start server while an instance is already running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionConfig cConfig = Init();
|
ConnectionConfig cConfig = Init();
|
||||||
if (NetworkConfig.ConnectionApproval)
|
if (NetworkConfig.ConnectionApproval)
|
||||||
{
|
{
|
||||||
@ -389,6 +395,12 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
||||||
public void StartClient()
|
public void StartClient()
|
||||||
{
|
{
|
||||||
|
if (isServer || isClient)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("MLAPI: Cannot start client while an instance is already running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ConnectionConfig cConfig = Init();
|
ConnectionConfig cConfig = Init();
|
||||||
HostTopology hostTopology = new HostTopology(cConfig, NetworkConfig.MaxConnections);
|
HostTopology hostTopology = new HostTopology(cConfig, NetworkConfig.MaxConnections);
|
||||||
hostId = NetworkTransport.AddHost(hostTopology, 0, null);
|
hostId = NetworkTransport.AddHost(hostTopology, 0, null);
|
||||||
@ -453,6 +465,11 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
/// <param name="netConfig">The NetworkingConfiguration to use</param>
|
||||||
public void StartHost()
|
public void StartHost()
|
||||||
{
|
{
|
||||||
|
if (isServer || isClient)
|
||||||
|
{
|
||||||
|
Debug.LogWarning("MLAPI: Cannot start host while an instance is already running");
|
||||||
|
return;
|
||||||
|
}
|
||||||
ConnectionConfig cConfig = Init();
|
ConnectionConfig cConfig = Init();
|
||||||
if (NetworkConfig.ConnectionApproval)
|
if (NetworkConfig.ConnectionApproval)
|
||||||
{
|
{
|
||||||
@ -502,6 +519,7 @@ namespace MLAPI.MonoBehaviours.Core
|
|||||||
isListening = false;
|
isListening = false;
|
||||||
_isClient = false;
|
_isClient = false;
|
||||||
_isServer = false;
|
_isServer = false;
|
||||||
|
SpawnManager.DestroyNonSceneObjects();
|
||||||
NetworkTransport.Shutdown();
|
NetworkTransport.Shutdown();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -75,6 +75,15 @@ namespace MLAPI.NetworkingManagerComponents.Core
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
internal static void DestroyNonSceneObjects()
|
||||||
|
{
|
||||||
|
foreach (KeyValuePair<uint, NetworkedObject> netObject in spawnedObjects)
|
||||||
|
{
|
||||||
|
if (!netObject.Value.sceneObject)
|
||||||
|
MonoBehaviour.Destroy(netObject.Value.gameObject);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
internal static GameObject SpawnObject(int spawnablePrefabIndex, uint networkId, int ownerId, Vector3 position, Quaternion rotation)
|
internal static GameObject SpawnObject(int spawnablePrefabIndex, uint networkId, int ownerId, Vector3 position, Quaternion rotation)
|
||||||
{
|
{
|
||||||
GameObject go = MonoBehaviour.Instantiate(netManager.SpawnablePrefabs[spawnablePrefabIndex]);
|
GameObject go = MonoBehaviour.Instantiate(netManager.SpawnablePrefabs[spawnablePrefabIndex]);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user