static private GetPrefab ( |
||
assetId | ||
prefab | ||
return | bool |
// ------------------------ NetworkScene pass-throughs --------------------- static internal string GetStringForAssetId(NetworkHash128 assetId) { GameObject prefab; if (NetworkScene.GetPrefab(assetId, out prefab)) { return(prefab.name); } SpawnDelegate handler; if (NetworkScene.GetSpawnHandler(assetId, out handler)) { return(handler.GetMethodName()); } SpawnExDelegate exHandler; if (NetworkScene.GetSpawnHandler(assetId, out exHandler)) { return(exHandler.GetMethodName()); } return("unknown"); }
internal static string GetStringForAssetId(NetworkHash128 assetId) { if (NetworkScene.GetPrefab(assetId, out GameObject prefab)) { return(prefab.name); } if (NetworkScene.GetSpawnHandler(assetId, out SpawnDelegate handler)) { return(handler.Method.Name); } return("unknown"); }
internal static string GetStringForAssetId(NetworkHash128 assetId) { GameObject obj2; SpawnDelegate delegate2; if (NetworkScene.GetPrefab(assetId, out obj2)) { return(obj2.name); } if (NetworkScene.GetSpawnHandler(assetId, out delegate2)) { return(delegate2.GetMethodName()); } return("unknown"); }
internal static string GetStringForAssetId(NetworkHash128 assetId) { GameObject gameObject; if (NetworkScene.GetPrefab(assetId, out gameObject)) { return(gameObject.name); } SpawnDelegate spawnDelegate; if (NetworkScene.GetSpawnHandler(assetId, out spawnDelegate)) { return(spawnDelegate.Method.Name); } return("unknown"); }
internal static string GetStringForAssetId(NetworkHash128 assetId) { GameObject gameObject; string result; SpawnDelegate func; if (NetworkScene.GetPrefab(assetId, out gameObject)) { result = gameObject.name; } else if (NetworkScene.GetSpawnHandler(assetId, out func)) { result = func.GetMethodName(); } else { result = "unknown"; } return(result); }
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 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); } }
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectSpawnMessage>(s_ObjectSpawnMessage); if (!s_ObjectSpawnMessage.assetId.IsValid()) { if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + s_ObjectSpawnMessage.netId + " has invalid asset Id"); } } else { NetworkIdentity component; if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", s_ObjectSpawnMessage.netId, " asset ID:", s_ObjectSpawnMessage.assetId, " pos:", s_ObjectSpawnMessage.position, "]" })); } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, 3, GetStringForAssetId(s_ObjectSpawnMessage.assetId), 1); if (s_NetworkScene.GetNetworkIdentity(s_ObjectSpawnMessage.netId, out component)) { ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, null); } else { GameObject obj2; if (NetworkScene.GetPrefab(s_ObjectSpawnMessage.assetId, out obj2)) { GameObject newGameObject = UnityEngine.Object.Instantiate <GameObject>(obj2, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.rotation); if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", s_ObjectSpawnMessage.netId, " asset ID:", s_ObjectSpawnMessage.assetId, " pos:", s_ObjectSpawnMessage.position, " rotation: ", s_ObjectSpawnMessage.rotation, "]" })); } component = newGameObject.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity"); } } else { component.Reset(); ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, newGameObject); } } else { SpawnDelegate delegate2; if (NetworkScene.GetSpawnHandler(s_ObjectSpawnMessage.assetId, out delegate2)) { GameObject obj4 = delegate2(s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.assetId); if (obj4 == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + s_ObjectSpawnMessage.assetId + " returned null"); } } else { component = obj4.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + s_ObjectSpawnMessage.assetId + " does not have a network identity"); } } else { component.Reset(); component.SetDynamicAssetId(s_ObjectSpawnMessage.assetId); ApplySpawnPayload(component, s_ObjectSpawnMessage.position, s_ObjectSpawnMessage.payload, s_ObjectSpawnMessage.netId, obj4); } } } else if (LogFilter.logError) { Debug.LogError(string.Concat(new object[] { "Failed to spawn server object, assetId=", s_ObjectSpawnMessage.assetId, " netId=", s_ObjectSpawnMessage.netId })); } } } } }
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectSpawnMessage>(ClientScene.s_ObjectSpawnMessage); if (!ClientScene.s_ObjectSpawnMessage.assetId.IsValid()) { if (!LogFilter.logError) { return; } Debug.LogError((object)("OnObjSpawn netId: " + (object)ClientScene.s_ObjectSpawnMessage.netId + " has invalid asset Id")); } else { if (LogFilter.logDebug) { Debug.Log((object)("Client spawn handler instantiating [netId:" + (object)ClientScene.s_ObjectSpawnMessage.netId + " asset ID:" + (object)ClientScene.s_ObjectSpawnMessage.assetId + " pos:" + (object)ClientScene.s_ObjectSpawnMessage.position + "]")); } NetworkDetailStats.IncrementStat(NetworkDetailStats.NetworkDirection.Incoming, (short)3, ClientScene.GetStringForAssetId(ClientScene.s_ObjectSpawnMessage.assetId), 1); NetworkIdentity uv; if (ClientScene.s_NetworkScene.GetNetworkIdentity(ClientScene.s_ObjectSpawnMessage.netId, out uv)) { ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, (GameObject)null); } else { GameObject prefab; if (NetworkScene.GetPrefab(ClientScene.s_ObjectSpawnMessage.assetId, out prefab)) { GameObject newGameObject = (GameObject)Object.Instantiate((Object)prefab, ClientScene.s_ObjectSpawnMessage.position, Quaternion.identity); uv = newGameObject.GetComponent <NetworkIdentity>(); if ((Object)uv == (Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)("Client object spawned for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity")); } else { ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, newGameObject); } } else { SpawnDelegate handler; if (NetworkScene.GetSpawnHandler(ClientScene.s_ObjectSpawnMessage.assetId, out handler)) { GameObject newGameObject = handler(ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.assetId); if ((Object)newGameObject == (Object)null) { if (!LogFilter.logWarn) { return; } Debug.LogWarning((object)("Client spawn handler for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " returned null")); } else { uv = newGameObject.GetComponent <NetworkIdentity>(); if ((Object)uv == (Object)null) { if (!LogFilter.logError) { return; } Debug.LogError((object)("Client object spawned for " + (object)ClientScene.s_ObjectSpawnMessage.assetId + " does not have a network identity")); } else { uv.SetDynamicAssetId(ClientScene.s_ObjectSpawnMessage.assetId); ClientScene.ApplySpawnPayload(uv, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, newGameObject); } } } else { if (!LogFilter.logError) { return; } Debug.LogError((object)("Failed to spawn server object, assetId=" + (object)ClientScene.s_ObjectSpawnMessage.assetId + " netId=" + (object)ClientScene.s_ObjectSpawnMessage.netId)); } } } } }
private static void OnObjectSpawn(NetworkMessage netMsg) { netMsg.ReadMessage <ObjectSpawnMessage>(ClientScene.s_ObjectSpawnMessage); if (!ClientScene.s_ObjectSpawnMessage.assetId.IsValid()) { if (LogFilter.logError) { Debug.LogError("OnObjSpawn netId: " + ClientScene.s_ObjectSpawnMessage.netId + " has invalid asset Id"); } } else { if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", ClientScene.s_ObjectSpawnMessage.netId, " asset ID:", ClientScene.s_ObjectSpawnMessage.assetId, " pos:", ClientScene.s_ObjectSpawnMessage.position, "]" })); } NetworkIdentity component; GameObject original; SpawnDelegate spawnDelegate; if (ClientScene.s_NetworkScene.GetNetworkIdentity(ClientScene.s_ObjectSpawnMessage.netId, out component)) { ClientScene.ApplySpawnPayload(component, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, null); } else if (NetworkScene.GetPrefab(ClientScene.s_ObjectSpawnMessage.assetId, out original)) { GameObject gameObject = Object.Instantiate <GameObject>(original, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.rotation); if (LogFilter.logDebug) { Debug.Log(string.Concat(new object[] { "Client spawn handler instantiating [netId:", ClientScene.s_ObjectSpawnMessage.netId, " asset ID:", ClientScene.s_ObjectSpawnMessage.assetId, " pos:", ClientScene.s_ObjectSpawnMessage.position, " rotation: ", ClientScene.s_ObjectSpawnMessage.rotation, "]" })); } component = gameObject.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + ClientScene.s_ObjectSpawnMessage.assetId + " does not have a NetworkIdentity"); } } else { component.Reset(); ClientScene.ApplySpawnPayload(component, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, gameObject); } } else if (NetworkScene.GetSpawnHandler(ClientScene.s_ObjectSpawnMessage.assetId, out spawnDelegate)) { GameObject gameObject2 = spawnDelegate(ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.assetId); if (gameObject2 == null) { if (LogFilter.logWarn) { Debug.LogWarning("Client spawn handler for " + ClientScene.s_ObjectSpawnMessage.assetId + " returned null"); } } else { component = gameObject2.GetComponent <NetworkIdentity>(); if (component == null) { if (LogFilter.logError) { Debug.LogError("Client object spawned for " + ClientScene.s_ObjectSpawnMessage.assetId + " does not have a network identity"); } } else { component.Reset(); component.SetDynamicAssetId(ClientScene.s_ObjectSpawnMessage.assetId); ClientScene.ApplySpawnPayload(component, ClientScene.s_ObjectSpawnMessage.position, ClientScene.s_ObjectSpawnMessage.payload, ClientScene.s_ObjectSpawnMessage.netId, gameObject2); } } } else if (LogFilter.logError) { Debug.LogError(string.Concat(new object[] { "Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=", ClientScene.s_ObjectSpawnMessage.assetId, " netId=", ClientScene.s_ObjectSpawnMessage.netId })); } } }