/// <summary> /// Load the campus game data. /// </summary> /// <param name="gameData">Campus game data.</param> protected override void LoadData(CampusData gameData) { var gridMeshArgs = new GridMeshArgs() { GridSquareSize = Constant.GridSize, GridStepSize = Constant.GridStepSize, CountX = gameData.Terrain.GridCountX, CountZ = gameData.Terrain.GridCountZ, CountY = gameData.Terrain.GridCountY, StartingHeight = gameData.Terrain.StartingHeight, GridMaterial = gameData.Terrain.TerrainMaterial, SkirtPrefab = gameData.Terrain.TerrainSkirt, }; GridMesh terrain; CampusFactory.GenerateTerrain(transform, gridMeshArgs, out terrain); Terrain = terrain; Buildings = new CampusBuildings(terrain); Paths = new CampusPaths(terrain); Game.State.RegisterController(GameState.SelectingTerrain, new SelectingTerrainController(terrain)); Game.State.RegisterController(GameState.EditingTerrain, new EditingTerrainController(terrain)); Game.State.RegisterController(GameState.PlacingConstruction, new PlacingConstructionController(terrain)); Game.State.RegisterController(GameState.SelectingPath, new SelectingPathController(terrain)); Game.State.RegisterController(GameState.PlacingPath, new PlacingPathController(terrain)); var footprintCreatorObject = new GameObject("FootprintCreator"); using (var footprintCreator = footprintCreatorObject.AddComponent <FootprintCreator>()) { // Load the buildings foreach (var buildingData in gameData.Buildings) { buildingData.Footprint = footprintCreator.CalculateFootprint(buildingData.Mesh, Constant.GridSize); _buildingRegistry[buildingData.Name] = buildingData; } } }
/// <summary> /// Instantiates the campus terrain game object. /// </summary> /// <param name="parent">Parent of the terrain.</param> /// <param name="args">GridMesh arguments to generate a terrain.</param> /// <param name="mesh">Returns the grid mesh that manages the terrain.</param> /// <returns>The terrain game object.</returns> public static GameObject GenerateTerrain(Transform parent, GridMeshArgs args, out GridMesh mesh) { var terrainObject = new GameObject("Campus Terrain"); terrainObject.transform.SetParent(parent, false); var filter = terrainObject.AddComponent <MeshFilter>(); var collider = terrainObject.AddComponent <MeshCollider>(); var renderer = terrainObject.AddComponent <MeshRenderer>(); var selectable = terrainObject.AddComponent <SelectableTerrain>(); filter.mesh = new Mesh(); filter.mesh.name = "grid-mesh"; renderer.receiveShadows = true; mesh = new GridMesh(filter.mesh, collider, renderer, args); selectable.Terrain = mesh; mesh.Selectable = selectable; return(terrainObject); }