Exemplo n.º 1
0
        public static void ServerSpawn(NetworkEntity toSpawn, NetworkSpawnArgs args)
        {
            Debug.Log("Spawning object with no ownership");

            List <int>        currentIds = objectsManager.spawnedEntities.Keys.Select(key => key.id).ToList();
            NetworkInstanceId id         = new NetworkInstanceId(Identification.GetUniqueIdentifierFromList(currentIds));

            toSpawn.Initialize(-1, id, toSpawn.definitionName, args);

            objectsManager.spawnedEntities.Add(id, toSpawn);

            SpawnCommand spawnCommand = toSpawn.GetSpawnRequest();

            pendingSpawnCommands.Add(spawnCommand);
        }
Exemplo n.º 2
0
        private static void SpawnObjects()
        {
            List <SpawnCommand> spawnCommands = new List <SpawnCommand>();

            spawnCommands.AddRange(pendingSpawnRequests);
            pendingSpawnRequests.RemoveRange(0, pendingSpawnRequests.Count);

            foreach (SpawnCommand command in spawnCommands)
            {
                if (command == null || objectsManager.spawnedEntities.ContainsKey(command.id))
                {
                    continue;
                }

                NetworkEntity newEntity = objectsManager.entityDefinitions.Where(entity => entity.name == command.name).Single().entity;

                NetworkEntity spawnedEntity = GameObject.Instantiate(newEntity, command.position.Value, command.rotation.Value);
                spawnedEntity.Initialize(command.ownerId, command.id, command.name, command.arguments);
                spawnedEntity.ReceiveSyncVarUpdate(command.syncVarValues);

                objectsManager.spawnedEntities.Add(spawnedEntity.instanceId, spawnedEntity);
            }
        }