public static Node CreateNodeFromCopyRuntime(NodeCategoryTree.NodeData _nodeData, Node _originalNode, Graph _rootGraph, Graph _graphOwner, string _type) { Node _n = CreateNode(_originalNode.nodeData, _rootGraph, _graphOwner, _type, new Vector2(_originalNode.nodeRect.x, _originalNode.nodeRect.y), true); CopyAll(_originalNode, _n); _n.node = _n; _n.rootGraph = _rootGraph; _n.graphOwner = _graphOwner; _n.inputNodes = new List <Node.InputNode>(); _n.nodeData = new NodeCategoryTree.NodeData(_originalNode.nodeData.title, _originalNode.nodeData.typeName, _originalNode.nodeData.nameSpace, _originalNode.nodeData.category, _originalNode.nodeData.description, _originalNode.nodeData.color, _originalNode.nodeData.outputSlotCount, _originalNode.nodeData.nodeOutputs, _originalNode.nodeData.nodeType); _n.nodeRect = new Rect(_n.nodeRect.position.x + 20, _n.nodeRect.position.y + 20, _n.nodeRect.width, _n.nodeRect.height); return(_n); }
public static Node CreateNodeFromCopy(NodeCategoryTree.NodeData _nodeData, Node _originalNode, Graph _rootGraph, Graph _graphOwner, string _type, int _copyPastNodeOffsetPositionMultiplier) { Node _n = CreateNode(_originalNode.nodeData, _rootGraph, _graphOwner, _type, new Vector2(_originalNode.nodeRect.x, _originalNode.nodeRect.y)); EditorUtility.CopySerialized(_originalNode, _n); _n.node = _n; _n.rootGraph = _rootGraph; _n.graphOwner = _graphOwner; _n.inputNodes = new List <Node.InputNode>(); _n.nodeData = new NodeCategoryTree.NodeData(_originalNode.nodeData.title, _originalNode.nodeData.typeName, _originalNode.nodeData.nameSpace, _originalNode.nodeData.category, _originalNode.nodeData.description, _originalNode.nodeData.color, _originalNode.nodeData.outputSlotCount, _originalNode.nodeData.nodeOutputs, _originalNode.nodeData.nodeType); _n.nodeRect = new Rect(_n.nodeRect.position.x + (20 * _copyPastNodeOffsetPositionMultiplier + 1), _n.nodeRect.position.y + (20 * _copyPastNodeOffsetPositionMultiplier + 1), _n.nodeRect.width, _n.nodeRect.height); return(_n); }
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); }
public static Node CreateNode(NodeCategoryTree.NodeData _nodeData, Graph _rootGraph, Graph _graphOwner, string _type, Vector2 _position) { return(CreateNode(_nodeData, _rootGraph, _graphOwner, _type, _position, false)); }
public static Node CreateNode(NodeCategoryTree.NodeData _nodeData, Graph _rootGraph, Graph graphOwner, string _type) { Vector2 _position = new Vector2(Event.current.mousePosition.x, Event.current.mousePosition.y) * _rootGraph.zoomFactor; return(CreateNode(_nodeData, _rootGraph, graphOwner, _type, _position, false)); }
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(); } }