Skip to content

Commit

Permalink
Added HSBColor, BangFilter and RandomValue.
Browse files Browse the repository at this point in the history
  • Loading branch information
keijiro committed Apr 23, 2017
1 parent b041da9 commit 1242128
Show file tree
Hide file tree
Showing 12 changed files with 350 additions and 0 deletions.
64 changes: 64 additions & 0 deletions Assets/Klak/Wiring/Basic/HSBColor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;

namespace Klak.Wiring
{
[AddComponentMenu("Klak/Wiring/Convertion/HSB Color")]
public class HSBColor : NodeBase
{
#region Editable properties

[SerializeField, Range(0, 1)]
float _hue = 0;

[SerializeField, Range(0, 1)]
float _saturation = 1;

[SerializeField]
float _brightness = 1;

#endregion

#region Node I/O

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

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

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

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

#endregion

#region Private members

void UpdateAndInvoke()
{
_colorEvent.Invoke(Color.HSVToRGB(_hue, _saturation, _brightness));
}

#endregion
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Basic/HSBColor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 45 additions & 0 deletions Assets/Klak/Wiring/Editor/Basic/HSBColorEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;
using UnityEditor;

namespace Klak.Wiring
{
[CanEditMultipleObjects]
[CustomEditor(typeof(HSBColor))]
public class HSBColorEditor : Editor
{
SerializedProperty _hue;
SerializedProperty _saturation;
SerializedProperty _brightness;
SerializedProperty _colorEvent;

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

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

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_hue, _textHue);
EditorGUILayout.PropertyField(_saturation, _textSaturation);
EditorGUILayout.PropertyField(_brightness, _textBrightness);

EditorGUILayout.Space();

EditorGUILayout.PropertyField(_colorEvent);

serializedObject.ApplyModifiedProperties();
}
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Editor/Basic/HSBColorEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 37 additions & 0 deletions Assets/Klak/Wiring/Editor/Filter/BangFilterEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;
using UnityEditor;

namespace Klak.Wiring
{
[CanEditMultipleObjects]
[CustomEditor(typeof(BangFilter))]
public class BangFilterEditor : Editor
{
SerializedProperty _state;
SerializedProperty _bangEvent;

static GUIContent _textInitialState = new GUIContent("Opened");

void OnEnable()
{
_state = serializedObject.FindProperty("_state");
_bangEvent = serializedObject.FindProperty("_bangEvent");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_state, _textInitialState);

EditorGUILayout.Space();

EditorGUILayout.PropertyField(_bangEvent);

serializedObject.ApplyModifiedProperties();
}
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Editor/Filter/BangFilterEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions Assets/Klak/Wiring/Editor/Input/RandomValueEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;
using UnityEditor;

namespace Klak.Wiring
{
[CanEditMultipleObjects]
[CustomEditor(typeof(RandomValue))]
public class RandomValueEditor : Editor
{
SerializedProperty _minimum;
SerializedProperty _maximum;
SerializedProperty _sendOnStartUp;
SerializedProperty _outputEvent;

void OnEnable()
{
_minimum = serializedObject.FindProperty("_minimum");
_maximum = serializedObject.FindProperty("_maximum");
_sendOnStartUp = serializedObject.FindProperty("_sendOnStartUp");
_outputEvent = serializedObject.FindProperty("_outputEvent");
}

public override void OnInspectorGUI()
{
serializedObject.Update();

EditorGUILayout.PropertyField(_minimum);
EditorGUILayout.PropertyField(_maximum);
EditorGUILayout.PropertyField(_sendOnStartUp);

EditorGUILayout.Space();

EditorGUILayout.PropertyField(_outputEvent);

serializedObject.ApplyModifiedProperties();
}
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Editor/Input/RandomValueEditor.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 43 additions & 0 deletions Assets/Klak/Wiring/Filter/BangFilter.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;

namespace Klak.Wiring
{
[AddComponentMenu("Klak/Wiring/Filter/Bang Filter")]
public class BangFilter : NodeBase
{
#region Editable properties

[SerializeField]
bool _state;

#endregion

#region Node I/O

[Inlet]
public void Bang()
{
if (_state) _bangEvent.Invoke();
}

[Inlet]
public void Open()
{
_state = true;
}

[Inlet]
public void Close()
{
_state = false;
}

[SerializeField, Outlet]
VoidEvent _bangEvent = new VoidEvent();

#endregion
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Filter/BangFilter.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 48 additions & 0 deletions Assets/Klak/Wiring/Input/RandomValue.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// Klak - Creative coding library for Unity
// https://github.com/keijiro/Klak

using UnityEngine;

namespace Klak.Wiring
{
[AddComponentMenu("Klak/Wiring/Input/Random Value")]
public class RandomValue : NodeBase
{
#region Editable properties

[SerializeField]
float _minimum = 0;

[SerializeField]
float _maximum = 1;

[SerializeField]
bool _sendOnStartUp = false;

#endregion

#region Node I/O

[Inlet]
public void Bang()
{
if (!enabled) return;

_outputEvent.Invoke(Random.Range(_minimum, _maximum));
}

[SerializeField, Outlet]
FloatEvent _outputEvent = new FloatEvent();

#endregion

#region MonoBehaviour functions

void Start()
{
if (_sendOnStartUp) Bang();
}

#endregion
}
}
12 changes: 12 additions & 0 deletions Assets/Klak/Wiring/Input/RandomValue.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1242128

Please sign in to comment.