public void DrawDot(Point point) { Color color = currentColor; int index = DotEditUtils.GetIndexFromPoint(point, sizeX); if (0 <= index && index < cells.Length) { if (currentToolType == ToolType.Pencil) { cells[index].image.color = color; colors[index] = color; } else if (currentToolType == ToolType.Eraser) { Erase(point); } else if (currentToolType == ToolType.Fill) { startColor = colors[index]; searched = new HashSet <Point>(); total = 0; Fill(point); } } else { Debug.LogWarningFormat("不正な index: {0}", index); } }
public void Setup() { cells = new DotCellUI[sizeX * sizeY]; colors = new Color[sizeX * sizeY]; currentColor = Color.black; currentToolType = ToolType.Pencil; for (int i = 0; i < sizeX; i++) { for (int j = 0; j < sizeY; j++) { Point point = new Point(i, j); int index = DotEditUtils.GetIndexFromPoint(point, sizeX); DotCellUI cell = Instantiate <DotCellUI>(cellTemplate, cellParent); cell.point = point; cell.onDraw = DrawDot; cell.gameObject.SetActive(true); cells[index] = cell; Erase(point); } } // テンプレートを隠す cellTemplate.gameObject.SetActive(false); }
public void SavePng(Color[] cols) { Texture2D m_texture = new Texture2D(Max, Max, TextureFormat.ARGB32, false); m_texture.name = ""; for (int index = 0; index < Max * Max; index++) { Point point = DotEditUtils.GetPointFromIndex(index, Max); m_texture.SetPixel(point.y, Max - point.x, cols[index]); } m_texture.Apply(); SavePngSub(m_texture); }
public void Erase(Point point) { int d = point.y % 2; int index = DotEditUtils.GetIndexFromPoint(point, sizeX); if ((point.x + d) % 2 == 0) { cells[index].image.color = alpha1; } else { cells[index].image.color = alpha2; } colors[index] = new Color(0f, 0f, 0f, 0f); }
public void Fill(Point point) { total++; if (searched.Contains(point)) { return; } if (total > 10000) { return; } // Debug.LogFormat("({0}, {1})", point.x, point.y); searched.Add(point); int index = DotEditUtils.GetIndexFromPoint(point, sizeX); Color color = currentColor; if (0 <= point.x && point.x < sizeX && 0 <= point.y && point.y < sizeY) { if (colors[index] != startColor) { return; } cells[index].image.color = color; colors[index] = color; } else { return; } Point right = new Point(point.x + 1, point.y); Point left = new Point(point.x - 1, point.y); Point down = new Point(point.x, point.y + 1); Point up = new Point(point.x, point.y - 1); Fill(right); Fill(left); Fill(up); Fill(down); }