public static bool TryGetWorldLayerCount(MapBuilderSettings mapBuilderSettings, string worldSize, out int worldLayerCount) { switch (worldSize) { case SmallLevelFlag: worldLayerCount = 4; break; case LargeLevelFlag: worldLayerCount = mapBuilderSettings.LargeWorldLayerCount; break; default: return(int.TryParse(worldSize, out worldLayerCount)); } return(true); }
// Get the world size from the config, and use it to generate the correct-sized level public static IEnumerator GenerateMap( MapBuilderSettings mapBuilderSettings, Transform workerTransform, Connection connection, string workerType, ILogDispatcher logDispatcher, WorkerConnectorBase worker) { var worldSize = GetWorldSizeFlag(connection); if (!TryGetWorldLayerCount(mapBuilderSettings, worldSize, out var worldLayerCount)) { logDispatcher.HandleLog(LogType.Error, new LogEvent("Invalid world_size worker flag. Make sure that it is either small or large,") .WithField("world_size", worldSize)); yield break; } var levelInstance = worker.LevelInstance = new GameObject(); levelInstance.name = $"FPS-Level_{worldLayerCount}({workerType})"; levelInstance.transform.position = workerTransform.position; levelInstance.transform.rotation = workerTransform.rotation; var mapBuilder = new MapBuilder(mapBuilderSettings, levelInstance); var volumesPrefab = mapBuilderSettings.WorldTileVolumes == null ? null : Object.Instantiate(mapBuilderSettings.WorldTileVolumes); yield return(mapBuilder.CleanAndBuild(worldLayerCount)); if (volumesPrefab != null) { UnityObjectDestroyer.Destroy(volumesPrefab); } }
public MapBuilder(MapBuilderSettings mapBuilderSettings, GameObject gameObject) { this.mapBuilderSettings = mapBuilderSettings; this.gameObject = gameObject; }
public static Vector3 GetWorldDimensions(MapBuilderSettings mapBuilderSettings, int worldLayerCount) { var dimensions = worldLayerCount * mapBuilderSettings.UnitsPerTile * 2 + mapBuilderSettings.UnitsPerBlock; return(new Vector3(dimensions, 100f, dimensions)); }