private void DrawNodes() { if (_isLayoutEvent) { _culledNodes = new List <Node>(); } _nodeSizes = new Dictionary <Node, Vector2>(); Color oldColor = GUI.color; //Utilities.BeginZoom(position, Zoom, TopPadding); for (int i = 0; i < _graph.NodeCount; i++) { Node node = _graph.GetNode(i); if (node == null) { continue; } if (i >= _graph.NodeCount) { return; } bool selected = Selection.Contains(node); if (_isLayoutEvent) { if (!selected && ShouldBeCulled(node)) { _culledNodes.Add(node); continue; } } else if (_culledNodes.Contains(node)) { continue; } NodeEditor nodeEditor = NodeEditor.GetEditor(node); Vector2 nodePosition = GridToWindowPositionNotClipped(node.Position); GUILayout.BeginArea(new Rect(nodePosition, new Vector2(nodeEditor.GetWidth(), 4000))); if (selected) { GUIStyle style = new GUIStyle(nodeEditor.GetBodyStyle()); GUIStyle highlightStyle = new GUIStyle(NodeResources.Styles.nodeHighlight) { padding = style.padding }; style.padding = new RectOffset(); GUI.color = nodeEditor.GetTint(); GUILayout.BeginVertical(style); GUI.color = Color.white; GUILayout.BeginVertical(new GUIStyle(highlightStyle)); } else { GUIStyle style = new GUIStyle(nodeEditor.GetBodyStyle()); GUI.color = nodeEditor.GetTint(); GUILayout.BeginVertical(style); } GUI.color = oldColor; EditorGUI.BeginChangeCheck(); nodeEditor.OnHeaderGUI(); nodeEditor.OnBodyGUI(); if (EditorGUI.EndChangeCheck()) { NodeEditor.UpdateCallback(node); EditorUtility.SetDirty(node); nodeEditor.SerializedObject.ApplyModifiedProperties(); } GUILayout.EndVertical(); if (!_isLayoutEvent) { Rect rect = GUILayoutUtility.GetLastRect(); //Debug.Log("Caching Rect: " + rect); _nodeSizes[node] = rect.size; } if (selected) { GUILayout.EndVertical(); } GUILayout.EndArea(); } }
private void MouseUp() { if (!_leftMouseButtonUsed) { if (_rightMouseButtonUsed || _middleMouseButtonUsed) { ContextClick(); } return; } if (IsDraggingPort) { //If the connection is valid, save it if (DraggedOutputTarget != null) { //DraggedOutput.Connect(DraggedOutputTarget) if (Graph.NodeCount != 0) { Connect(DraggedOutput, DraggedOutputTarget); } NodeEditor.UpdateCallback(DraggedOutputTarget.Node); NodeEditor.UpdateCallback(DraggedOutput.Node); } //Release the dragged connection DraggedOutput = null; DraggedOutputTarget = null; EditorUtility.SetDirty(Graph); NodeEditorUtilities.AutoSaveAssets(); } else if (_currentActivity == Activity.Dragging) { Node[] nodes = GetSelected <Node>(); foreach (Node node in nodes) { EditorUtility.SetDirty(node); } NodeEditorUtilities.AutoSaveAssets(); } else if (!IsHoveringConnectionModifier) { //If clicking outside the Con. Mod, release the field focus if (!IsPanning) { EditorGUI.FocusTextInControl(null); } NodeEditorUtilities.AutoSaveAssets(); } else if (!IsHoveringNode) { //If clicking outside the node, release the field focus if (!IsPanning) { EditorGUI.FocusTextInControl(null); } NodeEditorUtilities.AutoSaveAssets(); } if (_currentActivity == Activity.Holding && !(_cachedEvent.control || _cachedEvent.shift)) { if (IsHoveringNode) { Select(_hoveredNode, false); } else if (IsHoveringConnectionModifier) { Select(_hoveredInstruction, false); } } Repaint(); _currentActivity = Activity.Idle; }