Skip to content

Commit

Permalink
Add ComponentVector
Browse files Browse the repository at this point in the history
  • Loading branch information
finnTE committed Mar 23, 2018
1 parent bb5f40a commit 41d0c89
Show file tree
Hide file tree
Showing 4 changed files with 113 additions and 0 deletions.
65 changes: 65 additions & 0 deletions Assets/Klak/Wiring/Basic/ComponentVector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
using UnityEngine;

namespace Klak.Wiring
{
[AddComponentMenu("Klak/Wiring/Convertion/Component Vector")]
public class ComponentVector : NodeBase
{
#region Editable properties

[SerializeField]
Vector3 _vector;
public Vector3 vector {
get { return _vector; }
set { _vector = value; }
}

#endregion

#region Node I/O

[Inlet]
public float x {
set {
if (!enabled) return;
_vector.x = value;
}
}

[Inlet]
public float y {
set {
if (!enabled) return;
_vector.y = value;
}
}

[Inlet]
public float z {
set {
if (!enabled) return;
_vector.z = value;
}
}

[SerializeField, Outlet]
Vector3Event _vectorEvent = new Vector3Event();

#endregion

Vector3 _prevVector;

#region Monobehaviour

void Update()
{
if (_vector != _prevVector)
{
_vectorEvent.Invoke(_vector);
_prevVector = _vector;
}
}

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

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

24 changes: 24 additions & 0 deletions Assets/Klak/Wiring/Editor/Basic/ComponentVectorEditor.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
using UnityEngine;
using UnityEditor;

namespace Klak.Wiring
{
[CanEditMultipleObjects]
[CustomEditor(typeof(ComponentVector))]
public class ComponentVectorEditor : Editor {

public override bool RequiresConstantRepaint()
{
return true;
}

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

DrawPropertiesExcluding(serializedObject, new string[] {"m_Script"});

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

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

0 comments on commit 41d0c89

Please sign in to comment.