예제 #1
0
        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));
        }
예제 #2
0
        public void RemoveNode(TerraNode node)
        {
            if (node.GetType() == typeof(OutNode))
            {
                return;
            }

            DestroyImmediate(node, true);
            Graph.RemoveNode(node);
            EditorUtility.SetDirty(Graph);
        }
예제 #3
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);
            }
        }