Skip to content

Commit e2b259d

Browse files
committed
Added alpha property to HSBColor.
1 parent 1242128 commit e2b259d

2 files changed

Lines changed: 19 additions & 1 deletion

File tree

Assets/Klak/Wiring/Basic/HSBColor.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@ public class HSBColor : NodeBase
1919
[SerializeField]
2020
float _brightness = 1;
2121

22+
[SerializeField]
23+
float _alpha = 1;
24+
2225
#endregion
2326

2427
#region Node I/O
@@ -47,6 +50,14 @@ public float brightness {
4750
}
4851
}
4952

53+
[Inlet]
54+
public float alpha {
55+
set {
56+
_alpha = value;
57+
if (enabled) UpdateAndInvoke();
58+
}
59+
}
60+
5061
[SerializeField, Outlet]
5162
ColorEvent _colorEvent = new ColorEvent();
5263

@@ -56,7 +67,10 @@ public float brightness {
5667

5768
void UpdateAndInvoke()
5869
{
59-
_colorEvent.Invoke(Color.HSVToRGB(_hue, _saturation, _brightness));
70+
var hue = _hue - Mathf.Floor(_hue);
71+
var c = Color.HSVToRGB(hue, _saturation, _brightness);
72+
c.a = _alpha;
73+
_colorEvent.Invoke(c);
6074
}
6175

6276
#endregion

Assets/Klak/Wiring/Editor/Basic/HSBColorEditor.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@ public class HSBColorEditor : Editor
1313
SerializedProperty _hue;
1414
SerializedProperty _saturation;
1515
SerializedProperty _brightness;
16+
SerializedProperty _alpha;
1617
SerializedProperty _colorEvent;
1718

1819
static GUIContent _textHue = new GUIContent("Initial Hue");
1920
static GUIContent _textSaturation = new GUIContent("Initial Saturation");
2021
static GUIContent _textBrightness = new GUIContent("Initial Brightness");
22+
static GUIContent _textAlpha = new GUIContent("Initial Alpha");
2123

2224
void OnEnable()
2325
{
2426
_hue = serializedObject.FindProperty("_hue");
2527
_saturation = serializedObject.FindProperty("_saturation");
2628
_brightness = serializedObject.FindProperty("_brightness");
29+
_alpha = serializedObject.FindProperty("_alpha");
2730
_colorEvent = serializedObject.FindProperty("_colorEvent");
2831
}
2932

@@ -34,6 +37,7 @@ public override void OnInspectorGUI()
3437
EditorGUILayout.PropertyField(_hue, _textHue);
3538
EditorGUILayout.PropertyField(_saturation, _textSaturation);
3639
EditorGUILayout.PropertyField(_brightness, _textBrightness);
40+
EditorGUILayout.PropertyField(_alpha, _textAlpha);
3741

3842
EditorGUILayout.Space();
3943

0 commit comments

Comments
 (0)