static void OnSpawnSceneObject(NetworkMessage netMsg)
{
SpawnSceneObjectMessage msg = new SpawnSceneObjectMessage();
netMsg.ReadMessage(msg);
if (LogFilter.logDebug)
{
Debug.Log("Client spawn scene handler instantiating [netId:" + msg.netId + " sceneId:" + msg.sceneId + " pos:" + msg.position);
}
#if UNITY_EDITOR
UnityEditor.NetworkDetailStats.IncrementStat(
UnityEditor.NetworkDetailStats.NetworkDirection.Incoming,
(short)MsgType.SpawnSceneObject, "sceneId", 1);
#endif
NetworkIdentity localNetworkIdentity;
if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity))
{
// this object already exists (was in the scene)
localNetworkIdentity.Reset();
ApplySpawnPayload(localNetworkIdentity, msg.position, msg.payload, msg.netId, localNetworkIdentity.gameObject);
return;
}
NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId);
if (spawnedId == null)
{
if (LogFilter.logError)
{
Debug.LogError("Spawn scene object not found for " + msg.sceneId + " SpawnableObjects.Count=" + s_SpawnableObjects.Count);
// dump the whole spawnable objects dict for easier debugging
foreach (var kvp in s_SpawnableObjects)
{
Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name);
}
}
return;
}
if (LogFilter.logDebug)
{
Debug.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId.gameObject.name);
}
spawnedId.Reset();
ApplySpawnPayload(spawnedId, msg.position, msg.payload, msg.netId, spawnedId.gameObject);
}