public void SplitByBorder() { cells.Clear(); ImageCell cell = new ImageCell(); Color curPixel = bmpImage.GetPixel(0, 0); cell.cell_Color = curPixel; for (int i = 0; i < bmpImage.width; i++) { for (int j = 0; j < bmpImage.height; j++) { Color pixel = bmpImage.GetPixel(i, j); if (pixel == Color.black) { Color prevPixel = bmpImage.GetPixel(i - 1, j); if (HasColour(prevPixel)) { ImageCell prevCell = GetCell(bmpImage.GetPixel(i - 1, j)); if (cell.seed_Location == Vector3.zero || prevCell.seed_Location == Vector3.zero) { prevCell.SetSeedLoc(i, j, 0); } if (IsBorderCell(prevCell.cell_Color, i, j)) { prevCell.borderPoints.Add(new Vector3(i, j, 0)); } } else if (cell.seed_Location == Vector3.zero || cell.seed_Location == Vector3.zero) { cell.seed_Location = new Vector3(i, j, 0); // Alterar o y pelo z pois quero o mapa horizontal if (IsBorderCell(prevPixel, i, j)) { cell.borderPoints.Add(new Vector3(i, j, 0)); } } continue; } if (IsBorderCell(pixel, i, j)) { if (pixel != curPixel && pixel != Color.black) { if (HasColour(pixel)) { GetCell(pixel).borderPoints.Add(new Vector3(i, j, 0)); } else { curPixel = pixel; cells.Add(cell); cell = new ImageCell { borderPoints = new List <Vector3>(), cell_Color = curPixel }; cell.borderPoints.Add(new Vector3(i, j, 0)); } } else { cell.borderPoints.Add(new Vector3(i, j, 0)); } } } } cells.Add(cell); Debug.Log(cells.Count); }