Пример #1
0
        static void BuildToRoom()
        {
            int xAmount = m_startPos.x - m_endPos.x;
            int yAmount = m_startPos.y - m_endPos.y;

            if (xAmount < 0)
            {
                for (int x = 0; x > xAmount; --x)//Left
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                    }
                }
            }
            else if (xAmount > 0)
            {
                for (int x = 0; x < xAmount; ++x)//Right
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                    }
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)) != null)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0)).name.Contains("Wall"))
                        {
                            BuildPathTile(new Vector3Int(m_startPos.x - x, m_startPos.y, 0));
                        }
                    }
                }
            }
            if (yAmount < 0)
            {
                for (int y = 0; y > yAmount; --y)
                {
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y, 0)) == null)
                    {
                        BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y, 0));
                    }
                    if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0)) != null)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0)).name.Contains("Wall"))
                        {
                            TileManager.RemoveTilePiece(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0), DungeonUtility.GetTilemap());

                            if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 2, 0)) == null)
                            {
                                BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0));
                            }
                            else
                            {
                                BuildPathTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y - 1, 0));
                            }
                        }
                    }
                }
            }
            else
            {
                if (yAmount > 0)
                {
                    for (int y = 0; y < yAmount; ++y)
                    {
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y, 0)) == null)
                        {
                            BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y, 0));
                        }
                        if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0)) != null)
                        {
                            if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0)).name.Contains("Wall"))
                            {
                                TileManager.RemoveTilePiece(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0), DungeonUtility.GetTilemap());
                                if (DungeonUtility.GetTilemap().GetTile(new Vector3Int(m_startPos.x - xAmount, m_startPos.y - y + 2, 0)) == null)
                                {
                                    BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0));
                                }
                                else
                                {
                                    BuildPathTile(new Vector3Int(m_startPos.x + -xAmount, m_startPos.y - y + 1, 0));
                                }
                            }
                        }
                    }
                }
            }
        }