Пример #1
0
        public override void DrawPreview(Rect previewArea)
        {
            if (visualize && Event.current.type == EventType.Repaint)
            {
                var  mazeGen = (MazeGenModule)target;
                Maze maze;
                try
                {
                    maze = mazeGen.GetMaze();
                }
                catch (InvalidOperationException)
                {
                    // Maze generator is not properly configured yet: suppress error to avoid spamming the console,
                    // and exit the draw method.
                    return;
                }
                if (editorState == null)
                {
                    editorState = AtlasEditorState.Load();
                }
                MazeTexture mazeTexture = mazeDrawer.CreateTexture(maze, editorState.TagTable);

                int numCellsX = mazeTexture.NumCellsX;
                int numCellsY = mazeTexture.NumCellsY;

                float originalCellWidth  = previewArea.width / numCellsX;
                float originalCellHeight = previewArea.height / numCellsY;

                // we want to make cells have equal height and width
                float cellSize = Math.Min(originalCellWidth, originalCellHeight);

                float newWidth  = numCellsX * cellSize;
                float newHeight = numCellsY * cellSize;

                float xOffset = (previewArea.width - newWidth) / 2;
                float yOffset = (previewArea.height - newHeight) / 2;

                previewArea.width  = newWidth;
                previewArea.height = newHeight;
                previewArea.x     += xOffset;
                previewArea.y     += yOffset;

                mazeTexture.Draw(previewArea);
            }
        }
Пример #2
0
        void CreateMazeTexture()
        {
            Maze maze = new Maze(EnumerateGridCoordinates(), Enumerable.Empty <MazeLink>());

            mazeTexture = mazeDrawer.CreateTexture(maze, properties.TagTable);
            foreach (Coord cell in selectedCells)
            {
                mazeTexture.ColorCell(cell, SELECTED_COLOR);
            }
            foreach (MazeLink link in selectedLinks)
            {
                mazeTexture.ColorLink(link, SELECTED_COLOR);
            }
            if (properties.TagTable != null)
            {
                foreach (var tagListPair in cellTags)
                {
                    DrawTags(tagListPair.Key);
                }
            }
            mazeTexture.Apply();
        }
Пример #3
0
        public MazeTexture CreateTexture(Maze maze, TagDrawTable tagTable)
        {
            if (maze == null)
            {
                throw new ArgumentNullException("maze");
            }

            Coord numCells    = CalculateCells(maze.GetCells());
            var   mazeTexture = new MazeTexture(numCells.x, numCells.y);

            mazeTexture.SetBackgroundColor(BACKGROUND_COLOR);
            Coord[] cells      = maze.GetCells();
            Coord   bottomLeft = GetBottomLeft(cells);

            foreach (Coord actualCell in cells)
            {
                mazeTexture.ColorCell(actualCell - bottomLeft, CELL_COLOR);
            }
            foreach (MazeLink link in maze.GetLinks())
            {
                var shiftedLink = new MazeLink(link.CellA - bottomLeft, link.CellB - bottomLeft);
                mazeTexture.ColorLink(shiftedLink, CELL_COLOR);
            }
            if (tagTable != null)
            {
                foreach (CellTag tag in maze.GetTags())
                {
                    Coord    shiftedCell = tag.Cell - bottomLeft;
                    MetaData metaData    = tag.MetaData;
                    foreach (var pair in metaData)
                    {
                        TagDrawer drawer = tagTable[pair.Key];
                        mazeTexture.ColorTag(shiftedCell, drawer.Coords, drawer.Color);
                    }
                }
            }
            mazeTexture.Apply();
            return(mazeTexture);
        }