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