Fixed various critical object spawning issues

This commit is contained in:
Albin Corén 2018-04-02 06:29:14 +02:00
parent 679c56a62f
commit 20310d44dd
2 changed files with 6 additions and 6 deletions

View File

@ -797,6 +797,7 @@ namespace MLAPI.MonoBehaviours.Core
uint networkId = messageReader.ReadUInt32(); uint networkId = messageReader.ReadUInt32();
int ownerId = messageReader.ReadInt32(); int ownerId = messageReader.ReadInt32();
int prefabId = messageReader.ReadInt32(); int prefabId = messageReader.ReadInt32();
if (isPlayerObject) if (isPlayerObject)
{ {
connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId }); connectedClients.Add(ownerId, new NetworkedClient() { ClientId = ownerId });

View File

@ -1,4 +1,5 @@
using MLAPI.MonoBehaviours.Core; using MLAPI.MonoBehaviours.Core;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using UnityEngine; using UnityEngine;
@ -170,12 +171,13 @@ namespace MLAPI.NetworkingManagerComponents.Core
Debug.LogWarning("MLAPI: Server only objects does not have to be spawned"); Debug.LogWarning("MLAPI: Server only objects does not have to be spawned");
return; return;
} }
else if (netManager.NetworkConfig.HandleObjectSpawning) else if (!netManager.NetworkConfig.HandleObjectSpawning)
{ {
Debug.LogWarning("MLAPI: NetworkingConfiguration is set to not handle object spawning"); Debug.LogWarning("MLAPI: NetworkingConfiguration is set to not handle object spawning");
return; return;
} }
uint netId = GetNetworkObjectId(); uint netId = GetNetworkObjectId();
netObject.networkId = netId;
spawnedObjects.Add(netId, netObject); spawnedObjects.Add(netId, netObject);
netObject.isSpawned = true; netObject.isSpawned = true;
if (clientOwnerId != null) if (clientOwnerId != null)
@ -192,11 +194,8 @@ namespace MLAPI.NetworkingManagerComponents.Core
writer.Write(netObject.OwnerClientId); writer.Write(netObject.OwnerClientId);
writer.Write(netObject.SpawnablePrefabIndex); writer.Write(netObject.SpawnablePrefabIndex);
} }
//If we are host, send to everyone except ourselves. Otherwise, send to all
if (netManager.isHost) netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer());
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer(), -1);
else
netManager.Send("MLAPI_ADD_OBJECT", "MLAPI_INTERNAL", stream.GetBuffer());
} }
} }
} }