static NetworkIdentity SpawnSceneObject(SpawnMessage msg) { NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId); if (spawnedId == null) { Debug.LogError("Spawn scene object not found for " + msg.sceneId.ToString("X") + " SpawnableObjects.Count=" + spawnableObjects.Count); // dump the whole spawnable objects dict for easier debugging if (LogFilter.Debug) { foreach (KeyValuePair <ulong, NetworkIdentity> kvp in spawnableObjects) { Debug.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name); } } } if (LogFilter.Debug) { Debug.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId); } return(spawnedId); }
static void ApplySpawnPayload(NetworkIdentity identity, SpawnMessage msg) { identity.Reset(); identity.pendingLocalPlayer = msg.isLocalPlayer; identity.assetId = msg.assetId; if (!identity.gameObject.activeSelf) { identity.gameObject.SetActive(true); } // apply local values for VR support identity.transform.localPosition = msg.position; identity.transform.localRotation = msg.rotation; identity.transform.localScale = msg.scale; // deserialize components if any payload // (Count is 0 if there were no components) if (msg.payload.Count > 0) { NetworkReader payloadReader = new NetworkReader(msg.payload); identity.OnUpdateVars(payloadReader, true); } identity.netId = msg.netId; NetworkIdentity.spawned[msg.netId] = identity; identity.pendingAuthority = msg.isOwner; // objects spawned as part of initial state are started on a second pass if (isSpawnFinished) { identity.OnStartClient(); CheckForLocalPlayer(identity); identity.hasAuthority = identity.pendingAuthority; } }