fix: Do not call InternalAddPlayer twice (#1246)

This commit is contained in:
Paul Pacheco 2019-11-28 13:47:31 -06:00 committed by GitHub
parent 4c0fb9ba34
commit 7119dd15f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -510,12 +510,6 @@ internal static void OnSpawn(SpawnMessage msg)
} }
if (LogFilter.Debug) Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}"); if (LogFilter.Debug) Debug.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}");
// is this supposed to be the local player?
if (msg.isLocalPlayer)
{
OnSpawnMessageForLocalPlayer(msg.netId);
}
// was the object already spawned? // was the object already spawned?
NetworkIdentity identity = GetExistingObject(msg.netId); NetworkIdentity identity = GetExistingObject(msg.netId);
@ -716,30 +710,14 @@ internal static void OnSyncEventMessage(SyncEventMessage msg)
} }
} }
// called for the one object in the spawn message which is the local player!
internal static void OnSpawnMessageForLocalPlayer(uint netId)
{
if (LogFilter.Debug) Debug.Log("ClientScene.OnSpawnMessageForLocalPlayer - " + readyConnection + " netId: " + netId);
// is there already an owner that is a different object??
if (readyConnection.identity != null)
{
readyConnection.identity.SetNotLocalPlayer();
}
if (NetworkIdentity.spawned.TryGetValue(netId, out NetworkIdentity localObject) && localObject != null)
{
// this object already exists
localObject.connectionToServer = readyConnection;
localObject.SetLocalPlayer();
InternalAddPlayer(localObject);
}
}
static void CheckForLocalPlayer(NetworkIdentity identity) static void CheckForLocalPlayer(NetworkIdentity identity)
{ {
if (identity.pendingLocalPlayer) if (identity.pendingLocalPlayer)
{ {
if (readyConnection.identity != null && readyConnection.identity != identity)
{
readyConnection.identity.SetNotLocalPlayer();
}
// supposed to be local player, so make it the local player! // supposed to be local player, so make it the local player!
// Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO // Set isLocalPlayer to true on this NetworkIdentity and trigger OnStartLocalPlayer in all scripts on the same GO