Texture2D CreateHueTexture(int width, int height) { var tex = new Texture2D(width, height); for (int y = 0; y < height; y++) { var h = 1f * y / height; var color = IMColorUtil.HSVToRGB(h, 1f, 1f); for (int x = 0; x < width; x++) { tex.SetPixel(x, y, color); } } tex.Apply(); return(tex); }
void DrawSVHandler(Rect rect, ref Color c) { const float size = 10f; const float offset = 5f; GUI.DrawTexture(new Rect(rect.x + s * rect.width - offset, rect.y + (1f - v) * rect.height - offset, size, size), circle); var e = Event.current; var p = e.mousePosition; if (e.button == 0 && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && rect.Contains(p)) { s = (p.x - rect.x) / rect.width; v = 1f - (p.y - rect.y) / rect.height; c = IMColorUtil.HSVToRGB(h, s, v); e.Use(); ClearPresetSelection(); } }
void UpdateSVTexture(Color c, Texture2D tex) { float h, _s, _v; IMColorUtil.RGBToHSV(c, out h, out _s, out _v); var size = tex.width; for (int y = 0; y < size; y++) { var v = 1f * y / size; for (int x = 0; x < size; x++) { var s = 1f * x / size; var color = IMColorUtil.HSVToRGB(h, s, v); tex.SetPixel(x, y, color); } } tex.Apply(); }
void DrawHueHandler(Rect rect, ref Color c) { const float size = 15f; GUI.DrawTexture(new Rect(rect.x - size * 0.75f, rect.y + (1f - h) * rect.height - size * 0.5f, size, size), rightArrow); GUI.DrawTexture(new Rect(rect.x + rect.width - size * 0.25f, rect.y + (1f - h) * rect.height - size * 0.5f, size, size), leftArrow); var e = Event.current; var p = e.mousePosition; if (e.button == 0 && (e.type == EventType.MouseDown || e.type == EventType.MouseDrag) && rect.Contains(p)) { h = 1f - (p.y - rect.y) / rect.height; c = IMColorUtil.HSVToRGB(h, s, v); UpdateSVTexture(c, svTexture); e.Use(); ClearPresetSelection(); } }