Example #1
0
        internal async Task DrawMap(TileDetail[,,] tileDetails)
        {
            int xNum = tileDetails.GetLength(0);
            int yNum = tileDetails.GetLength(1);
            int zNum = tileDetails.GetLength(2);

            tileUnits = new TileUnit[xNum, yNum, zNum];

            for (int x = 0; x < xNum; ++x)
            {
                for (int y = 0; y < yNum; ++y)
                {
                    for (int z = 0; z < zNum; ++z)
                    {
                        TileDetail detail = tileDetails[x, y, z];
                        if (detail.tileType != eTileType.None)
                        {
                            GameObject go       = GameObject.CreatePrimitive(PrimitiveType.Cube);
                            TileUnit   tileUnit = go.AddComponent <TileUnit>();
                            tileUnit.TileType = detail.tileType;
                            tileUnit.Position = new Vector3(x, y, z);
                            tileUnit.SetMaterial(await GetMaterialAsync(detail.tileType));
                        }
                    }
                }
            }
        }
Example #2
0
        public TileDetail[,,] Generate()
        {
            SurfaceGenerate mapGenerate = new SurfaceGenerate();

            Map2 voronioMap = new Map2((float)width, (float)length);

            voronioMap.Init();

            var terrain = ConvertToTerrain(voronioMap);

            TileDetail[,,] tileDetails = new TileDetail[width, height, length];

            Map1 geologyMap     = new Map1((float)width, (float)length, geologyPointCount);
            var  geologyTerrain = ConvertToGeology(geologyMap, geologyRefinement);

            //土
            IList <(Vector3 pos, float perlinNoise)> surfacePoints = mapGenerate.CreateSurfacePositions(width, length, refinement, offsetX, offsetY, multiplier);

            foreach (var v in surfacePoints)
            {
                if (terrain[(int)v.pos.x, (int)v.pos.z].tileType == eTileType.Ocean)
                {
                    for (int i = 0; i < altitude; ++i)
                    {
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.Ocean;
                    }

                    continue;
                }

                for (int i = 0; i < v.pos.y; ++i)
                {
                    switch (geologyTerrain[(int)v.pos.x, (int)v.pos.z].geology)
                    {
                    case eGeology.None:
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.None;
                        break;

                    case eGeology.Grass:
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.Earth;
                        break;

                    case eGeology.Desert:
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.Sand;
                        break;

                    case eGeology.RockyMountain:
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.Stone;
                        break;

                    default:
                        tileDetails[(int)v.pos.x, i, (int)v.pos.z].tileType = eTileType.Earth;
                        break;
                    }
                }
            }

            //水
            for (int i = 0; i < width; ++i)
            {
                for (int k = 0; k < length; ++k)
                {
                    if (tileDetails[i, altitude - 1, k].tileType == eTileType.None)
                    {
                        for (int j = altitude - 1; j >= 0; --j)
                        {
                            if (tileDetails[i, j, k].tileType == eTileType.None)
                            {
                                tileDetails[i, j, k].tileType = eTileType.Lake;
                            }
                        }
                    }
                }
            }

            //種樹
            IList <(Vector3 pos, float perlinNoise)> trees = mapGenerate.CreateSurfacePositions(width, length, treeRefinement, offsetX, offsetY, 1, treeWeights);

            foreach (var tree in trees)
            {
                for (int i = 0; i < height; ++i)
                {
                    if (tileDetails[(int)tree.pos.x, i, (int)tree.pos.z].tileType == eTileType.None &&
                        i > 0 &&
                        tileDetails[(int)tree.pos.x, i - 1, (int)tree.pos.z].tileType == eTileType.Earth)
                    {
                        tileDetails[(int)tree.pos.x, i, (int)tree.pos.z].tileType = eTileType.Tree;
                        break;
                    }
                }
            }

            return(tileDetails);
        }