Skip to content
This repository has been archived by the owner on Oct 31, 2023. It is now read-only.

Commit

Permalink
Added Node and Canvas Inspector GUI
Browse files Browse the repository at this point in the history
- Node Inspector calls DrawNodePropertyEditor and defaults to imitating the NodeGUI
- Adjusted selected objects after click to either select a node or the canvas itself
  • Loading branch information
Seneral committed Jul 4, 2017
1 parent 58f5553 commit 79a6567
Show file tree
Hide file tree
Showing 5 changed files with 173 additions and 6 deletions.
73 changes: 73 additions & 0 deletions Editor/Node_Editor/CanvasInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
using UnityEngine;
using UnityEditor;

namespace NodeEditorFramework.Standard
{
[CustomEditor(typeof(NodeCanvas), true)]
public class CanvasInspector : Editor
{
public static GUIStyle titleStyle;
public static GUIStyle subTitleStyle;
public static GUIStyle boldLabelStyle;

public NodeCanvas canvas;

public void OnEnable()
{
canvas = (NodeCanvas)target;
canvas.Validate();
}

public override void OnInspectorGUI()
{
if (canvas == null)
canvas = (NodeCanvas)target;
if (canvas == null)
return;
if (titleStyle == null)
{
titleStyle = new GUIStyle(GUI.skin.label);
titleStyle.fontStyle = FontStyle.Bold;
titleStyle.alignment = TextAnchor.MiddleCenter;
titleStyle.fontSize = 16;
}
if (subTitleStyle == null)
{
subTitleStyle = new GUIStyle(GUI.skin.label);
subTitleStyle.fontStyle = FontStyle.Bold;
subTitleStyle.alignment = TextAnchor.MiddleCenter;
subTitleStyle.fontSize = 12;
}
if (boldLabelStyle == null)
{
boldLabelStyle = new GUIStyle(GUI.skin.label);
boldLabelStyle.fontStyle = FontStyle.Bold;
}

EditorGUI.BeginChangeCheck();

GUILayout.Space(10);

GUILayout.Label(new GUIContent(canvas.saveName, canvas.savePath), titleStyle);
GUILayout.Label(canvas.livesInScene? "Scene Save" : "Asset Save", subTitleStyle);
GUILayout.Label("Type: " + canvas.canvasName, subTitleStyle);

GUILayout.Space(10);

if (GUILayout.Button("Open"))
{
string NodeCanvasPath = AssetDatabase.GetAssetPath(canvas);
NodeEditorWindow.OpenNodeEditor().canvasCache.LoadNodeCanvas(NodeCanvasPath);
}

GUILayout.Space(10);

GUILayout.Label("Nodes", boldLabelStyle);
foreach (Node node in canvas.nodes)
{
string label = node.Title;
EditorGUILayout.ObjectField(label, node, node.GetType(), true);
}
}
}
}
72 changes: 72 additions & 0 deletions Editor/Node_Editor/NodeInspector.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
using UnityEngine;
using UnityEditor;
using NodeEditorFramework.Utilities;

namespace NodeEditorFramework.Standard
{
[CustomEditor(typeof(Node), true)]
public class NodeInspector : Editor
{
public static GUIStyle titleStyle;
public static GUIStyle boldLabelStyle;
public Node node;

public void OnEnable()
{
node = (Node)target;
}

public override void OnInspectorGUI()
{
if (node == null)
node = (Node)target;
if (node == null)
return;
if (titleStyle == null)
{
titleStyle = new GUIStyle(GUI.skin.label);
titleStyle.fontStyle = FontStyle.Bold;
titleStyle.alignment = TextAnchor.MiddleCenter;
titleStyle.fontSize = 16;
}
if (boldLabelStyle == null)
{
boldLabelStyle = new GUIStyle(GUI.skin.label);
boldLabelStyle.fontStyle = FontStyle.Bold;
}

OverlayGUI.StartOverlayGUI("NodeInspector");

EditorGUI.BeginChangeCheck();

GUILayout.Space(10);

GUILayout.Label(node.Title, titleStyle);

GUILayout.Space(10);

GUILayout.Label("Rect: " + node.rect.ToString());
node.backgroundColor = EditorGUILayout.ColorField("Color", node.backgroundColor);

GUILayout.Space(10);

GUILayout.Label("Connection Ports", boldLabelStyle);
foreach (ConnectionPort port in node.connectionPorts)
{
string labelPrefix = port.direction == Direction.In ? "Input " : (port.direction == Direction.Out ? "Output " : "");
string label = labelPrefix + port.styleID + " '" + port.name + "'";
EditorGUILayout.ObjectField(label, port, port.GetType(), true);
}

GUILayout.Space(10);

GUILayout.Label("Property Editor", boldLabelStyle);
node.DrawNodePropertyEditor();

if (EditorGUI.EndChangeCheck())
NodeEditor.RepaintClients();

OverlayGUI.EndOverlayGUI();
}
}
}
6 changes: 5 additions & 1 deletion Node_Editor/Framework/Core/ConnectionKnob.cs
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ public void DisplayLayout (GUIContent content, GUIStyle style)
/// </summary>
public void SetPosition ()
{
if (Event.current.type != EventType.Repaint)
if (Event.current.type != EventType.Repaint || body.ignoreGUIKnobPlacement)
return;
Vector2 pos = GUILayoutUtility.GetLastRect ().center + body.contentOffset;
SetPosition (side == NodeSide.Bottom || side == NodeSide.Top? pos.x : pos.y);
Expand All @@ -258,6 +258,8 @@ public void SetPosition ()
/// </summary>
public void SetPosition(float position, NodeSide nodeSide)
{
if (body.ignoreGUIKnobPlacement)
return;
if (side != nodeSide)
{
side = nodeSide;
Expand All @@ -271,6 +273,8 @@ public void SetPosition(float position, NodeSide nodeSide)
/// </summary>
public void SetPosition(float position)
{
if (body.ignoreGUIKnobPlacement)
return;
sidePosition = position;
}

Expand Down
18 changes: 17 additions & 1 deletion Node_Editor/Framework/Core/Node.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ public abstract partial class Node : ScriptableObject
// Internal
internal Vector2 contentOffset = Vector2.zero;
internal Vector2 nodeGUIHeight;
internal bool ignoreGUIKnobPlacement;

// Style
public Color backgroundColor = Color.white;
Expand Down Expand Up @@ -115,7 +116,22 @@ public virtual void NodeGUI ()
/// Used to display a custom node property editor in the GUI.
/// By default shows the standard NodeGUI.
/// </summary>
public virtual void DrawNodePropertyEditor () { NodeGUI (); }
public virtual void DrawNodePropertyEditor ()
{
try
{ // Draw Node GUI without disturbing knob placement
ignoreGUIKnobPlacement = true;
NodeEditorGUI.StartNodeGUI(false);
GUILayout.BeginVertical(GUI.skin.box);
NodeGUI();
GUILayout.EndVertical();
NodeEditorGUI.EndNodeGUI();
}
finally
{ // Be sure to always reset the state to not mess up other GUI code
ignoreGUIKnobPlacement = false;
}
}

/// <summary>
/// Calculates the outputs of this Node depending on the inputs.
Expand Down
10 changes: 6 additions & 4 deletions Node_Editor/Framework/Interface/NodeEditorInputSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -251,11 +251,13 @@ private static void HandleSelecting (NodeEditorInputInfo inputInfo)
unfocusControlsForState = state;
state.selectedNode = state.focusedNode;
NodeEditor.RepaintClients ();
#if UNITY_EDITOR
if (state.selectedNode != null)
UnityEditor.Selection.activeObject = state.selectedNode;
#endif
}
#if UNITY_EDITOR
if (state.selectedNode != null)
UnityEditor.Selection.activeObject = state.selectedNode;
else
UnityEditor.Selection.activeObject = state.canvas;
#endif
}

// CONTEXT CLICKS
Expand Down

0 comments on commit 79a6567

Please sign in to comment.