Esempio n. 1
0
 public static void ClearSpawners()
 {
     NetworkScene.ClearSpawners();
 }
Esempio n. 2
0
        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);
            }
        }
Esempio n. 3
0
 public static void UnregisterSpawnHandler(Guid assetId)
 {
     NetworkScene.UnregisterSpawnHandler(assetId);
 }
Esempio n. 4
0
 public static void RegisterSpawnHandler(Guid assetId, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterSpawnHandler(assetId, spawnHandler, unspawnHandler);
 }
Esempio n. 5
0
 public static void UnregisterPrefab(GameObject prefab)
 {
     NetworkScene.UnregisterPrefab(prefab);
 }
Esempio n. 6
0
 public static void RegisterPrefab(GameObject prefab, SpawnDelegate spawnHandler, UnSpawnDelegate unspawnHandler)
 {
     NetworkScene.RegisterPrefab(prefab, spawnHandler, unspawnHandler);
 }
Esempio n. 7
0
 // ------------------------ 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);
 }