Esempio n. 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);
            }
        }
Esempio n. 2
0
        public static void OpenWindow(SerializedObject maze,
                                      IEnumerable <Coord> cells, IEnumerable <MazeLink> links, IEnumerable <CellTag> tags,
                                      Action <List <Coord>, List <MazeLink>, List <CellTag> > updateMaze)
        {
            Assert.IsNotNull(maze);
            var window = GetWindow <MazeWindow>("Maze Editor", true);

            if (EditorPrefs.HasKey(EDITOR_PREFS_SCALE_KEY))
            {
                window.scale = EditorPrefs.GetInt(EDITOR_PREFS_SCALE_KEY);
            }
            window.position         = window.ComputeWindowPosition();
            window.updateMaze       = updateMaze;
            window.serializedMaze   = maze;
            window.serializedLength = maze.FindProperty("length");
            window.serializedWidth  = maze.FindProperty("width");

            window.selectedCells = cells.ToList();
            window.selectedLinks = links.ToList();

            window.cellTags = new Dictionary <Coord, List <KeyValuePair <string, string> > >();
            foreach (var tag in tags)
            {
                if (!window.cellTags.ContainsKey(tag.Cell))
                {
                    window.cellTags.Add(tag.Cell, tag.MetaData.ToList());
                }
                else
                {
                    Debug.LogWarningFormat("Removing duplicate cell {0} with metadata: {1}", tag.Cell, tag.MetaData);
                }
            }

            window.properties = AtlasEditorState.Load();

            window.CreateMazeTexture();
        }