Exemplo n.º 1
0
        public void UpdateHeatMapVisual()
        {
            Vector3[] vertices;
            Vector2[] uv;
            int[]     triangles;

            MeshUtils.CreateEmptyMeshArrays(grid.GetWidth() * grid.GetHeight(), out vertices, out uv, out triangles);

            for (int x = 0; x < grid.GetWidth(); x++)
            {
                for (int y = 0; y < grid.GetHeight(); y++)
                {
                    int     index               = x * grid.GetHeight() + y;
                    Vector3 baseSize            = new Vector3(1, 1) * grid.GetCellSize();
                    int     gridValue           = grid.GetValue(x, y);
                    int     maxGridValue        = 100;
                    float   gridValueNormalized = Mathf.Clamp01((float)gridValue / maxGridValue);
                    Vector2 gridCellUV          = new Vector2(gridValueNormalized, 0f);
                    MeshUtils.AddToMeshArrays(vertices, uv, triangles, index, grid.GetWorldPosition(x, y) + baseSize * .5f, 0f, baseSize, gridCellUV, gridCellUV);
                }
            }

            mesh.vertices  = vertices;
            mesh.uv        = uv;
            mesh.triangles = triangles;
        }
Exemplo n.º 2
0
        private void UpdateVisual()
        {
            // UNDONE: We should check if the current visuals are still inside the camera.
            // If they are inside the camera view, we can leave them as is.
            // if they are not inside the camera view, we can eliminate them.
            //
            // We should only draw clusters that are inside the camera view.


            MeshUtils.CreateEmptyMeshArrays(_grid.GetWidth() * _grid.GetHeight(), out var vertices, out var uv,
                                            out var triangles);

            for (var x = 0; x < _grid.GetWidth(); x++)
            {
                for (var y = 0; y < _grid.GetHeight(); y++)
                {
                    var index    = x * _grid.GetHeight() + y;
                    var quadSize = new Vector3(1, 1) * _grid.GetCellSize();

                    var gridNode = _grid.GetGridObject(x, y, _currentDepthIndex);


                    var uv00 = new Vector2(0, 0);
                    var uv11 = new Vector2(0.5f, 0.5f);

                    if (!gridNode.IsWalkable())
                    {
                        uv00 = new Vector2(.5f, .5f);
                        uv11 = new Vector2(1f, 1f);
                    }

                    MeshUtils.AddToMeshArrays(vertices, uv, triangles, index, _grid.GetWorldPosition(x, y) + quadSize * .0f,
                                              0f, quadSize, uv00, uv11);
                }
            }

            _mesh.vertices  = vertices;
            _mesh.uv        = uv;
            _mesh.triangles = triangles;
            Debug.Log(_mesh.vertexCount);
        }