private void OnGUI() { Event e = Event.current; Matrix4x4 m = GUI.matrix; if (graph == null) { return; } graphEditor = NodeGraphEditor.GetEditor(graph); graphEditor.position = position; Controls(); DrawGrid(position, zoom, panOffset); DrawConnections(); DrawDraggedConnection(); DrawNodes(); DrawSelectionBox(); DrawTooltip(); graphEditor.OnGUI(); // Run and reset onLateGUI if (onLateGUI != null) { onLateGUI(); onLateGUI = null; } GUI.matrix = m; }
/// <summary> Add items for the context menu when right-clicking this node. Override to add custom menu items. </summary> public virtual void AddContextMenuItems(GenericMenu menu) { bool canRemove = true; // Actions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddItem(new GUIContent("Move To Top"), false, () => NodeEditorWindow.current.MoveNodeToTop(node)); menu.AddItem(new GUIContent("Rename"), false, NodeEditorWindow.current.RenameSelectedNode); canRemove = NodeGraphEditor.GetEditor(node.graph, NodeEditorWindow.current).CanRemove(node); } // Add actions to any number of selected nodes menu.AddItem(new GUIContent("Copy"), false, NodeEditorWindow.current.CopySelectedNodes); menu.AddItem(new GUIContent("Duplicate"), false, NodeEditorWindow.current.DuplicateSelectedNodes); if (canRemove) { menu.AddItem(new GUIContent("Remove"), false, NodeEditorWindow.current.RemoveSelectedNodes); } else { menu.AddItem(new GUIContent("Remove"), false, null); } // Custom sctions if only one node is selected if (Selection.objects.Length == 1 && Selection.activeObject is XNode.Node) { XNode.Node node = Selection.activeObject as XNode.Node; menu.AddCustomContextMenuItems(node); } }
/// <summary> Make sure the graph editor is assigned and to the right object </summary> private void ValidateGraphEditor() { NodeGraphEditor graphEditor = NodeGraphEditor.GetEditor(graph, this); if (this.graphEditor != graphEditor) { this.graphEditor = graphEditor; graphEditor.OnOpen(); } }
private void OnGUI() { Event e = Event.current; Matrix4x4 m = GUI.matrix; if (graph == null) { return; } graphEditor = NodeGraphEditor.GetEditor(graph); graphEditor.position = position; Controls(); DrawGrid(position, zoom, panOffset); DrawConnections(); DrawDraggedConnection(); try { DrawNodes(); } catch {} DrawSelectionBox(); DrawTooltip(); graphEditor.OnGUI(); GUI.matrix = m; }
private void OnOpened() { if (graph != null) { var editor = NodeGraphEditor.GetEditor(graph); editor.OnOpened(this); } }
void OnFocus() { current = this; graphEditor = NodeGraphEditor.GetEditor(graph); if (graphEditor != null && NodeEditorPreferences.GetSettings().autoSave) { AssetDatabase.SaveAssets(); } }
/// <summary> Make sure the graph editor is assigned and to the right object </summary> private void ValidateGraphEditor() { NodeGraphEditor graphEditor = NodeGraphEditor.GetEditor(graph, this); if (this.graphEditor != graphEditor && graphEditor != null) { var oldgraphEditor = this.graphEditor; this.graphEditor = graphEditor; oldgraphEditor?.OnClose(); graphEditor.OnOpen(); } }
/// <summary> Make a simple port field. </summary> public static void PortField(GUIContent label, XNode.NodePort port, params GUILayoutOption[] options) { if (port == null) { return; } if (label == null) { EditorGUILayout.LabelField(ObjectNames.NicifyVariableName(port.fieldName), options); } else { EditorGUILayout.LabelField(label, options); } Rect rect = GUILayoutUtility.GetLastRect(); if (port.direction == XNode.NodePort.IO.Input) { rect.position = rect.position - new Vector2(16, 0); } else if (port.direction == XNode.NodePort.IO.Output) { rect.position = rect.position + new Vector2(rect.width, 0); } rect.size = new Vector2(16, 16); Color backgroundColor = new Color32(90, 97, 105, 255); if (NodeEditorWindow.nodeTint.ContainsKey(port.node.GetType())) { backgroundColor *= NodeEditorWindow.nodeTint[port.node.GetType()]; } Color col = NodeGraphEditor.GetEditor(port.node.graph).GetTypeColor(port.ValueType); DrawPortHandle(rect, backgroundColor, col); // Register the handle position Vector2 portPos = rect.center; if (NodeEditor.portPositions.ContainsKey(port)) { NodeEditor.portPositions[port] = portPos; } else { NodeEditor.portPositions.Add(port, portPos); } }
private void OnGUI() { Event e = Event.current; Matrix4x4 m = GUI.matrix; if (graph == null) { return; } graphEditor = NodeGraphEditor.GetEditor(graph); if (graphEditor == null) { return; } graphEditor.position = position; Controls(); DrawGrid(position, zoom, panOffset); DrawConnections(); DrawDraggedConnection(); DrawNodes(); DrawSelectionBox(); DrawTooltip(); graphEditor.OnGUI(); if (currentActivity == NodeActivity.AddingNode) { BeginWindows(); contextWindowRect = new Rect(contextMenuMousePos, Vector2.one * 400); // All GUI.Window or GUILayout.Window must come inside here contextWindowRect = GUILayout.Window(1, contextWindowRect, DrawWindow, "Add node"); EndWindows(); } // Run and reset onLateGUI if (onLateGUI != null) { onLateGUI(); onLateGUI = null; } GUI.matrix = m; }
/// <summary> Make sure the graph editor is assigned and to the right object </summary> private void ValidateGraphEditor() { if (graph is DialogGraph) { DialogGraphEditor graphEditor = (DialogGraphEditor)DialogGraphEditor.GetEditor(graph, this); if (this.graphEditor != graphEditor && graphEditor != null) { this.graphEditor = graphEditor; graphEditor.OnOpen(); } } else { NodeGraphEditor graphEditor = NodeGraphEditor.GetEditor(graph, this); if (this.graphEditor != graphEditor && graphEditor != null) { this.graphEditor = graphEditor; graphEditor.OnOpen(); } } }
/// <summary> Make a field for a serialized property. Manual node port override. </summary> public static void PropertyField(SerializedProperty property, GUIContent label, XNode.NodePort port, bool includeChildren = true, params GUILayoutOption[] options) { if (property == null) { throw new NullReferenceException(); } // If property is not a port, display a regular property field if (port == null) { EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } else { Rect rect = new Rect(); // If property is an input, display a regular property field and put a port handle on the left side if (port.direction == XNode.NodePort.IO.Input) { // Get data from [Input] attribute XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; XNode.Node.InputAttribute inputAttribute; if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out inputAttribute)) { showBacking = inputAttribute.backingValue; } switch (showBacking) { case XNode.Node.ShowBackingValue.Unconnected: // Display a label if port is connected if (port.IsConnected) { EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); } // Display an editable property field if port is not connected else { EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } break; case XNode.Node.ShowBackingValue.Never: // Display a label EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName)); break; case XNode.Node.ShowBackingValue.Always: // Display an editable property field EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; } rect = GUILayoutUtility.GetLastRect(); rect.position = rect.position - new Vector2(16, 0); // If property is an output, display a text label and put a port handle on the right side } else if (port.direction == XNode.NodePort.IO.Output) { // Get data from [Output] attribute XNode.Node.ShowBackingValue showBacking = XNode.Node.ShowBackingValue.Unconnected; XNode.Node.OutputAttribute outputAttribute; if (NodeEditorUtilities.GetAttrib(port.node.GetType(), property.name, out outputAttribute)) { showBacking = outputAttribute.backingValue; } switch (showBacking) { case XNode.Node.ShowBackingValue.Unconnected: // Display a label if port is connected if (port.IsConnected) { EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30)); } // Display an editable property field if port is not connected else { EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); } break; case XNode.Node.ShowBackingValue.Never: // Display a label EditorGUILayout.LabelField(label != null ? label : new GUIContent(property.displayName), NodeEditorResources.styles.outputPort, GUILayout.MinWidth(30)); break; case XNode.Node.ShowBackingValue.Always: // Display an editable property field EditorGUILayout.PropertyField(property, label, includeChildren, GUILayout.MinWidth(30)); break; } rect = GUILayoutUtility.GetLastRect(); rect.position = rect.position + new Vector2(rect.width, 0); } rect.size = new Vector2(16, 16); Color backgroundColor = new Color32(90, 97, 105, 255); if (NodeEditorWindow.nodeTint.ContainsKey(port.node.GetType())) { backgroundColor *= NodeEditorWindow.nodeTint[port.node.GetType()]; } Color col = NodeGraphEditor.GetEditor(port.node.graph).GetTypeColor(port.ValueType); DrawPortHandle(rect, backgroundColor, col); // Register the handle position Vector2 portPos = rect.center; if (NodeEditor.portPositions.ContainsKey(port)) { NodeEditor.portPositions[port] = portPos; } else { NodeEditor.portPositions.Add(port, portPos); } } }