public static void BuildNodeSockets(TerraNode node)
        {
            node.ClearSockets();
            int inputCount  = 0;
            int outputCount = 0;

            foreach (FieldInfo fieldInfo in node.GetType().GetFields())
            {
                foreach (NodeSocketAttribute nodeSocketAttribute in (NodeSocketAttribute[])fieldInfo.GetCustomAttributes(typeof(NodeSocketAttribute), false))
                {
                    switch (nodeSocketAttribute.SocketType)
                    {
                    case SocketType.Input:
                        node.AddInputSocket(fieldInfo.Name);
                        node.GetSocket(fieldInfo.Name).FieldType = fieldInfo.FieldType;
                        inputCount++;
                        break;

                    case SocketType.Output:
                        node.AddOutputSocket(fieldInfo.Name);
                        node.GetSocket(fieldInfo.Name).FieldType = fieldInfo.FieldType;
                        outputCount++;

                        if (fieldInfo.GetCustomAttribute <AutoFieldAttribute>() != null)
                        {
                            node.GetSocket(fieldInfo.Name).UseField = true;
                        }

                        break;
                    }
                }
            }

            node.SetSize(inputCount > outputCount ? new Vector2(node.Rect.size.x, inputCount * 30) : new Vector2(node.Rect.size.x, outputCount * 30));
        }
 public NodeSocket(TerraNode node, string fieldName, SocketType socketType, int index)
 {
     this.node       = node;
     this.fieldName  = fieldName;
     this.socketType = socketType;
     this.index      = index;
 }
        public static void ProcessNodeEvent(Event e, TerraNode node)
        {
            foreach (NodeSocket socket in node.Sockets)
            {
                ProcessSocketEvent(e, socket);
            }

            switch (e.type)
            {
            case EventType.MouseDown:

                if (e.button == 0)
                {
                    if (node.Rect.Contains(e.mousePosition))
                    {
                        if (!TerraGraphEditor.NodeSelection.Contains(node))
                        {
                            if (!e.shift)
                            {
                                TerraGraphEditor.NodeSelection.Clear();
                                TerraGraphEditor.CommentSelection.Clear();
                            }

                            TerraGraphEditor.NodeSelection.Add(node);
                        }
                        else
                        {
                            if (e.shift)
                            {
                                TerraGraphEditor.NodeSelection.Remove(node);
                            }
                        }

                        GUI.FocusControl(null);
                        e.Use();
                    }
                }

                if (e.button == 1)
                {
                    if (node.Rect.Contains(e.mousePosition))
                    {
                        TerraGraphEditor.NodeSelection.Clear();
                        TerraGraphEditor.CommentSelection.Clear();
                        GUI.FocusControl(null);

                        GenericMenu contextMenu = TerraUtility.CreateNodeContextMenu((t) => TerraGraphEditor.Window.CreateNode(t, e.mousePosition));
                        contextMenu.AddSeparator("");
                        contextMenu.AddItem(new GUIContent("Remove Node"), false, () => TerraGraphEditor.Window.RemoveNode(node));
                        contextMenu.ShowAsContext();

                        e.Use();
                    }
                }

                break;
            }

            TerraUtility.BuildNodeCursorRects(node);
        }
        public TerraNode AddNode(System.Type nodeType)
        {
            TerraNode node = CreateInstance(nodeType) as TerraNode;

            node.AssignToGraph(this);
            nodes.Add(node);
            return(node);
        }
Example #5
0
        public void CreateNode(Type type, Vector2 position)
        {
            TerraNode node = Graph.AddNode(type);

            TerraUtility.BuildNodeSockets(node);
            node.SetPosition(position - node.Rect.size * 0.5f);
            AssetDatabase.AddObjectToAsset(node, Graph);
            EditorUtility.SetDirty(Graph);
            EditorUtility.SetDirty(node);
        }
Example #6
0
        public void RemoveNode(TerraNode node)
        {
            if (node.GetType() == typeof(OutNode))
            {
                return;
            }

            DestroyImmediate(node, true);
            Graph.RemoveNode(node);
            EditorUtility.SetDirty(Graph);
        }
        public static void BuildNodeCursorRects(TerraNode node)
        {
            EditorGUIUtility.AddCursorRect(node.Rect, MouseCursor.MoveArrow);

            foreach (NodeSocket socket in node.Sockets)
            {
                EditorGUIUtility.AddCursorRect(GetSocketRect(socket), MouseCursor.ArrowPlus);

                if (socket.SocketType == SocketType.Output)
                {
                    BuildConnectionCursorRects(socket);
                }
            }
        }
Example #8
0
        public static void DrawNode(TerraNode node)
        {
            //if(TerraUtility.TryGetTooltip(node.GetType(), out string tooltip))
            GUI.Box(node.Rect, new GUIContent("", TerraUtility.GetNodeTooltip(node.GetType())));
            Handles.DrawSolidRectangleWithOutline(node.Rect, Color.white, new Color(0, 0, 0, 0.6f));
            GUI.enabled = false;
            GUI.TextField(new Rect(node.Rect.position, new Vector2(node.Rect.width, 20)), "");
            GUI.enabled = true;
            GUI.Label(new Rect(node.Rect.position, new Vector2(node.Rect.width, 20)), node.GetType().Name, EditorStyles.centeredGreyMiniLabel);

            foreach (NodeSocket socket in node.Sockets)
            {
                DrawSocket(socket);
            }
        }
 public SocketConnection(NodeSocket socket)
 {
     this.socket = socket;
     node        = socket.Node;
     fieldName   = socket.FieldName;
 }
Example #10
0
 public void RemoveNode(TerraNode node)
 {
     node.RemoveAllConnections();
     nodes.Remove(node);
 }