Beispiel #1
0
        public void ShowElevation(GameObject plane, Map2 map)
        {
            var textureWidth = (int)Map1.Width * _textureScale;
            var textureHeight = (int)Map1.Height * _textureScale;

            var texture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGB565, true);
            texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray());

            //绘制陆地
            var lands = map.Graph.centers.Where(p => !p.ocean);
            foreach (var land in lands)
                texture.FillPolygon(
                    land.corners.Select(p => p.point * _textureScale).ToArray(),
					BiomeProperties.Colors[Biome.Beach] * land.elevation);

            //绘制边缘
            var lines = map.Graph.edges.Where(p => p.v0 != null).Select(p => new[]
            {
                p.v0.point.x, p.v0.point.y,
                p.v1.point.x, p.v1.point.y
            }).ToArray();

            foreach (var line in lines)
                DrawLine(texture, line[0], line[1], line[2], line[3], Color.black);
            //绘制中心点
            var points = map.Graph.centers.Select(p => p.point).ToList();
            foreach (var p in points)
                texture.SetPixel((int)(p.x * _textureScale), (int)(p.y * _textureScale), Color.red);

            texture.Apply();

            plane.GetComponent<Renderer>().material.mainTexture = texture;
        }
Beispiel #2
0
        public void DrawBiome(GameObject plane, Map2 map)
        {
            var textureWidth  = (int)map.Width * _textureScale;
            var textureHeight = (int)map.Height * _textureScale;

            var texture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGB565, true);

            texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray());

            //绘制陆地
            var lands = map.Graph.centers.Where(p => !p.ocean);

            foreach (var land in lands)
            {
                texture.FillPolygon(
                    land.corners.Select(p => p.point * _textureScale).ToArray(),
                    BiomeProperties.Colors[land.biome]);
            }
            //绘制湖泊
            var lakeConors = map.Graph.centers.Where(p => p.water && !p.ocean).Select(p => p.corners);

            foreach (var conors in lakeConors)
            {
                texture.FillPolygon(
                    conors.Select(p => p.point * _textureScale).ToArray(),
                    BiomeProperties.Colors[Biome.Lake]);
            }

            //绘制边缘
            var lines = map.Graph.edges.Where(p => p.v0 != null).Select(p => new[]
            {
                p.v0.point.x, p.v0.point.y,
                p.v1.point.x, p.v1.point.y
            }).ToArray();

            foreach (var line in lines)
            {
                DrawLine(texture, line[0], line[1], line[2], line[3], Color.black);
            }
            //绘制中心点
            var points = map.Graph.centers.Select(p => p.point).ToList();

            foreach (var p in points)
            {
                texture.SetPixel((int)(p.x * _textureScale), (int)(p.y * _textureScale), Color.red);
            }
            //绘制河流
            foreach (var line in map.Graph.edges.Where(p => p.river > 0 && !p.d0.water && !p.d1.water))
            {
                DrawLine(texture, line.v0.point.x, line.v0.point.y, line.v1.point.x, line.v1.point.y, Color.blue, 10);
            }

            texture.Apply();

            plane.GetComponent <Renderer>().material.mainTexture = texture;
        }
Beispiel #3
0
        public Texture2D AttachTexture(Map2 map)
        {
            var textureWidth  = (int)map.Width * _textureScale;
            var textureHeight = (int)map.Height * _textureScale;

            var texture = new Texture2D(textureWidth, textureHeight, TextureFormat.RGB565, true);

            texture.SetPixels(Enumerable.Repeat(BiomeProperties.Colors[Biome.Ocean], textureWidth * textureHeight).ToArray());

            //绘制陆地
            var oceanConors = map.Graph.centers.Where(p => !p.water).Select(p => p.corners);

            foreach (var conors in oceanConors)
            {
                texture.FillPolygon(
                    conors.Select(p => p.point * _textureScale).ToArray(),
                    BiomeProperties.Colors[Biome.Beach]);
            }
            //绘制湖泊
            var lakeConors = map.Graph.centers.Where(p => p.water && !p.ocean).Select(p => p.corners);

            foreach (var conors in lakeConors)
            {
                texture.FillPolygon(
                    conors.Select(p => p.point * _textureScale).ToArray(),
                    BiomeProperties.Colors[Biome.Lake]);
            }

            //绘制边缘
            var lines = map.Graph.edges.Where(p => p.v0 != null).Select(p => new[]
            {
                p.v0.point.x, p.v0.point.y,
                p.v1.point.x, p.v1.point.y
            }).ToArray();

            foreach (var line in lines)
            {
                DrawLine(texture, line[0], line[1], line[2], line[3], Color.black);
            }
            //绘制中心点
            var points = map.Graph.centers.Select(p => p.point).ToList();

            foreach (var p in points)
            {
                texture.SetPixel((int)(p.x * _textureScale), (int)(p.y * _textureScale), Color.red);
            }

            texture.Apply();

            return(texture);
        }
Beispiel #4
0
        public void AttachTexture(GameObject plane, Map2 map)
        {
            var texture = AttachTexture(map);

            plane.GetComponent <Renderer>().material.mainTexture = texture;
        }