private void DrawPlusButtonsOnNode(VisualNodeBase node, int i) { var childIndex = i; var butLabel = i < node.ChildrenLabelsInEditor().Length ? node.ChildrenLabelsInEditor()[i] : "+"; float windowFraction = node.windowPosition.height / node.ChildMax(); var butRect = new Rect( node.windowPosition.xMax, node.windowPosition.y + (i) * (windowFraction) + windowFraction / 2 - 10, Mathf.Min(10 * butLabel.Length + 10, 50), 20); if (GUI.Button(butRect, butLabel)) { new VisualNodeEditorContextMenu((nodeType) => { var newNode = new VisualNodeAssetHelper().CreateNodeAsset(_currentRoot, nodeType); newNode.windowPosition = new Rect(node.windowPosition.xMax + 20, node.windowPosition.y, 150, 0); newNode.parent = node; node.children.RemoveAt(childIndex); node.children.Insert(childIndex, newNode); _currentRoot.nodes.Add(newNode); SaveRootAsset(); SetNodeForSaving(node); SetNodeForSaving(newNode); }).ShowMenu(); } }
void AddNodeToRoot(object o) { var nodeType = (Type)o; var node = new VisualNodeAssetHelper().CreateNodeAsset(_currentRoot, nodeType); node.windowPosition = new Rect(0, 0, 150, 0); node.parent = null; _currentRoot.root = node; _currentRoot.nodes.Add(node); SaveRootAsset(); }
private void HandleContextClick() { if (Event.current.button == 1 && mouseOverWindow == this) { Event.current.Use(); var mousePos = Event.current.mousePosition; new VisualNodeEditorContextMenu((nodeType) => { var newNode = new VisualNodeAssetHelper().CreateNodeAsset(_currentRoot, nodeType); mousePos += scrollPos; newNode.windowPosition = new Rect(mousePos.x, mousePos.y, 150, 0); newNode.parent = null; _currentRoot.nodes.Add(newNode); SaveRootAsset(); }).ShowMenu(); } }