// Window GUI function void OnWindowGUI(int id) { // It can update the button position info on a repaint event. var rectUpdate = (Event.current.type == EventType.Repaint); // Draw the inlet labels and buttons. foreach (var inlet in _inlets) { if (inlet.DrawGUI(rectUpdate)) { // The inlet button was pressed; nofity via FeedbackQueue. FeedbackQueue.Enqueue(new FeedbackQueue.InletButtonRecord(this, inlet)); } } // Draw the outlet labels and buttons. foreach (var outlet in _outlets) { if (outlet.DrawGUI(rectUpdate)) { // The outlet button was pressed; nofity via FeedbackQueue. FeedbackQueue.Enqueue(new FeedbackQueue.OutletButtonRecord(this, outlet)); } } // The standard GUI behavior. _controlID = GUIUtility.GetControlID(FocusType.Keyboard); GUI.DragWindow(); // Is this window clicked? if (Event.current.type == EventType.Used) { // Then assume it's active one. _activeWindowID = id; // Grab the keyboard focus. EditorGUIUtility.keyboardControl = _controlID; } var e = Event.current; if (e.GetTypeForControl(_controlID) == EventType.ValidateCommand) { if (e.commandName == "Delete" || e.commandName == "SoftDelete") { e.Use(); } } if (e.GetTypeForControl(_controlID) == EventType.ExecuteCommand) { if (e.commandName == "Delete" || e.commandName == "SoftDelete") { FeedbackQueue.Enqueue(new FeedbackQueue.DeleteNodeRecord(this)); } } }
// GUI function for the main view void DrawMainViewGUI() { FeedbackQueue.Reset(); _scrollMain = EditorGUILayout.BeginScrollView( _scrollMain, false, false, GUIStyles.horizontalScrollbar, GUIStyles.verticalScrollbar, GUIStyles.background ); // Draw the link lines. if (Event.current.type == EventType.Repaint) { foreach (var node in _patch.nodeList) { if (!node.DrawLinkLines(_patch)) { // Request repaint if position info is not ready. Repaint(); break; } } } // Draw all the nodes and make the bounding box. BeginWindows(); foreach (var node in _patch.nodeList) { node.DrawWindowGUI(); _mainViewSize = Vector2.Max(_mainViewSize, node.windowPosition); } EndWindows(); // Place an empty box to expand the scroll view. GUILayout.Box( "", EditorStyles.label, GUILayout.Width(_mainViewSize.x + 256), GUILayout.Height(_mainViewSize.y + 128) ); // Draw working link line while wiring. if (_wiring != null) { DrawWorkingLink(); } EditorGUILayout.EndScrollView(); // Process all the feedback from the leaf UI elements. while (!FeedbackQueue.IsEmpty) { ProcessUIFeedback(FeedbackQueue.Dequeue()); } }