private void GetDiagonalCollision()
    {
        Rect diagonalRect = new Rect();

        for (int row = 0; row < mapData.Height; ++row)
        {
            for (int col = 0; col < mapData.Width; ++col)
            {
                Tile currentTile = mapData[row, col];
                if (IsDiagonalCollision(currentTile))
                {
                    if (IsLowerCollision(currentTile))
                    {
                        diagonalRect.x      = col;
                        diagonalRect.y      = row;
                        diagonalRect.width  = 1f;
                        diagonalRect.height = 0.5f;
                    }
                    else                     // upper collision
                    {
                        diagonalRect.x      = col;
                        diagonalRect.y      = row + 0.5f;
                        diagonalRect.width  = 1f;
                        diagonalRect.height = 0.5f;
                    }

                    if (IsLeftCollision(currentTile))
                    {
                        diagonalRect.x    += 1;
                        diagonalRect.width = -diagonalRect.width;
                    }
                    else
                    {
                    }

                    RectangleMesh diagRectMesh = new RectangleMesh(diagonalRect);
                    diagRectMesh.BuildDiagonalMesh();

                    if (IsTopCollision(currentTile) || IsLeftCollision(currentTile))
                    {
                        diagRectMesh.InvertMesh();
                    }



                    meshes.Add(diagRectMesh.Mesh);
                }
            }
        }
    }
    private void GetCeilingCollision()
    {
        Rect ceilingRect = new Rect();

        for (int row = mapData.Height - 1; row >= 0; --row)
        {
            for (int col = 0; col < mapData.Width; ++col)
            {
                Tile currentTile = mapData[row, col];
                if (IsNormalCollision(currentTile))
                {
                    if (row - 1 >= 0)
                    {
                        Tile belowTile = mapData[row - 1, col];
                        if (IsNormalCollision(belowTile))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        continue;
                    }
                    ceilingRect.x = col;
                    ceilingRect.y = row;

                    while (IsInBounds(row - 1, col + 1))
                    {
                        currentTile = mapData[row, col + 1];
                        if (row - 1 >= 0)
                        {
                            Tile belowTile = mapData[row - 1, col];
                            if (IsNormalCollision(belowTile))
                            {
                                --col;
                                break;
                            }
                        }
                        if (IsNormalCollision(currentTile))
                        {
                            ++col;
                        }
                        else
                        {
                            break;
                        }
                    }

                    float floorWidth = col - ceilingRect.x + 1;

                    ceilingRect.width  = floorWidth;
                    ceilingRect.height = 0;

                    RectangleMesh ceilingMesh = new RectangleMesh(ceilingRect);
                    ceilingMesh.BuildHorizontalMesh();
                    ceilingMesh.InvertMesh();
                    meshes.Add(ceilingMesh.Mesh);
                }
            }
        }
    }
    private void GetRightCollision()
    {
        Rect rightRect = new Rect();

        for (int col = 0; col < mapData.Width; ++col)
        {
            for (int row = 0; row < mapData.Height; ++row)
            {
                Tile currentTile = mapData[row, col];
                if (IsNormalCollision(currentTile))
                {
                    if (col + 1 < mapData.Width)
                    {
                        Tile rightTile = mapData[row, col + 1];
                        if (IsNormalCollision(rightTile))
                        {
                            continue;
                        }
                    }
                    else
                    {
                        return;
                    }

                    rightRect.x = col + 1;
                    rightRect.y = row;

                    while (row + 1 < mapData.Height)
                    {
                        currentTile = mapData[row + 1, col];
                        if (col + 1 < mapData.Width)
                        {
                            Tile rightTile = mapData[row, col + 1];
                            if (IsNormalCollision(rightTile))
                            {
                                --row;
                                break;
                            }
                        }
                        if (IsNormalCollision(currentTile))
                        {
                            ++row;
                        }
                        else
                        {
                            break;
                        }
                    }
                    rightRect.width  = 0;
                    rightRect.height = row - rightRect.y + 1;


                    RectangleMesh rightMesh = new RectangleMesh(rightRect);
                    rightMesh.BuildVerticalMesh();
                    rightMesh.InvertMesh();

                    meshes.Add(rightMesh.Mesh);
                }
            }
        }
    }
	private void GetDiagonalCollision ()
	{
		Rect diagonalRect = new Rect();

		for (int row = 0; row < mapData.Height; ++row)
		{
			for (int col = 0; col < mapData.Width; ++col)
			{
				Tile currentTile = mapData[row, col];
				if (IsDiagonalCollision(currentTile))
				{
					if (IsLowerCollision(currentTile))
					{
						diagonalRect.x      = col;
						diagonalRect.y      = row;
						diagonalRect.width  = 1f;
						diagonalRect.height = 0.5f;
					}
					else // upper collision
					{
						diagonalRect.x      = col;
						diagonalRect.y      = row + 0.5f;
						diagonalRect.width  = 1f;
						diagonalRect.height = 0.5f;
					}

					if (IsLeftCollision(currentTile))
					{
						diagonalRect.x += 1;
						diagonalRect.width = -diagonalRect.width;

					}
					else
					{
					}

					RectangleMesh diagRectMesh = new RectangleMesh(diagonalRect);
					diagRectMesh.BuildDiagonalMesh();

					if (IsTopCollision(currentTile) || IsLeftCollision(currentTile))
					{
						diagRectMesh.InvertMesh();
					}



					meshes.Add(diagRectMesh.Mesh);
				}

			}
		}
	}
	private void GetRightCollision ()
	{
		Rect rightRect = new Rect();

		for (int col = 0; col < mapData.Width; ++col)
		{
			for (int row = 0; row < mapData.Height; ++row)
			{
				Tile currentTile = mapData[row, col];
				if (IsNormalCollision(currentTile))
				{
					if (col + 1 < mapData.Width)
					{
						Tile rightTile = mapData[row, col + 1];
						if (IsNormalCollision(rightTile))
						{
							continue;
						}
					}
					else
					{
						return;
					}

					rightRect.x = col + 1;
					rightRect.y = row;

					while (row + 1 < mapData.Height)
					{
						currentTile = mapData[row + 1, col];
						if (col + 1 < mapData.Width)
						{
							Tile rightTile = mapData[row, col + 1];
							if (IsNormalCollision(rightTile))
							{
								--row;
								break;
							}
						}
						if (IsNormalCollision(currentTile))
						{
							++row;
						}
						else
						{
							break;
						}
					}
					rightRect.width = 0;
					rightRect.height = row - rightRect.y + 1;


					RectangleMesh rightMesh = new RectangleMesh(rightRect);
					rightMesh.BuildVerticalMesh();
					rightMesh.InvertMesh();
					
					meshes.Add(rightMesh.Mesh);
				}
			}
		}

	}
	private void GetCeilingCollision ()
	{
		Rect ceilingRect = new Rect();
		
		for (int row = mapData.Height - 1; row >= 0; --row)
		{
			for (int col = 0; col < mapData.Width; ++col)
			{
				Tile currentTile = mapData[row, col];
				if (IsNormalCollision(currentTile))
				{
					if (row - 1 >= 0)
					{
						Tile belowTile = mapData[row - 1, col];
						if (IsNormalCollision(belowTile))
						{
							continue;
						}
					}
					else
					{
						continue;
					}
					ceilingRect.x = col;
					ceilingRect.y = row;
					
					while (IsInBounds(row - 1, col + 1))
					{
						currentTile = mapData[row, col + 1];
						if (row - 1 >= 0)
						{
							Tile belowTile = mapData[row - 1, col];
							if (IsNormalCollision(belowTile))
							{ 
								--col;
								break;
							}
						}
						if (IsNormalCollision(currentTile))
						{
							++col;
						}
						else
						{
							break;
						}
					}
					
					float floorWidth = col - ceilingRect.x + 1;
					
					ceilingRect.width  = floorWidth;
					ceilingRect.height = 0;
					
					RectangleMesh ceilingMesh = new RectangleMesh(ceilingRect);
					ceilingMesh.BuildHorizontalMesh();
					ceilingMesh.InvertMesh();
					meshes.Add (ceilingMesh.Mesh);
				}
			}
		}
	}