Skip to content

Commit

Permalink
Added alpha property to HSBColor.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Apr 23, 2017
1 parent 1242128 commit e2b259d
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
16 changes: 15 additions & 1 deletion Assets/Klak/Wiring/Basic/HSBColor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ public class HSBColor : NodeBase
[SerializeField]
float _brightness = 1;

[SerializeField]
float _alpha = 1;

#endregion

#region Node I/O
Expand Down Expand Up @@ -47,6 +50,14 @@ public float brightness {
}
}

[Inlet]
public float alpha {
set {
_alpha = value;
if (enabled) UpdateAndInvoke();
}
}

[SerializeField, Outlet]
ColorEvent _colorEvent = new ColorEvent();

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

void UpdateAndInvoke()
{
_colorEvent.Invoke(Color.HSVToRGB(_hue, _saturation, _brightness));
var hue = _hue - Mathf.Floor(_hue);
var c = Color.HSVToRGB(hue, _saturation, _brightness);
c.a = _alpha;
_colorEvent.Invoke(c);
}

#endregion
Expand Down
4 changes: 4 additions & 0 deletions Assets/Klak/Wiring/Editor/Basic/HSBColorEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,17 +13,20 @@ public class HSBColorEditor : Editor
SerializedProperty _hue;
SerializedProperty _saturation;
SerializedProperty _brightness;
SerializedProperty _alpha;
SerializedProperty _colorEvent;

static GUIContent _textHue = new GUIContent("Initial Hue");
static GUIContent _textSaturation = new GUIContent("Initial Saturation");
static GUIContent _textBrightness = new GUIContent("Initial Brightness");
static GUIContent _textAlpha = new GUIContent("Initial Alpha");

void OnEnable()
{
_hue = serializedObject.FindProperty("_hue");
_saturation = serializedObject.FindProperty("_saturation");
_brightness = serializedObject.FindProperty("_brightness");
_alpha = serializedObject.FindProperty("_alpha");
_colorEvent = serializedObject.FindProperty("_colorEvent");
}

Expand All @@ -34,6 +37,7 @@ public override void OnInspectorGUI()
EditorGUILayout.PropertyField(_hue, _textHue);
EditorGUILayout.PropertyField(_saturation, _textSaturation);
EditorGUILayout.PropertyField(_brightness, _textBrightness);
EditorGUILayout.PropertyField(_alpha, _textAlpha);

EditorGUILayout.Space();

Expand Down

0 comments on commit e2b259d

Please sign in to comment.