public override void DisplayMap(WorldMapData mapData)
        {
            if (!enabled)
            {
                return;
            }

            _mapData   = mapData;
            _heightMap = _mapData.GetLayer <HeightMapLayerData>().heightMap;

            ClearChunks();

            //Chunks
            var chunksWide = Mathf.CeilToInt(mapData.width / (float)chunkWidth);
            var chunksHigh = Mathf.CeilToInt(mapData.height / (float)chunkHeight);

            for (var chunkY = 0; chunkY < chunksHigh; chunkY++)
            {
                for (var chunkX = 0; chunkX < chunksWide; chunkX++)
                {
                    //Create the mesh
                    var startX    = chunkX * chunkWidth;
                    var startY    = chunkY * chunkHeight;
                    var chunkView = GetChunk(new Vector2Int(chunkX, chunkY));
                    chunkView.transform.localPosition = new Vector3(0, 0, 0);
                    var mesh = HexMeshUtility.GenerateHexagonMesh(radius, border, startX, startY, chunkWidth, chunkHeight, mapData.width, mapData.height, _heightMap, GetColor, GetElevation);
                    chunkView.SetMesh(mesh);
                }
            }
        }
        public override Vector3 MapToWorldPosition(Vector2Int point)
        {
            var innerRadius = HexMeshUtility.GetInnerRadius(radius);
            var xOffset     = point.x + point.y * 0.5f - (int)(point.y / 2);
            var pt          = new Vector3
            {
                x = xOffset * innerRadius * 2,
                y = _mapData == null || _heightMap == null ? 0 : GetElevation(_heightMap[point.y * _mapData.width + point.x]),
                z = point.y * radius * 1.5f
            };

            return(pt);
        }
Esempio n. 3
0
        public HexMeshData(float radius, float border = 0.2f)
        {
            this._border = Mathf.Clamp01(border);

            _outerRadius = radius;
            _innerRadius = HexMeshUtility.GetInnerRadius(_outerRadius);
            _vertices    = new List <Vector3>();
            _triangles   = new List <int>();
            _colors      = new List <Color>();
            _uv          = new List <Vector2>();
            _corners     = new [] {
                new Vector3(0f, 0f, _outerRadius),
                new Vector3(_innerRadius, 0f, 0.5f * _outerRadius),
                new Vector3(_innerRadius, 0f, -0.5f * _outerRadius),
                new Vector3(0f, 0f, -_outerRadius),
                new Vector3(-_innerRadius, 0f, -0.5f * _outerRadius),
                new Vector3(-_innerRadius, 0f, 0.5f * _outerRadius),
                new Vector3(0f, 0f, _outerRadius)
            };
        }