internal NetworkIdentity SpawnSceneObject(SpawnMessage msg) { var spawned = SpawnSceneObject(msg.sceneId.Value); if (spawned == null) { logger.LogError($"Spawn scene object not found for {msg.sceneId:X} SpawnableObjects.Count={spawnableObjects.Count}"); // dump the whole spawnable objects dict for easier debugging if (logger.LogEnabled()) { foreach (var kvp in spawnableObjects) { logger.Log($"Spawnable: SceneId={kvp.Key} name={kvp.Value.name}"); } } } if (logger.LogEnabled()) { logger.Log($"Client spawn for [netId:{msg.netId}] [sceneId:{msg.sceneId:X}] obj:{spawned}"); } return(spawned); }
internal void OnSpawn(SpawnMessage msg) { if (msg.prefabHash == null && msg.sceneId == null) { throw new InvalidOperationException($"OnSpawn has empty prefabHash and sceneId for netId: {msg.netId}"); } if (logger.LogEnabled()) { logger.Log($"Client spawn handler instantiating netId={msg.netId} prefabHash={msg.prefabHash:X} sceneId={msg.sceneId:X} pos={msg.position}"); } // was the object already spawned? var existing = Client.World.TryGetIdentity(msg.netId, out var identity); if (!existing) { //is the object on the prefab or scene object lists? identity = msg.sceneId.HasValue ? SpawnSceneObject(msg) : SpawnPrefab(msg); } if (identity == null) { //object could not be found. throw new InvalidOperationException($"Could not spawn prefabHash={msg.prefabHash:X} scene={msg.sceneId:X} netId={msg.netId}"); } ApplySpawnPayload(identity, msg); // add after applying payload, but only if it is new object if (!existing) { Client.World.AddIdentity(msg.netId, identity); } }
internal void OnSpawn(SpawnMessage msg) { if (msg.assetId == Guid.Empty && msg.sceneId == 0) { throw new InvalidOperationException("OnObjSpawn netId: " + msg.netId + " has invalid asset Id"); } if (logger.LogEnabled()) { logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}"); } bool spawned = false; // was the object already spawned? NetworkIdentity identity = GetExistingObject(msg.netId); if (identity == null) { //is the object on the prefab or scene object lists? identity = msg.sceneId == 0 ? SpawnPrefab(msg) : SpawnSceneObject(msg); spawned = true; } if (identity == null) { //object could not be found. throw new InvalidOperationException($"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); } ApplySpawnPayload(identity, msg); if (spawned) { Spawned.Invoke(identity); } }
internal NetworkIdentity SpawnSceneObject(SpawnMessage msg) { NetworkIdentity spawnedId = SpawnSceneObject(msg.sceneId); if (spawnedId == null) { logger.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 (logger.LogEnabled()) { foreach (KeyValuePair <ulong, NetworkIdentity> kvp in spawnableObjects) { logger.Log("Spawnable: SceneId=" + kvp.Key + " name=" + kvp.Value.name); } } } if (logger.LogEnabled()) { logger.Log("Client spawn for [netId:" + msg.netId + "] [sceneId:" + msg.sceneId + "] obj:" + spawnedId); } return(spawnedId); }
internal void OnSpawn(SpawnMessage msg) { if (msg.assetId == Guid.Empty && msg.sceneId == 0) { throw new InvalidOperationException("OnObjSpawn netId: " + msg.netId + " has invalid asset Id"); } if (logger.LogEnabled()) { logger.Log($"Client spawn handler instantiating netId={msg.netId} assetID={msg.assetId} sceneId={msg.sceneId} pos={msg.position}"); } // was the object already spawned? bool existing = Client.World.TryGetIdentity(msg.netId, out NetworkIdentity identity); if (!existing) { //is the object on the prefab or scene object lists? identity = msg.sceneId == 0 ? SpawnPrefab(msg) : SpawnSceneObject(msg); } if (identity == null) { //object could not be found. throw new InvalidOperationException($"Could not spawn assetId={msg.assetId} scene={msg.sceneId} netId={msg.netId}"); } ApplySpawnPayload(identity, msg); // add after applying payload, but only if it is new object if (!existing) { Client.World.AddIdentity(msg.netId, identity); } }