/* ============================== Draw ============================== */ public void Draw(Vector2 start, Vector2 end, ECBrush brush) { if (brush.size <= 1) { Line(start, end, brush.color); return; } brush.size += 1; if (end == start) { end.y++; } Rect rect = new Rect(Mathf.Min(start.x, end.x) - brush.size, Mathf.Min(start.y, end.y) - brush.size, Mathf.Abs(start.x - end.x) + brush.size * 2, Mathf.Abs(start.y - end.y) + brush.size * 2); rect = DestRect(rect, texture); int rx = (int)rect.x; int ry = (int)rect.y; int rw = (int)rect.width; int rh = (int)rect.height; if (rx < 0 || ry < 0 || rw < 0 || rh < 0) { return; } //Color[] colors = preview.GetPixels(rx, ry, rw, rh); //Color[] colors = new Color[rw * rh]; //for (int i = 0; i < colors.Length; i++) colors[i] = Color.clear; for (int y = ry; y < ry + rh; y++) { for (int x = rx; x < rx + rw; x++) { Vector2 p = new Vector2(x, y); float d = StraightLine.Distance(p, start, end); if (d > brush.size) { continue; } else if (d <= brush.size) { int i = (x - rx) + (y - ry) * rw; float a = (brush.size - d) / (brush.size * (1 - brush.hardness)); a = d / (float)brush.size <= brush.hardness ? brush.color.a : a * brush.color.a; if (preview.GetPixel(x, y).a < a) //colors[i].a < a) { Color c = brush.color; if (brush.tool == ECBrush.Tool.Eraser) { c = origin[x + y * width]; } if (d >= brush.size - 1) { c.a = 0; } else { c.a = a; } Map(x, y, c); //colors[i] = c; //Map(x, y, colors[i]); } } } } //Map(rx, ry, rw, rh, colors); }