private GetNetworkIdentity ( |
||
netId | ||
uv | ||
return | bool |
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage(s_ObjectSpawnMessage); if (!s_ObjectSpawnMessage.assetId.IsValid()) { if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + s_ObjectSpawnMessage.netId + " has invalid asset Id"); } return; } if (LogFilter.logDebug) { Debug.Log("Client spawn handler instantiating [netId:" + s_ObjectSpawnMessage.netId + " asset ID:" + s_ObjectSpawnMessage.assetId + " pos:" + s_ObjectSpawnMessage.position + "]"); } GameObject prefab; SpawnDelegate handler; if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.netId, out NetworkIdentity uv)) { ApplySpawnPayload(uv, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, null); } else if (NetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out prefab)) { GameObject gameObject = (GameObject)Object.Instantiate(prefab, s_ObjectSpawnMessage.position, Quaternion.identity); uv = gameObject.GetComponent <NetworkIdentity>(); if (uv == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity"); } } else { ApplySpawnPayload(uv, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, gameObject); } } else if (NetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out handler)) { GameObject gameObject2 = handler(s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.assetId); if (gameObject2 == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + s_ObjectSpawnMessage.assetId + " returned null"); } return; } uv = gameObject2.GetComponent <NetworkIdentity>(); if (uv == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a network identity"); } } else { uv.SetDynamicAssetId(s_ObjectSpawnMessage.assetId); ApplySpawnPayload(uv, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, gameObject2); } } else if (LogFilter.logError) { Debug.LogError("Failed to spawn server object, assetId=" + s_ObjectSpawnMessage.assetId + " netId=" + s_ObjectSpawnMessage.netId); } }
static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage(s_ObjectSpawnMessage); if (!s_ObjectSpawnMessage.assetId.IsValid()) { if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + s_ObjectSpawnMessage.netId + " has invalid asset Id"); } return; } if (LogFilter.logDebug) { Debug.Log("Client spawn handler instantiating [netId:" + s_ObjectSpawnMessage.netId + " asset ID:" + s_ObjectSpawnMessage.assetId + " pos:" + s_ObjectSpawnMessage.position + "]"); } #if UNITY_EDITOR UnityEditor.NetworkDetailStats.IncrementStat( UnityEditor.NetworkDetailStats.NetworkDirection.Incoming, MsgType.ObjectSpawn, GetStringForAssetId(s_ObjectSpawnMessage.assetId), 1); #endif NetworkIdentity localNetworkIdentity; if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.netId, out localNetworkIdentity)) { // this object already exists (was in the scene), just apply the update to existing object ApplySpawnPayload(localNetworkIdentity, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, null, s_ObjectSpawnMessage.data); return; } GameObject prefab; SpawnDelegate handler; SpawnExDelegate exHandler; if (NetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out prefab)) { var obj = (GameObject)Object.Instantiate(prefab, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.rotation); if (LogFilter.logDebug) { Debug.Log("Client spawn handler instantiating [netId:" + s_ObjectSpawnMessage.netId + " asset ID:" + s_ObjectSpawnMessage.assetId + " pos:" + s_ObjectSpawnMessage.position + " rotation: " + s_ObjectSpawnMessage.rotation + "]"); } localNetworkIdentity = obj.GetComponent <NetworkIdentity>(); if (localNetworkIdentity == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity"); } return; } localNetworkIdentity.Reset(); ApplySpawnPayload(localNetworkIdentity, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, obj); } // lookup registered factory for type: else if (NetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out handler)) { GameObject obj = handler(s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.assetId); if (obj == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + s_ObjectSpawnMessage.assetId + " returned null"); } return; } localNetworkIdentity = obj.GetComponent <NetworkIdentity>(); if (localNetworkIdentity == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a network identity"); } return; } localNetworkIdentity.Reset(); localNetworkIdentity.SetDynamicAssetId(s_ObjectSpawnMessage.assetId); ApplySpawnPayload(localNetworkIdentity, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, obj); } else if (NetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out exHandler)) { GameObject obj = exHandler(s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.assetId, s_ObjectSpawnMessage.data); if (obj == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + s_ObjectSpawnMessage.assetId + " returned null"); } return; } localNetworkIdentity = obj.GetComponent <NetworkIdentity>(); if (localNetworkIdentity == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a network identity"); } return; } localNetworkIdentity.Reset(); localNetworkIdentity.SetDynamicAssetId(s_ObjectSpawnMessage.assetId); ApplySpawnPayload(localNetworkIdentity, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, obj, s_ObjectSpawnMessage.data); } else { if (LogFilter.logError) { Debug.LogError("Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=" + s_ObjectSpawnMessage.assetId + " netId=" + s_ObjectSpawnMessage.netId); } } }
private static void OnClientAuthority(NetworkMessage netMsg) { NetworkIdentity identity; netMsg.ReadMessage <ClientAuthorityMessage>(s_ClientAuthorityMessage); if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "ClientScene::OnClientAuthority for connectionId=", netMsg.conn.connectionId, " netId: ", s_ClientAuthorityMessage.netId })); } if (s_NetworkScene.GetNetworkIdentity(s_ClientAuthorityMessage.netId, out identity)) { identity.HandleClientAuthority(s_ClientAuthorityMessage.authority); } }