public override GameObject Generate()
        {
            int           scale            = configuration.Scale;
            Map           map              = configuration.MapGenerator.Generate();
            Material      floorMaterial    = configuration.Material;
            IHeightMap    heightMap        = configuration.HeightMapModule.GetHeightMap();
            OutlineModule outlinePrefabber = configuration.OutlineModule;

            GameObject cave = new GameObject("Cave");

            Map[,] mapChunks = MapSplitter.Subdivide(map);
            mapChunks.ForEach((x, y) =>
            {
                Coord index = new Coord(x, y);

                WallGrid grid             = MapConverter.MapToWallGrid(mapChunks[x, y], scale, index);
                List <Vector3[]> outlines = meshGenerator.BuildOutlines(grid);
                CaveMeshes caveMeshes     = BuildCaveMesh(grid, heightMap);
                Sector sector             = BuildSector(caveMeshes, index, cave, floorMaterial);
                GameObject rockAnchor     = BuildRockAnchor(sector.GameObject, index);
                BuildOutline(outlines, outlinePrefabber, rockAnchor.transform);
            });

            return(cave);
        }
예제 #2
0
        void PopulateSamples()
        {
            Module[] modules = AssetDatabase.FindAssets("Sample t:Module")
                               .Select(AssetDatabase.GUIDToAssetPath)
                               .Select(AssetDatabase.LoadAssetAtPath <Module>)
                               .ToArray();

            MapGenModule    mapGenerator = modules.FirstOrDefault(m => m.name == "SampleMapGenerator") as MapGenModule;
            HeightMapModule floor        = modules.FirstOrDefault(m => m.name == "SampleFloorHeightMap") as HeightMapModule;
            HeightMapModule ceiling      = modules.FirstOrDefault(m => m.name == "SampleCeilingHeightMap") as HeightMapModule;
            OutlineModule   outline      = modules.FirstOrDefault(m => m.name == "SampleOutline") as OutlineModule;

            Undo.RecordObject(this, "Insert sample modules");
            var missingModules = new StringBuilder();

            if (mapGenerator != null)
            {
                threeTierCaveConfig.MapGenerator = mapGenerator;
                rockCaveConfig.MapGenerator      = mapGenerator;
            }
            else
            {
                missingModules.AppendLine("Sample map generator module not found.");
            }

            if (floor != null)
            {
                threeTierCaveConfig.FloorHeightMapModule = floor;
                rockCaveConfig.HeightMapModule           = floor;
            }
            else
            {
                missingModules.AppendLine("Sample height map module for floor not found.");
            }

            if (ceiling != null)
            {
                threeTierCaveConfig.CeilingHeightMapModule = ceiling;
            }
            else
            {
                missingModules.AppendLine("Sample height map module for ceiling not found.");
            }

            if (outline != null)
            {
                rockCaveConfig.OutlineModule = outline;
            }
            else
            {
                missingModules.AppendLine("Sample outline module not found.");
            }

            if (missingModules.Length > 0)
            {
                Debug.LogError(missingModules.ToString());
            }
        }
 void BuildOutline(IEnumerable <Vector3[]> outlineVertices, OutlineModule prefabber, Transform parent)
 {
     prefabber.ProcessOutlines(outlineVertices.Select(vertices => new Outline(vertices)), parent);
 }