Esempio n. 1
0
        public static void DrawNodePreview(System.Type nodeType, NodeDataAttribute nodeData, params NodeHandleAttribute[] nodeHandles)
        {
            InitiateNodeStyles();

            Rect nodeRect = new Rect(new Vector2(16f, 16f), nodeData.nodeSize + new Vector2(nodeHandleWidth * 2f, 0f));

            GUILayout.BeginArea(nodeRect);

            // Draw Background
            Color oldColor = GUI.backgroundColor;

            GUI.backgroundColor = nodeData.nodeColor;
            GUILayout.BeginArea(new Rect(nodeHandleWidth, 0f, nodeRect.width - nodeHandleWidth * 2f, nodeRect.height), nodeBGStyle);
            GUI.backgroundColor = oldColor;

            // Draw Header
            Rect headerRect = new Rect(0f, 0f, nodeRect.width - nodeHandleWidth * 2f, 22f);

            GUI.Label(headerRect, new GUIContent(nodeData.nodeName, nodeData.nodeDescription), nodeHeaderStyle);

            // Draw Node Editor GUI
            GUILayout.BeginArea(new Rect(8f, 32f, nodeData.nodeSize.x - 16f, nodeData.nodeSize.y - 48f));
            if (nodeType != null)
            {
                DialogCanvas tempCanvas = DialogCanvas.CreateCanvas <DialogCanvas>();
                Node         tempNode   = Node.CreateNode(nodeType, Vector2.zero);
                tempCanvas.nodes.Add(tempNode);

                Editor        editor     = Editor.CreateEditor(tempNode);
                NodeInspector nodeEditor = editor as NodeInspector;
                if (nodeEditor != null)
                {
                    nodeEditor.OnDrawNodeGUI(new Rect(0f, 0f, nodeData.nodeSize.x - 16f, nodeData.nodeSize.y - 48f), tempCanvas);
                }
                else
                {
                    editor.OnInspectorGUI();
                }
                DestroyImmediate(editor);
                DestroyImmediate(tempNode);
                DestroyImmediate(tempCanvas);
            }
            else
            {
                GUI.Label(new Rect(0f, 0f, nodeData.nodeSize.x - 16f, nodeData.nodeSize.y - 48f), "No GUI given", nodeHeaderStyle);
            }
            GUILayout.EndArea();

            GUILayout.EndArea();

            // Draw Handles
            DrawHandles(nodeHandles, Northwind.Essentials.VectorMath.Step(nodeData.nodeSize, 16f), ConnectionType.Input);
            DrawHandles(nodeHandles, Northwind.Essentials.VectorMath.Step(nodeData.nodeSize, 16f), ConnectionType.Output);

            GUILayout.EndArea();
        }
Esempio n. 2
0
        /// <summary>
        /// Initiates the Node with a given position
        /// </summary>
        /// <param name="pos">The position this node should start at</param>
        public void InitiateNode(Vector2 pos)
        {
            position = pos;

            object[]          attributes = this.GetType().GetCustomAttributes(false);
            NodeDataAttribute nodeData   = new NodeDataAttribute("", "", 0f, 0f);

            foreach (object attribute in attributes)
            {
                if (attribute.GetType() == typeof(NodeDataAttribute))
                {
                    nodeData = attribute as NodeDataAttribute;
                }
            }

            size = nodeData.nodeSize;
        }
Esempio n. 3
0
        private void OnEnable()
        {
            this.titleContent = new GUIContent("Node Previewer");

            object[]          attributes = previewNodeType.GetCustomAttributes(false);
            NodeDataAttribute nodeData   = new NodeDataAttribute("", "", 0f, 0f);

            foreach (object attribute in attributes)
            {
                if (attribute.GetType() == typeof(NodeDataAttribute))
                {
                    nodeData = attribute as NodeDataAttribute;
                }
            }

            previewNodeData = nodeData;

            this.maxSize = this.minSize = new Vector2(nodeData.nodeSize.x + 64f, nodeData.nodeSize.y + 32f);
        }
        /// <summary>
        /// Collects all Nodes under a specific root folder and returns them in a Dictionary
        /// </summary>
        /// <param name="root">The root folder of the search query</param>
        /// <returns>The relative path and the Node Type</returns>
        public static Dictionary <string, System.Type> CollectNodeTypes(string root)
        {
            Dictionary <string, System.Type> nodeTypes = new Dictionary <string, Type>();

            string[] assets = AssetDatabase.FindAssets("t:MonoScript", new string[] { root });
            for (int a = 0; a < assets.Length; a++)
            {
                string path = AssetDatabase.GUIDToAssetPath(assets[a]);
                if (AssetDatabase.GetMainAssetTypeAtPath(path) == typeof(MonoScript))
                {
                    MonoScript        script             = AssetDatabase.LoadAssetAtPath <MonoScript>(path);
                    object[]          attributes         = script.GetClass().GetCustomAttributes(false);
                    bool              attributeContained = false;
                    NodeDataAttribute nodeData           = null;
                    bool              obsolete           = false;
                    foreach (object attribute in attributes)
                    {
                        if (attribute.GetType() == typeof(NodeDataAttribute))
                        {
                            nodeData           = (NodeDataAttribute)attribute;
                            attributeContained = true;
                        }
                        if (attribute.GetType() == typeof(System.ObsoleteAttribute))
                        {
                            obsolete = true;
                        }
                    }
                    if (script.GetClass().BaseType == typeof(Node) && attributeContained && nodeData != null)
                    {
                        string relativePath = GenerateHomogeneousMenu(root, path, script.GetClass().Name);
                        nodeTypes.Add(relativePath + nodeData.nodeName + (obsolete ? " [Obsolete]" : ""), script.GetClass());
                    }
                }
            }

            return(nodeTypes);
        }
Esempio n. 5
0
 public static void DrawNodePreview(Vector2 origin, System.Type nodeType, NodeDataAttribute nodeData, params NodeHandleAttribute[] nodeHandles)
 {
     GUILayout.BeginArea(new Rect(origin, nodeData.nodeSize + new Vector2(64f, 32f)));
     DrawNodePreview(nodeType, nodeData, nodeHandles);
     GUILayout.EndArea();
 }