@@ -13,6 +13,8 @@ public class ColorPicker
13
13
public static Texture2D imRight , imLeft , imCircle ;
14
14
int wid ;
15
15
Rect pos ;
16
+ public float wX { get => pos . x ; }
17
+ public float wY { get => pos . y ; }
16
18
public Color color ;
17
19
public void UpdateColor ( )
18
20
{
@@ -29,7 +31,7 @@ public void UpdateColor()
29
31
30
32
public ColorPicker ( Color _color , int x , int y ) {
31
33
wid = ImGUI_WID . GetWindowId ( ) ;
32
- pos = new Rect ( x , y , 165 , 200 ) ;
34
+ pos = new Rect ( x , y , 165 , 215 ) ;
33
35
color = _color ;
34
36
35
37
RGBToHSV ( _color , out h , out s , out v ) ;
@@ -77,7 +79,7 @@ public void DrawWindow()
77
79
#region https://github.com/mattatz/unity-immediate-color-picker
78
80
// Licensed under MIT license. Copyright (c) 2016 mattatz
79
81
// Check their repo for full license and copyright notice
80
- public static Color HSVToRGB ( float H , float S , float V , bool hdr = false )
82
+ public static Color HSVToRGB ( float H , float S , float V , float keepAlpha = - 1 , bool hdr = false )
81
83
{
82
84
Color white = Color . white ;
83
85
if ( S == 0f )
@@ -153,6 +155,8 @@ public static Color HSVToRGB(float H, float S, float V, bool hdr = false)
153
155
white . b = Mathf . Clamp ( white . b , 0f , 1f ) ;
154
156
}
155
157
}
158
+ if ( keepAlpha != - 1 )
159
+ white . a = Mathf . Clamp ( keepAlpha , 0 , 1 ) ;
156
160
return white ;
157
161
}
158
162
@@ -272,12 +276,18 @@ void DrawManualInput(ref Color c)
272
276
c . g = float . Parse ( GUILayout . TextField ( c . g . ToString ( "0.00" ) , GUILayout . Height ( 20 ) , GUILayout . Width ( 35 ) ) ) ;
273
277
c . b = float . Parse ( GUILayout . TextField ( c . b . ToString ( "0.00" ) , GUILayout . Height ( 20 ) , GUILayout . Width ( 35 ) ) ) ;
274
278
c . a = float . Parse ( GUILayout . TextField ( c . a . ToString ( "0.00" ) , GUILayout . Height ( 20 ) , GUILayout . Width ( 35 ) ) ) ;
275
- // clamp values
276
- c . r = Mathf . Clamp ( c . r , 0 , 1 ) ;
277
- c . g = Mathf . Clamp ( c . g , 0 , 1 ) ;
278
- c . b = Mathf . Clamp ( c . b , 0 , 1 ) ;
279
- c . a = Mathf . Clamp ( c . a , 0 , 1 ) ;
280
279
}
280
+ using ( new GUILayout . HorizontalScope ( ) )
281
+ {
282
+ GUILayout . Space ( - 3 ) ;
283
+ c . a = GUILayout . HorizontalSlider ( c . a , 0 , 1 , GUILayout . Height ( 20 ) , GUILayout . Width ( 150 ) ) ;
284
+ }
285
+
286
+ // clamp values
287
+ c . r = Mathf . Clamp ( c . r , 0 , 1 ) ;
288
+ c . g = Mathf . Clamp ( c . g , 0 , 1 ) ;
289
+ c . b = Mathf . Clamp ( c . b , 0 , 1 ) ;
290
+ c . a = Mathf . Clamp ( c . a , 0 , 1 ) ;
281
291
}
282
292
283
293
void UpdateSVTexture ( Color c , Texture2D tex )
@@ -311,7 +321,7 @@ void DrawSVHandler(Rect rect, ref Color c)
311
321
{
312
322
s = ( p . x - rect . x ) / rect . width ;
313
323
v = 1f - ( p . y - rect . y ) / rect . height ;
314
- c = HSVToRGB ( h , s , v ) ;
324
+ c = HSVToRGB ( h , s , v , c . a ) ;
315
325
316
326
e . Use ( ) ;
317
327
}
@@ -328,7 +338,7 @@ void DrawHueHandler(Rect rect, ref Color c)
328
338
if ( e . button == 0 && ( e . type == EventType . MouseDown || e . type == EventType . MouseDrag ) && rect . Contains ( p ) )
329
339
{
330
340
h = 1f - ( p . y - rect . y ) / rect . height ;
331
- c = HSVToRGB ( h , s , v ) ;
341
+ c = HSVToRGB ( h , s , v , c . a ) ;
332
342
UpdateSVTexture ( c , svTexture ) ;
333
343
334
344
e . Use ( ) ;
0 commit comments