Esempio n. 1
0
            void DrawCategories(NodeCategoryTree tree, int depth)
            {
                using (new GUILayout.HorizontalScope())
                {
                    if (tree.Path.Contains("Favorites"))
                    {
                        if (GUILayout.Button(new GUIContent(" " + tree.Path, favoriteIcon), FlowReactorEditorStyles.elementButtonBold, GUILayout.ExpandWidth(true), GUILayout.Height(25)))
                        {
                            tree.FoldOut = !tree.FoldOut;

                            currentDepth    = depth + 1;
                            currentPath     = tree.Path;
                            currentCategory = tree;
                        }
                    }
                    else
                    {
                        if (GUILayout.Button(tree.Path, FlowReactorEditorStyles.elementButtonBold, GUILayout.ExpandWidth(true), GUILayout.Height(25)))
                        {
                            tree.FoldOut = !tree.FoldOut;

                            currentDepth    = depth + 1;
                            currentPath     = tree.Path;
                            currentCategory = tree;
                        }
                    }


                    var _l = GUILayoutUtility.GetLastRect();
                    GUI.Label(new Rect(_l.width - 20, _l.y, _l.width, _l.height), ">");
                }
            }
Esempio n. 2
0
 public void Draw(NodeCategoryTree tree)
 {
     if (stopTraversing)
     {
         return;
     }
     tree.Traverse(DrawGUI);
 }
Esempio n. 3
0
        public static void CreateDefaultNodes(NodeCategoryTree _tree, Graph _graph)
        {
            var _nodeData = _tree.GetData("OnStart");

            NodeCreator.CreateNode(_nodeData, _graph, _graph, "OnStart", new Vector2(100, 100));

            _graph.parentLevels = new List <Graph.ParentLevels>();
            _graph.parentLevels.Add(new Graph.ParentLevels(_graph.name, _graph));
        }
Esempio n. 4
0
            void DrawFavoriteButton(NodeCategoryTree tree, int nodeCategoryIndex)
            {
                if (settings.favoredNodes == null)
                {
                    settings.favoredNodes = new List <NodeCategoryTree.NodeData>();
                }
                var _exists     = false;
                int _existIndex = 0;

                for (int f = 0; f < settings.favoredNodes.Count; f++)
                {
                    if (settings.favoredNodes[f].title == tree.nodesInCategory[nodeCategoryIndex].title)
                    {
                        _exists     = true;
                        _existIndex = f;
                        break;
                    }
                }

                var _favSkin = "FavoritDeactive";

                if (_exists)
                {
                    _favSkin = "FavoritActive";
                }

                if (GUILayout.Button("", editorSkin.GetStyle(_favSkin)))
                {
                    if (!_exists)
                    {
                        settings.favoredNodes.Add(tree.nodesInCategory[nodeCategoryIndex]);
                    }
                    else
                    {
                        settings.favoredNodes.RemoveAt(_existIndex);
                    }

                    favoritePath = tree.Path;

                    if (tree.Path.Contains("Favorites"))
                    {
                        stopTraversing = true;
                        UpdateFavourites();
                    }

                    currentPath = favoritePath;
                }
            }
        public NodeCategoryTree BuildTree(string _path, string _name)
        {
            //Debug.Log("build tree " + _path);
            // Parse into a sequence of parts.
            string[] parts = _path.Split("/"[0]);

            // The current tree.  Start with this.
            NodeCategoryTree current = this;



            // Iterate through the parts.
            foreach (string part in parts)
            {
                // The child GraphTree.
                NodeCategoryTree child;

                // Does the part exist in the current GraphTree?  If
                // not, then add.
                if (!current.categories.TryGetValue(part, out child))
                {
                    //Debug.Log(part + " does not exist");

                    var n = _name;
                    //if (part != parts[parts.Length-1])
                    //{
                    //	n = part;
                    //}

                    // Add the child.
                    child = new NodeCategoryTree {
                        Path            = part,
                        Name            = _name,
                        parentGraphTree = current
                    };

                    // Add to the dictionary.
                    current.categories[part] = child;
                }

                // Set the current to the child.
                current = child;
            }

            return(current);
        }
Esempio n. 6
0
        public static Node CreateNode(NodeCategoryTree.NodeData _nodeData, Graph _rootGraph, Graph _graphOwner, string _type, Vector2 _position, bool _isCopy)
        {
            if (_nodeData == null)
            {
                allNodes  = CollectAvailableNodes.CollectNodes();
                _nodeData = allNodes.GetData(_type);
            }

            Node node = Node.CreateNode(_type, _nodeData.typeName);

            // Assign attributes to node
            node.outputNodes = new List <Node.NodeOutput>();            //(_nodeAttributes.outputSlotCount);
            if (_nodeData.outputSlotCount > -1)
            {
                for (int i = 0; i < _nodeData.outputSlotCount; i++)
                {
                    node.outputNodes.Add(new Node.NodeOutput());
                }
            }
            if (_nodeData.nodeOutputs != null)
            {
                for (int i = 0; i < _nodeData.nodeOutputs.Length; i++)
                {
                    node.outputNodes.Add(new Node.NodeOutput(_nodeData.nodeOutputs[i]));
                }
            }


            //_position = new Vector2(_position.x / _rootGraph.zoomFactor, _position.y / _rootGraph.zoomFactor);

            node.inputNodes = new List <Node.InputNode>();
            node.nodeRect   = new Rect(_position.x, _position.y, node.nodeRect.width, node.nodeRect.height);

            // Get settings
            var _editorSettings = (FREditorSettings)FREditorSettings.GetSerializedSettings().targetObject as FREditorSettings;

            node.color    = _editorSettings.GetColor(_nodeData.color);
            node.nodeData = _nodeData;
            node.isCopy   = _isCopy;
            node.guid     = Guid.NewGuid().ToString();

            _graphOwner.AddNode(node);

            node.rootGraph  = _rootGraph;
            node.graphOwner = _graphOwner;
            //node.nodeStringType = _type;
            if (!_isCopy)
            {
                node.Init(_rootGraph, node);                 // _graphOwner.nodes.Count, node);
            }

            if (node.outputNodes.Count > 1)
            {
                node.nodeRect.height += (node.outputNodes.Count - 1) * 20;
            }

            node.SetupVariables();

            // check if newly created node has been created inside a group
            // if true, add new node to this group
            for (int n = 0; n < _rootGraph.currentGraph.nodes.Count; n++)
            {
                if (_rootGraph.currentGraph.nodes[n].nodeData.nodeType == NodeAttributes.NodeType.Group &&
                    _rootGraph.currentGraph.nodes[n] != node && _rootGraph.currentGraph.nodes[n].nodeRect.Contains(new Vector2(node.nodeRect.x, node.nodeRect.y)))
                {
                    var _g = _rootGraph.currentGraph.nodes[n] as Group;
                    _g.AddNodeToGroup(node);
                }
            }

            EditorUtility.SetDirty(node);
            EditorUtility.SetDirty(_rootGraph);

            node.lastZoomCoordsOrigin = _rootGraph.currentGraph.zoomCoordsOrigin;

            // Better than AssetDatabase SaveAsset or Refresh for refreshing node
            Undo.SetCurrentGroupName("Create Node");
            int undoGroup = Undo.GetCurrentGroup();

            Undo.RecordObject(node, "Create Node");
            Undo.CollapseUndoOperations(undoGroup);


            return(node);
        }
Esempio n. 7
0
            void DrawInternal()
            {
                GUILayout.Label("Nodes", FlowReactorEditorStyles.elementButtonBack, GUILayout.Height(20));

                GUILayout.Space(5);
                //if (currentCategory != null)
                //{
                //GUILayout.Label(currentPath + " " + currentDepth + " " + currentCategory.Path);
                //}
                using (new GUILayout.HorizontalScope())
                {
                    GUI.SetNextControlName("Filter");

                    EditorGUI.FocusTextInControl("Filter");
                    filter = GUILayout.TextField(filter, "SearchTextField");

                    if (GUILayout.Button("", GUI.skin.FindStyle("SearchCancelButton")))
                    {
                        firstNodeName = "";
                        filter        = "";

                        favoritePath = "";
                        filterReset  = false;
                        currentDepth = 0;

                        collectedNodes = CollectAvailableNodes.CollectNodes();
                    }


                    if (string.IsNullOrEmpty(filter) && !filterReset)
                    {
                        filterReset    = true;
                        firstNodeName  = "";
                        collectedNodes = CollectAvailableNodes.CollectNodes();
                    }
                    else if (!string.IsNullOrEmpty(filter) && filterReset)
                    {
                        filterReset = false;
                    }
                }

                GUILayout.Space(5);


                if (string.IsNullOrEmpty(filter))
                {
                    if (currentDepth - 1 >= 0)
                    {
                        // button back
                        if (GUILayout.Button(currentCategory.Path, FlowReactorEditorStyles.elementButtonBack, GUILayout.Height(25)))
                        {
                            currentDepth--;
                            currentPath             = currentCategory.parentGraphTree.Path;
                            currentCategory.FoldOut = false;
                            currentCategory         = currentCategory.parentGraphTree;

                            if (currentDepth == 0)
                            {
                                collectedNodes = CollectAvailableNodes.CollectNodes();
                            }
                        }


                        var _l = GUILayoutUtility.GetLastRect();
                        GUI.Label(new Rect(_l.x, _l.y, _l.width, _l.height), "<");                         // NodePanelStyles.leftArrow.normal.background);
                    }
                }

                using (var scrollView = new GUILayout.ScrollViewScope(scrollPosition))
                {
                    scrollPosition = scrollView.scrollPosition;


                    Draw(collectedNodes);
                }

                GUILayout.Label(description, "textArea");

                editorWindow.Repaint();
            }
Esempio n. 8
0
            void DrawGUI(int depth, NodeCategoryTree tree)
            {
                if (depth == -1)
                {
                    return;
                }


                // if search filter is empty draw categories and its nodes
                if (string.IsNullOrEmpty(filter))
                {
                    if (depth == currentDepth && currentPath == tree.parentGraphTree.Path)
                    {
                        if (tree.Path.Contains("Internal"))
                        {
                            return;
                        }

                        DrawCategories(tree, depth);
                    }

                    if (depth != currentDepth && currentPath != tree.parentGraphTree.Path)
                    {
                        if (currentPath == tree.Path)
                        {
                            if (currentPath == favoritePath)
                            {
                                tree.FoldOut = true;
                                favoritePath = "";
                            }

                            if (tree.FoldOut)
                            {
                                for (int n = 0; n < tree.nodesInCategory.Count; n++)
                                {
                                    if (string.IsNullOrEmpty(firstNodeName))
                                    {
                                        firstNodeName     = tree.nodesInCategory[n].title;
                                        firstNodePosition = new Vector2(rect.x - (graph.showInspector ? graph.tmpInspectorWidth : 0), rect.y - rect.height);
                                    }

                                    using (new GUILayout.HorizontalScope())
                                    {
                                        //if (settings.favoredNodes == null)
                                        //{
                                        //	settings.favoredNodes = new List<NodeCategoryTree.NodeData>();
                                        //}
                                        //var _exists = false;
                                        //int _existIndex = 0;
                                        //for (int f = 0; f < settings.favoredNodes.Count; f ++)
                                        //{
                                        //	if (settings.favoredNodes[f].name == tree.nodesInCategory[n].name)
                                        //	{
                                        //		_exists = true;
                                        //		_existIndex = f;
                                        //		break;
                                        //	}
                                        //}

                                        //var _favSkin = "FavouritDeactive";
                                        //if (_exists)
                                        //{
                                        //	_favSkin = "FavouritActive";
                                        //}

                                        //if (GUILayout.Button("", editorSkin.GetStyle(_favSkin)))
                                        //{
                                        //	if (!_exists)
                                        //	{
                                        //		settings.favoredNodes.Add(tree.nodesInCategory[n]);
                                        //	}
                                        //	else
                                        //	{
                                        //		settings.favoredNodes.RemoveAt(_existIndex);
                                        //	}

                                        //	//favouritDepth = depth;
                                        //	favouritPath = tree.Path;
                                        //	//favouritTree = tree;

                                        //	if (tree.Path.Contains("Favourites"))
                                        //	{
                                        //		stopTraversing = true;
                                        //		UpdateFavourites();
                                        //	}

                                        //	currentPath = favouritPath;

                                        //}

                                        DrawFavoriteButton(tree, n);

                                        //Debug.Log("hello");
                                        if (GUILayout.Button(tree.nodesInCategory[n].title, FlowReactorEditorStyles.elementButton))                                         //NodePanelStyles.elementButton, GUILayout.Height(25)))
                                        {
                                            Vector2 _position;

                                            _position = new Vector2(rect.x - (graph.showInspector ? graph.tmpInspectorWidth : 0), rect.y - (rect.height * graph.zoomFactor));
                                                                                        #if FLOWREACTOR_DEBUG
                                            Debug.Log("create");
                                                                                        #endif


                                            newNode = NodeCreator.CreateNode(tree.nodesInCategory[n], graph, graph.currentGraph, tree.nodesInCategory[n].nameSpace + "." + tree.nodesInCategory[n].typeName, _position);

                                            graph.nodeSelectionPanelOpen = false;
                                            createdNewNode = true;

                                            editorWindow.Close();
                                        }
                                    }

                                    var _lastRect = GUILayoutUtility.GetLastRect();
                                    if (_lastRect.Contains(Event.current.mousePosition))
                                    {
                                        description = tree.nodesInCategory[n].description;
                                    }
                                }
                            }
                        }
                    }
                }
                // if search filter is not null only show all nodes in one list
                else
                {
                    tree.FoldOut = true;

                    bool _found = false;
                    for (int n = 0; n < tree.nodesInCategory.Count; n++)
                    {
                        if (tree.Path.Contains("Internal"))
                        {
                            return;
                        }

                        if (tree.nodesInCategory[n].title.ToLower().Contains(filter.ToLower()))
                        {
                            _found = true;
                        }
                    }


                    if (_found)
                    {
                        GUILayout.Label(tree.parentGraphTree.Path + " / " + tree.Path, "boldLabel");
                        EditorHelpers.DrawUILine();
                    }

                    for (int n = 0; n < tree.nodesInCategory.Count; n++)
                    {
                        if (tree.nodesInCategory[n].title.ToLower().Contains(filter.ToLower()))
                        {
                            if (filter != lastFilter)
                            {
                                firstNodeName = "";
                            }
                            if (string.IsNullOrEmpty(firstNodeName))
                            {
                                lastFilter        = filter;
                                firstNodeName     = tree.nodesInCategory[n].title;
                                firstNodeData     = tree.nodesInCategory[n];
                                firstNodePosition = new Vector2(rect.x - (graph.showInspector ? graph.tmpInspectorWidth : 0), rect.y - rect.height);
                            }


                            using (new GUILayout.HorizontalScope())
                            {
                                DrawFavoriteButton(tree, n);


                                //GUILayout.Label(tree.nodesInCategory[n].name);
                                if (GUILayout.Button(tree.nodesInCategory[n].title, FlowReactorEditorStyles.elementButton))
                                {
                                    Vector2 _position;

                                    //_position = new Vector2((rect.x / graph.zoomFactor) - (graph.showInspector ? (graph.tmpInspectorWidth / graph.zoomFactor): 0), (rect.y / graph.zoomFactor) - (rect.height / graph.zoomFactor)); // (rect.height / graph.zoomFactor));
                                    _position = new Vector2((rect.x / graph.zoomFactor) - (graph.tmpInspectorWidth / graph.zoomFactor), (rect.y / graph.zoomFactor) - (rect.height / graph.zoomFactor) - 20);                                     // (rect.height / graph.zoomFactor));

                                                                        #if FLOWREACTOR_DEBUG
                                    Debug.Log("create " + _position);
                                                                        #endif

                                    newNode = NodeCreator.CreateNode(tree.nodesInCategory[n], graph, graph.currentGraph, tree.nodesInCategory[n].nameSpace + "." + tree.nodesInCategory[n].typeName, _position);

                                    //frEditor.showNodePanelMouse = false;
                                    graph.nodeSelectionPanelOpen = false;
                                    createdNewNode = true;

                                    editorWindow.Close();
                                }
                                var _lastRect = GUILayoutUtility.GetLastRect();
                                if (_lastRect.Contains(Event.current.mousePosition))
                                {
                                    description = tree.nodesInCategory[n].description;
                                }
                            }
                        }
                    }
                }


                var _e = Event.current;
                if (_e.isKey && _e.keyCode == KeyCode.Return && !string.IsNullOrEmpty(firstNodeName))
                {
                    _e.Use();

                    newNode = NodeCreator.CreateNode(firstNodeData, graph, graph.currentGraph, firstNodeData.nameSpace + "." + firstNodeName, firstNodePosition);

                    graph.nodeSelectionPanelOpen = false;
                    createdNewNode = true;

                    firstNodeName = "";

                    editorWindow.Close();
                }
            }
Esempio n. 9
0
        public static NodeCategoryTree CollectNodes()
        {
            collectedNodes = new NodeCategoryTree();

            var _found = System.AppDomain.CurrentDomain.FlowReactorGetAllDerivedTypes(typeof(Node));

            //System.Type[] _types = System.Reflection.Assembly.GetExecutingAssembly().GetTypes();
            //System.Type[] _found = (from System.Type type in _types where type.IsSubclassOf(typeof(Node)) select type).ToArray();


            List <CollectedNodesData> collected = new List <CollectedNodesData>();

            for (int i = 0; i < _found.Length; i++)
            {
                NodeAttributes _nodeAttributes = System.Attribute.GetCustomAttribute(_found[i], typeof(NodeAttributes)) as NodeAttributes;

                if (_nodeAttributes != null)
                {
                    collected.Add(new CollectedNodesData(
                                      _found[i].Name.ToString(),           // Title
                                      _found[i].Name.ToString(),           // type name
                                      _found[i].Namespace,
                                      _nodeAttributes.category,
                                      _nodeAttributes.description,
                                      _nodeAttributes.color,
                                      _nodeAttributes.outputSlotCount,
                                      _nodeAttributes.nodeOutputs,
                                      _nodeAttributes.nodeType));
                }
            }

            // Sort by categories
            collected = collected.OrderBy(c => c.category).ToList();

            // Add favorit nodes
            var _settings = (FREditorSettings)FREditorSettings.GetOrCreateSettings();

            if (_settings.favoredNodes == null)
            {
                _settings.favoredNodes = new List <NodeCategoryTree.NodeData>();
            }

            for (int f = 0; f < _settings.favoredNodes.Count; f++)
            {
                collected.Insert(0, new CollectedNodesData
                                 (
                                     //_settings.favoredNodes[f].name,
                                     _settings.favoredNodes[f].title,
                                     _settings.favoredNodes[f].typeName,
                                     _settings.favoredNodes[f].nameSpace,
                                     "Favorites",
                                     _settings.favoredNodes[f].description,
                                     _settings.favoredNodes[f].color,
                                     _settings.favoredNodes[f].outputSlotCount,
                                     _settings.favoredNodes[f].nodeOutputs,
                                     _settings.favoredNodes[f].nodeType

                                 ));
            }

            for (int c = 0; c < collected.Count; c++)
            {
                var _child = collectedNodes.BuildTree(collected[c].category, collected[c].name);

                _child.AddNode
                (
                    //collected[c].name,
                    collected[c].title,
                    collected[c].typeName,
                    collected[c].nameSpace,
                    collected[c].category,
                    collected[c].description,
                    collected[c].color,
                    collected[c].outputCount,
                    collected[c].nodeOutputs,
                    collected[c].nodeType
                );
            }

            return(collectedNodes);
        }