Esempio n. 1
0
        private static void CreatePassage(Region regionA, Region regionB, Vector3Int tileA, Vector3Int tileB)
        {
            List <Vector3Int> line       = HexTools.GetLine(tileA, tileB);
            Passageway        passageway = new Passageway(regionA, regionB, tileA, tileB, line);

            Region.ConnectRegions(regionA, regionB, passageway);
            //Debug.DrawLine(tilemap.CellToWorld(tileA), tilemap.CellToWorld(tileB), Color.green, 10);

            foreach (Vector3Int tileCoord in line)
            {
                mapGen.ChangeAllTilesAround(tileCoord, rules.passageSize, rules.openTile);
            }
        }
Esempio n. 2
0
        void Update()
        {
            Vector3 mousepos = Input.mousePosition;
            Ray     ray      = cam.ScreenPointToRay(mousepos);
            Plane   plane    = new Plane(Vector3.back, Vector3.zero);

            if (plane.Raycast(ray, out float hitDist))
            {
                Vector3    worldpoint = ray.GetPoint(hitDist);
                Vector3Int tilepoint  = tilemap.WorldToCell(worldpoint);

                TerrainTile tile = GetTile(tilepoint);

                if (startTile != null)
                {
                    foreach (Vector3Int lineTile in lastLine)
                    {
                        tilemap.SetColor(lineTile, Color.white);
                    }
                    lastLine.Clear();
                    foreach (Vector3Int radiusTile in lastRadius)
                    {
                        tilemap.SetColor(radiusTile, Color.white);
                    }
                    lastRadius.Clear();
                    foreach (Vector3Int ringTile in lastRing)
                    {
                        tilemap.SetColor(ringTile, Color.white);
                    }
                    lastRing.Clear();


                    if (Input.GetMouseButtonUp(0))
                    {
                        startTile = null;
                    }
                    else
                    {
                        int n = HexTools.DistanceInTiles(startTile.coordinates, tilepoint);
                        List <Vector3Int> radius =
                            HexTools.GetSpiral(startTile.coordinates, n);
                        //HexTools.GetTilesInRange(startTile.coordinates, n);
                        List <Vector3Int> line = HexTools.GetLine(startTile.coordinates, tilepoint);
                        List <Vector3Int> ring = HexTools.GetRing(startTile.coordinates, n);

                        foreach (Vector3Int radiusTile in radius)
                        {
                            tilemap.SetColor(radiusTile, Color.yellow);
                        }

                        foreach (Vector3Int radiusTile in ring)
                        {
                            tilemap.SetColor(radiusTile, Color.red);
                        }

                        foreach (Vector3Int lineTile in line)
                        {
                            tilemap.SetColor(lineTile, Color.magenta);
                        }



                        lastLine   = line;
                        lastRadius = radius;
                        lastRing   = ring;
                    }
                }
                if (tile == null && Input.GetMouseButtonDown(0))
                {
                    RevealArea(tilepoint, revealRadius);
                }
                else
                {
                    if (tile != null)
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            Debug.Log("World: " + worldpoint + " Coords: " + tilepoint);
                            startTile = tile;
                        }
                    }
                    else
                    {
                        if (Input.GetMouseButtonDown(0))
                        {
                            Debug.Log("Null Tilepoint: " + tilepoint);
                        }
                    }
                }
            }
        }