public static void ClearSpawners() { NetworkScene.ClearSpawners(); }
static void OnSpawnPrefab(NetworkMessage netMsg) { SpawnPrefabMessage msg = new SpawnPrefabMessage(); netMsg.ReadMessage(msg); if (msg.assetId == Guid.Empty) { Debug.LogError("OnObjSpawn netId: " + msg.netId + " has invalid asset Id"); return; } if (LogFilter.Debug) { Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + "]"); } NetworkIdentity localNetworkIdentity; if (s_NetworkScene.GetNetworkIdentity(msg.netId, out localNetworkIdentity)) { // this object already exists (was in the scene), just apply the update to existing object localNetworkIdentity.Reset(); ApplySpawnPayload(localNetworkIdentity, msg.position, msg.payload, msg.netId, null); return; } GameObject prefab; SpawnDelegate handler; if (NetworkScene.GetPrefab(msg.assetId, out prefab)) { var obj = (GameObject)Object.Instantiate(prefab, msg.position, msg.rotation); if (LogFilter.Debug) { Debug.Log("Client spawn handler instantiating [netId:" + msg.netId + " asset ID:" + msg.assetId + " pos:" + msg.position + " rotation: " + msg.rotation + "]"); } localNetworkIdentity = obj.GetComponent <NetworkIdentity>(); if (localNetworkIdentity == null) { Debug.LogError("Client object spawned for " + msg.assetId + " does not have a NetworkIdentity"); return; } localNetworkIdentity.Reset(); ApplySpawnPayload(localNetworkIdentity, msg.position, msg.payload, msg.netId, obj); } // lookup registered factory for type: else if (NetworkScene.GetSpawnHandler(msg.assetId, out handler)) { GameObject obj = handler(msg.position, msg.assetId); if (obj == null) { Debug.LogWarning("Client spawn handler for " + msg.assetId + " returned null"); return; } localNetworkIdentity = obj.GetComponent <NetworkIdentity>(); if (localNetworkIdentity == null) { Debug.LogError("Client object spawned for " + msg.assetId + " does not have a network identity"); return; } localNetworkIdentity.Reset(); localNetworkIdentity.SetDynamicAssetId(msg.assetId); ApplySpawnPayload(localNetworkIdentity, msg.position, msg.payload, msg.netId, obj); } else { Debug.LogError("Failed to spawn server object, did you forget to add it to the NetworkManager? assetId=" + msg.assetId + " netId=" + msg.netId); } }
public static void UnregisterSpawnHandler(Guid assetId) { NetworkScene.UnregisterSpawnHandler(assetId); }
public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) { NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler); }
public static void UnregisterPrefab(GameObject prefab) { NetworkScene.UnregisterPrefab(prefab); }
public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler) { NetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler); }
// ------------------------ NetworkScene pass-throughs --------------------- // this assigns the newAssetId to the prefab. This is for registering dynamically created game objects for already know assetIds. public static void RegisterPrefab(GameObject prefab, Guid newAssetId) { NetworkScene.RegisterPrefab(prefab, newAssetId); }