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); }
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(); }