Ejemplo n.º 1
0
    override public void InitGrid()
    {
        var grid = (FlatTriGrid <TileCell>)Grid;

        var edgeGrid = grid.MakeEdgeGrid <MazeCell>();

        var edgeMap = new PointyRhombMap(cellDimensions)
                      .WithWindow(ExampleUtils.ScreenRect)
                      .AlignMiddleCenter(edgeGrid)
                      .To3DXY();

        foreach (var point in edgeGrid)
        {
            MazeCell cell = GridBuilderUtils.Instantiate(edgePrefab);
            cell.transform.parent        = transform;
            cell.transform.localScale    = Vector3.one;
            cell.transform.localPosition = edgeMap[point];
            cell.SetOrientation(point.I, false);
            cell.name       = "M";
            edgeGrid[point] = cell;
        }

        foreach (var point in MazeAlgorithms.GenerateMazeWalls(grid))
        {
            if (edgeGrid[point] != null)
            {
                edgeGrid[point].SetOrientation(point.I, true);
            }
        }
    }
Ejemplo n.º 2
0
        private void BuildGrid()
        {
            var grid = CreateGrid();
            var map  = CreateMap();

            GridBuilderUtils.InitTileGrid(grid, map, cellPrefab, gridRoot, InitCell);
        }
Ejemplo n.º 3
0
        private void BuildGrid()
        {
            var grid = CreateGrid();
            var map  = CreateMap(grid);

            GridBuilderUtils.InitTileGrid(grid, map, cellPrefab, gridRoot, InitCell);
            GridBuilderUtils.UpdateTileGridOrientations(grid, map);
        }
Ejemplo n.º 4
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
            var gridPoint     = map[worldPosition];

            grid[gridPoint].HighlightOn = !grid[gridPoint].HighlightOn;
        }
    }
Ejemplo n.º 5
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector2    worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);
                CairoPoint gridPoint     = map[worldPosition];

                if (grid.Contains(gridPoint))
                {
                    grid[gridPoint].HighlightOn = !grid[gridPoint].HighlightOn;
                }
            }
        }
Ejemplo n.º 6
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);

            DiamondPoint rectPoint = map[worldPosition];

            if (grid.Contains(rectPoint))
            {
                grid[rectPoint].OnClick();
            }
        }
    }
Ejemplo n.º 7
0
        private void BuildGrid()
        {
            var grid = CreateGrid();
            var map  = CreateMap(grid);

            //This method is provided as a utility method
            //because grid setup is so often the same.

            //However, if you look at its implementation,
            //You will see it does not do anything magical,
            //and it is easy to use and modify the code
            //directly if you need more control.
            GridBuilderUtils.InitTileGrid(grid, map, cellPrefab, gridRoot, InitCell);
        }
Ejemplo n.º 8
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3      mousePosition = Input.mousePosition;
                Vector2      worldPosition = GridBuilderUtils.ScreenToWorld(root, mousePosition);
                FlatHexPoint hexPoint      = map[worldPosition];

                if (grid.Contains(hexPoint))
                {
                    grid[hexPoint].HighlightOn = !grid[hexPoint].HighlightOn;
                }
            }
        }
Ejemplo n.º 9
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector2 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);

                DiamondPoint point = map[worldPosition];

                if (grid.Contains(point))
                {
                    //Toggle the highlight
                    grid[point].HighlightOn = !grid[point].HighlightOn;
                }
            }
        }
Ejemplo n.º 10
0
        private void ProcessMouse()
        {
            Vector3   worldPosition = GridBuilderUtils.ScreenToWorld(uiRoot, Input.mousePosition);
            RectPoint rectPosition  = map[worldPosition];

            if (tileGrid.Contains(rectPosition))
            {
                if (blocksGrid[rectPosition] != null)
                {
                    SetHighlight(currentBlock, false);
                    currentBlock = blocksGrid[rectPosition];
                    SetHighlight(currentBlock, true);
                }
            }
        }
Ejemplo n.º 11
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
            var     bigPoint      = bigMap[worldPosition];

            if (grid.BaseGrid.Contains(bigPoint))
            {
                var bigWorldPosition   = bigMap[bigPoint];
                var smallWorldPosition = worldPosition - bigWorldPosition;
                var smallPoint         = smallMap[smallWorldPosition];

                if (grid.GetSmallGrid(bigPoint).Contains(smallPoint))
                {
                    var cell = grid[bigPoint, smallPoint];
                    cell.HighlightOn = !cell.HighlightOn;
                }
            }
        }

        if (Input.GetMouseButtonDown(1))
        {
            Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
            var     bigPoint      = bigMap[worldPosition];

            if (grid.BaseGrid.Contains(bigPoint))
            {
                var bigWorldPosition   = bigMap[bigPoint];
                var smallWorldPosition = worldPosition - bigWorldPosition;
                var smallPoint         = smallMap[smallWorldPosition];

                if (grid.GetSmallGrid(bigPoint).Contains(smallPoint))
                {
                    var point = grid.CombinePoints(bigPoint, smallPoint);

                    if (cellSelectionState == 0)
                    {
                        SelectFirstPoint(point);
                    }
                    else
                    {
                        SelectLastPoint(point);
                    }
                }
            }
        }
    }
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                var worldPosition = GridBuilderUtils.ScreenToWorld(gridRoot, Input.mousePosition);
                var gridPoint     = map[worldPosition];

                if (grid.Contains(gridPoint))
                {
                    foreach (var point in grid.GetNeighbors(gridPoint))
                    {
                        grid[point].HighlightOn = !grid[point].HighlightOn;
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3   worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);
                LinePoint gridPoint     = 1;

                for (int i = 0; i < 101; i++)
                {
                    gridPoint = voronoiMap[worldPosition];
                }

                if (grid.Contains(gridPoint))
                {
                    grid[gridPoint].HighlightOn = !grid[gridPoint].HighlightOn;
                }
            }
        }
Ejemplo n.º 14
0
    void Update()
    {
        ConnectedCorridors.Clear();
        ConnectedRooms.Clear();

        var cellAtMouse = FindCellAtMousePosition(Camera.main);

        if (cellAtMouse == null)
        {
            return;
        }

        GridBuilderUtils.GetAdjacentCorridors(gridModel, cellAtMouse.Id, ref ConnectedCorridors, ref ConnectedRooms);

        cursorCellId = cellAtMouse.Id;
        // We don't want to override the color of the cell under the mouse
        ConnectedCorridors.Remove(cursorCellId);
        ConnectedRooms.Remove(cursorCellId);
    }
Ejemplo n.º 15
0
        /// <summary>
        /// Creates a Mesh grid using the mesh data provided for each cell.
        /// </summary>
        /// <param name="mesh">Mesh to use to place the generated mesh grid.</param>
        /// <param name="width">Width of the grid.</param>
        /// <param name="height">Height of the grid.</param>
        /// <param name="prefab">Prefab to use for the cells on the grid.</param>
        /// <param name="meshData">The mesh data information to use for the cells.</param>
        /// <param name="cellDimensions">The cell's dimensions.</param>
        public static IGrid <GridPoint2, T> RectXY <T>(
            Mesh mesh,
            int width,
            int height,
            MeshData meshData,
            Vector2 cellDimensions)
        {
            var spaceMap = Map.Linear(Matrixf33.Scale(cellDimensions.To3DXY(1)));
            var center   = new Vector2(width, height) / 2 - Vector2.one * 0.5f;

            spaceMap = spaceMap.PreTranslate(-center);

            var roundMap = Map.RectRound();
            var map      = new GridMap <GridPoint2>(spaceMap, roundMap);
            var grid     = Rect <T>(width, height);

            GridBuilderUtils.InitMesh(mesh, grid, map, meshData, false, true);

            return(grid);
        }
Ejemplo n.º 16
0
        /// <summary>
        /// Creates a Pysical Grid.
        /// </summary>
        /// <param name="root">GameObject where all the cells are going to be stored.</param>
        /// <param name="width">Width of the grid.</param>
        /// <param name="height">Height of the grid.</param>
        /// <param name="prefab">Prefab to use for the cells on the grid.</param>
        /// <param name="cellDimensions">The cell's dimensions.</param>
        public static PhysicalGrid <GridPoint2, T> RectXY <T>(
            GameObject root,
            int width,
            int height,
            T prefab,
            Vector2 cellDimensions)
            where T : Component
        {
            var spaceMap = Map.Linear(Matrixf33.Scale(cellDimensions.To3DXY(1)));
            var center   = new Vector2(width, height) / 2 - Vector2.one * 0.5f;

            spaceMap = spaceMap.PreTranslate(-center);

            var grid     = Rect <T>(width, height);
            var roundMap = Map.RectRound();
            var map      = new GridMap <GridPoint2>(spaceMap, roundMap);

            GridBuilderUtils.InitTileGrid(grid, map, prefab, root, (point, cell) => { });

            //root.AddComponent<PhysicalGrid<GridPoint2, T>>();
            return(new PhysicalGrid <GridPoint2, T>(grid, map, root));
        }
Ejemplo n.º 17
0
    public void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            // If you use a different GUI system, you will probably need a
            // custom version of this function.
            // This assumes your camera is orthographic. For perspective cameras,
            // you must use a ray casting method instead.
            Vector3 worldPosition = GridBuilderUtils.ScreenToWorld(root, Input.mousePosition);

            // Calculates the grid point that corresponds to the given world coordinate.
            RectPoint point = map[worldPosition];

            // The point may in fact lie outside the grid as we defined it when we built it.
            // So we first check whether the grid contains the point...
            if (grid.Contains(point))
            {
                //... and toggle the highlight of the cell
                grid[point].HighlightOn = !grid[point].HighlightOn;
            }
        }
    }
Ejemplo n.º 18
0
        public void Update()
        {
            if (Input.GetMouseButtonDown(0))
            {
                Vector3        worldPosition = GridBuilderUtils.ScreenToWorld(Input.mousePosition);
                PointyHexPoint hexPoint      = map[worldPosition];

                if (grid.Contains(hexPoint))
                {
                    if (grid[hexPoint] != null)
                    {
                        grid[hexPoint].gameObject.SetActive(!grid[hexPoint].gameObject.activeInHierarchy);
                    }
                }
            }

            if (Input.GetKey(KeyCode.UpArrow))
            {
                cam.transform.position = cam.transform.position + Vector3.up * 10f;
            }

            if (Input.GetKey(KeyCode.DownArrow))
            {
                cam.transform.position = cam.transform.position + Vector3.down * 10f;
            }

            if (Input.GetKey(KeyCode.LeftArrow))
            {
                cam.transform.position = cam.transform.position + Vector3.left * 10f;
            }

            if (Input.GetKey(KeyCode.RightArrow))
            {
                cam.transform.position = cam.transform.position + Vector3.right * 10f;
            }
        }
Ejemplo n.º 19
0
 public static Vector3 ScreenToWorld(GameObject root, Vector3 screenPosition)
 {
     return(GridBuilderUtils.ScreenToWorld(root, screenPosition));
 }
Ejemplo n.º 20
0
    void PostInitializeForGridBuilder(Dungeon dungeon, GridDungeonModel gridModel)
    {
        var _groupInfoArray = GameObject.FindObjectsOfType <DungeonItemGroupInfo>();

        Dictionary <int, DungeonItemGroupInfo> groupObjectByCellId = new Dictionary <int, DungeonItemGroupInfo>();

        foreach (var groupInfo in _groupInfoArray)
        {
            if (groupInfo.dungeon == dungeon)
            {
                var cellId = groupInfo.groupId;
                var cell   = gridModel.GetCell(cellId);
                if (cell == null || cell.CellType == CellType.Unknown)
                {
                    continue;
                }


                string objectNamePrefix = "";
                if (cell.CellType == CellType.Room)
                {
                    objectNamePrefix = "Room_";
                }
                else
                {
                    groupObjectByCellId[cell.Id] = groupInfo;

                    objectNamePrefix = (cell.CellType == CellType.Corridor) ? "CorridorBlock_" : "CorridorPad_";
                }

                if (objectNamePrefix.Length == 0)
                {
                    objectNamePrefix = "Cell_";
                }

                string groupName = objectNamePrefix + cell.Id;
                groupInfo.gameObject.name = groupName;
            }
        }


        var visited           = new HashSet <int>();
        int clusterCounter    = 1;
        var oldGroupsToDelete = new List <GameObject>();

        foreach (var groupInfo in groupObjectByCellId.Values)
        {
            var cellId = groupInfo.groupId;
            if (visited.Contains(cellId))
            {
                continue;
            }

            var clusters     = GridBuilderUtils.GetCellCluster(gridModel, cellId);
            var itemsToGroup = new List <GameObject>();

            // Mark all cluster cells as visited
            foreach (var clusterItemId in clusters)
            {
                visited.Add(clusterItemId);
                if (groupObjectByCellId.ContainsKey(clusterItemId))
                {
                    var clusterItemGroupInfo = groupObjectByCellId[clusterItemId];
                    for (int i = 0; i < clusterItemGroupInfo.transform.childCount; i++)
                    {
                        var childObject = clusterItemGroupInfo.transform.GetChild(i);
                        itemsToGroup.Add(childObject.gameObject);
                    }
                    oldGroupsToDelete.Add(clusterItemGroupInfo.gameObject);
                }
            }

            int clusterId = clusterCounter++;
            GroupItems(itemsToGroup.ToArray(), "Corridor_" + clusterId, dungeon, clusterId);
        }

        groupObjectByCellId.Clear();

        // Destroy the inner group info objects
        foreach (var itemToDestory in oldGroupsToDelete)
        {
            EditorDestroyObject(itemToDestory);
        }
    }
Ejemplo n.º 21
0
 public static Vector3 ScreenToWorld(Vector3 screenPosition)
 {
     return(GridBuilderUtils.ScreenToWorld(screenPosition));
 }