private static void InputGUI() { Event current = Event.current; if (target) { switch (current.type) { case EventType.DragUpdated: case EventType.DragPerform: if (current.button == 0) { if (DragAndDrop.objectReferences.Length > 0) { if (DragAndDrop.objectReferences[0] is GraphAsset) { if (current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); GraphController controller = UndoManager.AddComponent <GraphController>(target); controller.graph = (GraphAsset)DragAndDrop.objectReferences[0]; EditorGUIUtility.PingObject(controller); Selection.activeGameObject = target; set_dirty = true; current.Use(); if (Application.isPlaying) { controller.OnControllerEnable(); } } DragAndDrop.PrepareStartDrag(); } } } break; } } }
private static void HierarchyIndex(int instance_id, Rect index_rect) { Event current = Event.current; if (styles == null) { styles = new Styles(); } target = EditorUtility.InstanceIDToObject(instance_id) as GameObject; if (index_rect.Contains(current.mousePosition)) { InputGUI(); } if (target) { if (target.GetComponent <GraphController>()) { int graph_count = target.GetComponents <GraphController>().Length; Rect rect = new Rect(index_rect.width - 10.0f, index_rect.y - 2.0f, 20.0f, 20.0f); GUIContent content = new GUIContent(graph_count > 1 ? graph_count.ToString() : string.Empty, string.Empty); if (GUI.Button(rect, content, styles.icon)) { Selection.activeObject = target; GraphEditorWindow.OpenEditor(target.GetComponent <GraphController>().graph); } } if (set_dirty) { UndoManager.SetDirty(target); set_dirty = false; } } target = null; }
public static void QuickPlugPort(Port port, Node node) { UndoManager.RecordObject(asset, string.Format("{0} > {1}: {2} Plug", asset.name, node.name, port.name)); foreach (Port p in node.portValues) { if (p is IPlugOut && port is IPlugIn) { if (((IPlugIn)port).CanPlug((IPlugOut)p, false)) { ((IPlugIn)port).PlugTo((IPlugOut)p); break; } } else if (p is IPlugIn && port is IPlugOut) { if (((IPlugIn)p).CanPlug((IPlugOut)port, false)) { ((IPlugIn)p).PlugTo((IPlugOut)port); break; } } } UndoManager.SetDirty(asset); }
public override void OnInspectorGUI() { GraphController controller = (GraphController)target; GraphAsset graph = controller.graph; OnEnableAction on_enable = controller.on_enable; bool once = controller.once; float seconds = controller.seconds; OnDisableAction on_disable = controller.on_disable; controller.CopyParameters(); graph = (GraphAsset)EditorGUILayout.ObjectField(new GUIContent("Graph"), controller.graph, typeof(GraphAsset), false); if (controller.graph != graph) { controller.OnGraphChange(controller.graph, graph); } if (controller.graph) { on_enable = (OnEnableAction)EditorGUILayout.EnumPopup(new GUIContent("OnEnable"), controller.on_enable); switch (on_enable) { case OnEnableAction.DoNothing: case OnEnableAction.PlayGraph: if (height != 0.0f) { height = 0.0f; EditorUtils.RepaintInspector(); } seconds = 0.0f; break; case OnEnableAction.WaitForSeconds: GUILayout.BeginVertical("Box"); if (height != EditorGUIUtility.singleLineHeight) { height = Mathf.MoveTowards(height, EditorGUIUtility.singleLineHeight, 1.0f); EditorUtils.RepaintInspector(); } once = EditorGUILayout.Toggle(new GUIContent("Only Once"), controller.once, GUILayout.Height(height)); seconds = EditorGUILayout.FloatField(new GUIContent("Seconds"), controller.seconds, GUILayout.Height(height)); GUILayout.EndVertical(); break; } on_disable = (OnDisableAction)EditorGUILayout.EnumPopup(new GUIContent("OnDisable"), controller.on_disable); GUILayout.BeginHorizontal(); if (GUILayout.Button("Ping to Asset")) { EditorGUIUtility.PingObject(controller.graph); } if (GUILayout.Button("Open in Editor")) { GraphEditorWindow.OpenEditor(controller.graph); } GUILayout.EndHorizontal(); } GUILayout.BeginHorizontal("RL Header"); { GUILayout.Space(15.0f); GUILayout.BeginVertical(); { foldout = EditorGUILayout.Foldout(foldout, new GUIContent(string.Format("Variables [{0}]", controller.properties.Values.Where(p => p.is_public).Count()))); } GUILayout.EndVertical(); if (GUILayout.Toggle(debug, debug ? "Debug" : "Normal", (GUIStyle)"minibutton") != debug) { debug = !debug; } } GUILayout.EndHorizontal(); if (foldout) { GUILayout.BeginHorizontal("RL Background", GUILayout.MinHeight(10.0f)); { GUILayout.Space(10.0f); GUILayout.BeginVertical(); { foreach (VariableObject property in controller.properties.Values.ToList()) { if (property.is_public || debug) { object last_value = property.GetValue(); object new_value = GUIDraw.AnyField(last_value, property.valueType, debug ? property.name + string.Format(" (ID = {0}, Type = {1})", property.id, property.valueType.GetTypeName(true, true)) : property.name); if (new_value != last_value) { UndoManager.RecordObject(target, "Change Value"); property.SetValue(new_value); } } } } GUILayout.Space(5.0f); GUILayout.EndVertical(); } GUILayout.EndHorizontal(); } if (GUI.changed) { UndoManager.RecordObject(target, "GraphController Inspector"); controller.graph = graph; controller.on_enable = on_enable; controller.once = once; controller.seconds = seconds; controller.on_disable = on_disable; UndoManager.SetDirty(target); } }
public override void OnInspectorGUI() { bool restore_wide_mode = EditorGUIUtility.wideMode; EditorGUIUtility.wideMode = true; EditorGUIUtility.labelWidth = 0.0f; EditorGUIUtility.fieldWidth = 0.0f; if (GUILayout.Button("Open in Editor")) { GraphEditorWindow.OpenEditor(asset); } try { DrawMenuMode(); GUILayout.Space(5.0f); switch (currentMenu) { //Graph case 0: string title = EditorGUILayout.TextField(asset.title); GUIDraw.GhostLabel(title, "Title...", -2.0f, 5.0f); if (title != asset.title) { UndoManager.RecordObject(target, "Title Change"); asset.title = title; GraphEditor.current_validate = true; } GUILayout.Space(3.0f); string subtitle = EditorGUILayout.TextArea(asset.subtitle, GUILayout.MinHeight(50.0f)); GUIDraw.GhostLabel(subtitle, "Subtitle...", -2.0f, 5.0f); if (subtitle != asset.subtitle) { UndoManager.RecordObject(target, "Subtitle Change"); asset.subtitle = subtitle; GraphEditor.current_validate = true; } GUILayout.Label(string.Format("Nodes: {0}", asset.graph.nodes.Count.ToString())); break; //Parameters case 1: input_list.DoLayoutList(); output_list.DoLayoutList(); break; //Variables case 2: variable_list.DoLayoutList(); break; //Node Inspector case 3: DrawNodeInspector(); break; } } catch { CreateReorderableLists(); GraphEditor.current_validate = true; } if (GUI.changed) { UndoManager.SetDirty(target); GUI.changed = false; } EditorGUIUtility.wideMode = restore_wide_mode; }
private void CreateReorderableLists() { GraphAsset asset = (GraphAsset)target; variable_list = new ReorderableList(asset.graph.variableParameters, typeof(Parameter), true, true, true, true); input_list = new ReorderableList(asset.graph.inputParameters, typeof(Parameter), true, true, true, true); output_list = new ReorderableList(asset.graph.outputParameters, typeof(Parameter), true, true, true, true); variable_list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Variables Parameters"); }; input_list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Input Parameters"); }; output_list.drawHeaderCallback = rect => { EditorGUI.LabelField(rect, "Output Parameters"); }; variable_list.onReorderCallback = list => { GraphEditor.current_validate = true; }; input_list.onReorderCallback = list => { GraphEditor.current_validate = true; }; output_list.onReorderCallback = list => { GraphEditor.current_validate = true; }; variable_list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.height = EditorGUIUtility.singleLineHeight; Rect rect_declaring = new Rect(rect.x, rect.y, 10.0f, EditorGUIUtility.singleLineHeight); rect.y += 2; Rect rect_name = new Rect(rect.x + 20.0f, rect.y, rect.width / 2.0f, EditorGUIUtility.singleLineHeight); Rect rect_type = new Rect(rect.x + rect.width / 2.0f + 30.0f, rect.y, rect.width - (rect.width / 2.0f + 30.0f), EditorGUIUtility.singleLineHeight); string new_name = EditorGUI.TextField(rect_name, asset.graph.variableParameters[index].name); bool new_declaring_value = EditorGUI.Toggle(rect_declaring, asset.graph.variableParameters[index].is_public); if (new_name != asset.graph.variableParameters[index].name) { UndoManager.RecordObject(asset, "Variable Name Change"); asset.graph.variableParameters[index].name = new_name; GraphEditor.current_validate = true; } if (new_declaring_value != asset.graph.variableParameters[index].is_public) { UndoManager.RecordObject(asset, "Variable Declaring Type Change"); asset.graph.variableParameters[index].is_public = new_declaring_value; GraphEditor.current_validate = true; } GUI.Label(rect_type, asset.graph.variableParameters[index].valueType.GetTypeName()); }; input_list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.height = EditorGUIUtility.singleLineHeight; Rect rect_declaring = new Rect(rect.x, rect.y, 10.0f, EditorGUIUtility.singleLineHeight); rect.y += 2; Rect rect_name = new Rect(rect.x + 20.0f, rect.y, rect.width / 2.0f, EditorGUIUtility.singleLineHeight); Rect rect_type = new Rect(rect.x + rect.width / 2.0f + 30.0f, rect.y, rect.width - (rect.width / 2.0f + 30.0f), EditorGUIUtility.singleLineHeight); string new_name = EditorGUI.TextField(rect_name, asset.graph.inputParameters[index].name); bool new_declaring_value = EditorGUI.Toggle(rect_declaring, asset.graph.inputParameters[index].is_public); if (new_name != asset.graph.inputParameters[index].name) { UndoManager.RecordObject(asset, "Input Parameter Name Change"); asset.graph.inputParameters[index].name = new_name; GraphEditor.current_validate = true; } if (new_declaring_value != asset.graph.inputParameters[index].is_public) { UndoManager.RecordObject(asset, "Input Parameter Declaring Type Change"); asset.graph.inputParameters[index].is_public = new_declaring_value; GraphEditor.current_validate = true; } GUI.Label(rect_type, asset.graph.inputParameters[index].valueType.GetTypeName()); }; output_list.drawElementCallback = (Rect rect, int index, bool isActive, bool isFocused) => { rect.height = EditorGUIUtility.singleLineHeight; Rect rect_declaring = new Rect(rect.x, rect.y, 10.0f, EditorGUIUtility.singleLineHeight); rect.y += 2; Rect rect_name = new Rect(rect.x + 20.0f, rect.y, rect.width / 2.0f, EditorGUIUtility.singleLineHeight); Rect rect_type = new Rect(rect.x + rect.width / 2.0f + 30.0f, rect.y, rect.width - (rect.width / 2.0f + 30.0f), EditorGUIUtility.singleLineHeight); string new_name = EditorGUI.TextField(rect_name, asset.graph.outputParameters[index].name); bool new_declaring_value = EditorGUI.Toggle(rect_declaring, asset.graph.outputParameters[index].is_public); if (new_name != asset.graph.outputParameters[index].name) { UndoManager.RecordObject(asset, "Output Parameter Name Change"); asset.graph.outputParameters[index].name = new_name; GraphEditor.current_validate = true; } if (new_declaring_value != asset.graph.outputParameters[index].is_public) { UndoManager.RecordObject(asset, "Output Parameter Declaring Type Change"); asset.graph.outputParameters[index].is_public = new_declaring_value; GraphEditor.current_validate = true; } GUI.Label(rect_type, asset.graph.outputParameters[index].valueType.GetTypeName()); }; variable_list.onRemoveCallback = (ReorderableList list) => { UndoManager.RecordObject(target, "Remove parameter"); asset.graph.RemoveParameterAt(list.index, ParameterType.Variable); list.index = list.count - 1; GraphEditor.current_validate = true; }; input_list.onRemoveCallback = (ReorderableList list) => { UndoManager.RecordObject(target, "Remove parameter"); asset.graph.RemoveParameterAt(list.index, ParameterType.Input); list.index = list.count - 1; GraphEditor.current_validate = true; }; output_list.onRemoveCallback = (ReorderableList list) => { UndoManager.RecordObject(target, "Remove parameter"); asset.graph.RemoveParameterAt(list.index, ParameterType.Output); list.index = list.count - 1; GraphEditor.current_validate = true; }; variable_list.onAddDropdownCallback = (Rect buttonRect, ReorderableList list) => { ShowMenu(asset, ParameterType.Variable); }; input_list.onAddDropdownCallback = (Rect buttonRect, ReorderableList list) => { ShowMenu(asset, ParameterType.Input); }; output_list.onAddDropdownCallback = (Rect buttonRect, ReorderableList list) => { ShowMenu(asset, ParameterType.Output); }; }
private void DrawNodeInspector() { if (!GraphEditor.is_drag && GraphEditor.activeNode) { GUILayout.Space(20.0f); foreach (Node node in GraphEditor.selection) { //GUILayout.Label(string.Format("{0} : {1}", GraphEditor.scroll, node.position)); GUILayout.BeginVertical(node.title, "window"); if (node is IListPort) { GUILayout.BeginHorizontal(); if (GUILayout.Button("Add Port")) { UndoManager.RecordObject(asset, "Add Port"); ((IListPort)node).AddPort(); node.Validate(); //GraphEditor.current_validate = true; } if (GUILayout.Button("Remove Port")) { UndoManager.RecordObject(asset, "Remove Node"); ((IListPort)node).RemovePort(); node.Validate(); //GraphEditor.current_validate = true; } GUILayout.EndHorizontal(); } foreach (Port port in node.portValues) { var plug = port as IPlug; var input = port as IInputValue; var output = port as IOutputValue; if (input != null) { if (plug != null && plug.IsPlugged()) { GUILayout.BeginHorizontal(); GUI.enabled = false; GUIDraw.AnyField(input.GetDefaultValue(), input.valueType, port.name, GUILayout.ExpandWidth(true)); GUI.enabled = true; if (GUILayout.Button("x", GUILayout.Width(20.0f))) { UndoManager.RecordObject(asset, "Unplug Port"); plug.Unplug(); } GUILayout.EndHorizontal(); } else { object last_value = input.GetDefaultValue(); object new_value = GUIDraw.AnyField(last_value, input.valueType, port.name, GUILayout.ExpandWidth(true)); if (new_value != last_value) { UndoManager.RecordObject(asset, "Change Value"); input.SetDefaultValue(new_value); } } } else if (output != null) { GUILayout.BeginHorizontal(); GUILayout.Label("[PORT] " + port.name); GUILayout.FlexibleSpace(); GUILayout.Label(string.Format("<{0}>", output.valueType.GetTypeName())); if (plug != null && plug.IsPlugged()) { if (GUILayout.Button("x", GUILayout.Width(20.0f))) { UndoManager.RecordObject(asset, "Unplug Port"); plug.Unplug(); } } GUILayout.EndHorizontal(); } else { GUILayout.BeginHorizontal(); GUILayout.Label("[PORT] " + port.name); if (plug != null) { GUILayout.FlexibleSpace(); if (plug.IsPlugged()) { GUILayout.Label("[PLUGGED]"); } else { GUILayout.Label("[UNPLUGGED]"); } } GUILayout.FlexibleSpace(); GUILayout.Label("[ACTION]"); if (plug != null && plug.IsPlugged()) { if (GUILayout.Button("x", GUILayout.Width(20.0f))) { UndoManager.RecordObject(asset, "Unplug Port"); plug.Unplug(); } } GUILayout.EndHorizontal(); } } GUILayout.EndVertical(); } GUILayout.FlexibleSpace(); } }
public static void DeleteNode(Node node) { UndoManager.RecordObject(asset, string.Format("{0} > {1} Destroy Node", asset.name, node.name)); graph.RemoveNode(node); UndoManager.SetDirty(asset); }
private void InputGUI() { Vector2 delta = current.delta; switch (current.type) { case EventType.MouseDown: GraphEditor.mouse_down_position = GraphEditor.mouse_position; switch (current.button) { case 0: if (current.alt) { break; } if (GraphEditor.hover_node) { if (current.clickCount >= 2) { if (GraphEditor.hover_node is MacroNode) { SetGraphAsset(((MacroNode)GraphEditor.hover_node).reference); current.Use(); return; } else { EditorUtils.OpenScriptByType(GraphEditor.hover_node.type); current.Use(); } } if (GraphEditor.hover_port) { if (current.control) { if (GraphEditor.hover_port is OutputAction) { UndoManager.RecordObject(GraphEditor.asset, string.Format("{0} Add Branch", GraphEditor.asset.name)); set_dirty = true; QuickPlugPort(GraphEditor.hover_port, AddNode <Branch>(GraphEditor.mouse_position / GraphEditor.zoom - GraphEditor.scroll + new Vector2(60.0f, 0.0f))); } } else { if (current.shift) { GraphEditor.can_drag_node = false; GraphEditor.can_drag_port = false; if (GraphEditor.hover_port is IPlug) { UndoManager.RecordObject(GraphEditor.asset, string.Format("{0} > {1}: {2} Unplug", GraphEditor.asset.name, GraphEditor.hover_node.name, GraphEditor.hover_port.name)); set_dirty = true; ((IPlug)GraphEditor.hover_port).Unplug(); } current.Use(); } else { GraphEditor.can_drag_node = false; GraphEditor.can_drag_port = true; SelectOnlyNode(GraphEditor.hover_node); current.Use(); } } } else { if (current.shift) { if (GraphEditor.hover_node.is_selected) { GraphEditor.can_drag_node = false; DeselectNode(GraphEditor.hover_node); current.Use(); } else { GraphEditor.can_drag_node = true; SelectNode(GraphEditor.hover_node); current.Use(); } } else { if (GraphEditor.hover_node.is_selected) { GraphEditor.can_drag_node = true; } else { GraphEditor.can_drag_node = true; SelectOnlyNode(GraphEditor.hover_node); current.Use(); } } } } else if (editable_area.Contains(GraphEditor.mouse_position)) { GraphEditor.can_select = true; } break; case 1: break; case 2: break; } break; case EventType.MouseUp: switch (current.button) { case 0: if (GraphEditor.can_select && GraphEditor.is_select) { Rect select_box_in_scroll = new Rect(select_box.position / target_zoom, select_box.size / target_zoom); List <Node> nodes = GraphEditor.graph.nodes.Where((n) => select_box_in_scroll.Overlaps(n.nodeRect)).ToList(); if (current.shift) { foreach (Node node in nodes) { if (node.is_selected) { DeselectNode(node); } else { SelectNode(node); } } current.Use(); } else { ClearSelection(); SelectNodes(nodes); current.Use(); } } else { if (GraphEditor.hover_node) { if (GraphEditor.is_drag) { if (GraphEditor.drag_port) { if (GraphEditor.hover_port) { PlugPort(GraphEditor.drag_port, GraphEditor.hover_port); } else { QuickPlugPort(GraphEditor.drag_port, GraphEditor.hover_node); } current.Use(); } } else { if (!current.shift) { if (GraphEditor.selection.Count > 1) { SelectOnlyNode(GraphEditor.hover_node); current.Use(); } } } } else if (!GraphEditor.is_scrolling) { ClearSelection(); } if (GraphEditor.drag_port && !GraphEditor.hover_node) { InputAction in_act = GraphEditor.drag_port as InputAction; OutputAction out_act = GraphEditor.drag_port as OutputAction; IInputValue in_value = GraphEditor.drag_port as IInputValue; IOutputValue out_value = GraphEditor.drag_port as IOutputValue; if (in_act != null) { GraphEditor.waiting_for_new_node = true; AdvancedSearchWindow.Init(GraphEditor.mouse_position, "#tag:in void"); } else if (out_act != null) { GraphEditor.waiting_for_new_node = true; AdvancedSearchWindow.Init(GraphEditor.mouse_position, "#tag:out void"); } else if (in_value != null) { GraphEditor.waiting_for_new_node = true; AdvancedSearchWindow.Init(GraphEditor.mouse_position, "#tag:out " + in_value.valueType.GetTypeName(false, true)); } else if (out_value != null) { GraphEditor.waiting_for_new_node = true; AdvancedSearchWindow.Init(GraphEditor.mouse_position, "#tag:in " + out_value.valueType.GetTypeName(false, true)); } } } GraphEditor.can_select = false; GraphEditor.is_select = false; GraphEditor.is_scrolling = false; GraphEditor.hover_node = null; GraphEditor.drag_node = null; if (!GraphEditor.waiting_for_new_node) { GraphEditor.is_drag = false; GraphEditor.drag_port = null; GraphEditor.can_drag_port = false; } GraphEditor.can_drag_node = false; break; case 1: if (!GraphEditor.is_drag) { AdvancedSearchWindow.Init(GraphEditor.mouse_position); current.Use(); } GraphEditor.is_drag = false; break; case 2: break; } break; case EventType.MouseDrag: switch (current.button) { case 0: if (current.alt) { GraphEditor.is_drag = true; GraphEditor.is_scrolling = true; GraphEditor.scroll += delta; break; } if (!GraphEditor.is_drag) { if (GraphEditor.can_drag_port && GraphEditor.hover_port) { GraphEditor.is_drag = true; GraphEditor.can_drag_node = false; GraphEditor.drag_port = GraphEditor.hover_port; } if (GraphEditor.can_drag_node && GraphEditor.hover_node) { GraphEditor.is_drag = true; GraphEditor.can_drag_port = false; GraphEditor.drag_node = GraphEditor.hover_node; } } // ... if (GraphEditor.is_drag) { if (GraphEditor.drag_node) { foreach (Node node in GraphEditor.selection) { node.position += delta; } } } else { if (GraphEditor.can_select) { GraphEditor.is_select = true; } } break; case 1: GraphEditor.is_drag = true; GraphEditor.is_scrolling = true; GraphEditor.scroll += delta; break; case 2: GraphEditor.is_drag = true; GraphEditor.is_scrolling = true; GraphEditor.scroll += delta; break; } break; case EventType.ScrollWheel: if (!GraphEditor.is_drag) { float zoom_delta = 0.1f; zoom_delta = current.delta.y < 0.0f ? zoom_delta : -zoom_delta; target_zoom += zoom_delta; target_zoom = Mathf.Clamp(target_zoom, 0.2f, 1.0f); } break; case EventType.ValidateCommand: switch (Event.current.commandName) { case ("Delete"): DeleteSelectedNodes(); current.Use(); break; case ("Duplicate"): DuplicateSelectedNodes(); current.Use(); break; case ("SelectAll"): if (GraphEditor.selection.Count == GraphEditor.graph.nodeCount) { ClearSelection(); current.Use(); } else { SelectNodes(GraphEditor.graph.nodes); current.Use(); } break; } break; case EventType.DragUpdated: case EventType.DragPerform: if (DragAndDrop.objectReferences.Length > 0) { DragAndDrop.visualMode = DragAndDropVisualMode.Copy; if (current.type == EventType.DragPerform) { DragAndDrop.AcceptDrag(); GenericMenu generic_menu = new GenericMenu(); Type type; string type_name; foreach (UnityObject drag_obj in DragAndDrop.objectReferences) { if (drag_obj == null) { continue; } if (drag_obj is GraphAsset) { GraphAsset m_asset = (GraphAsset)drag_obj; if (m_asset) { generic_menu.AddItem(new GUIContent(string.Format("Add {0} as Macro", m_asset.title.IsNullOrEmpty() ? m_asset.name : m_asset.title)), false, (obj) => { AddMacro(m_asset, (Vector2)obj); }, GraphEditor.mouse_position - GraphEditor.scroll); } } else if (drag_obj is MonoScript) { MonoScript script = (MonoScript)drag_obj; if (script) { type = script.GetClass(); type_name = type.GetTypeName(); generic_menu.AddItem(new GUIContent(string.Format("{0}/Expose {0} members", type_name)), false, (obj) => { AddCustomNode <ReflectedObjectNode>((Vector2)obj, true, type); }, GraphEditor.mouse_position - GraphEditor.scroll); generic_menu.AddSeparator(string.Format("{0}/", type_name)); AddTypeMethodsToMenu(generic_menu, type, type_name); if (type.IsSubclassOf(typeof(Node)) && !type.IsAbstract && !type.IsGenericType) { generic_menu.AddItem(new GUIContent(string.Format("Add {0} as Node", type_name)), false, (obj) => { AddNode(type, (Vector2)obj); }, GraphEditor.mouse_position - GraphEditor.scroll); } } } if (drag_obj is GraphAsset || drag_obj is MonoScript) { generic_menu.AddSeparator(""); } type = drag_obj.GetType(); type_name = type.GetTypeName(); generic_menu.AddItem(new GUIContent(string.Format("Expose {0} members", type_name)), false, (obj) => { AddCustomNode <ReflectedObjectNode>((Vector2)obj, true, type); }, GraphEditor.mouse_position - GraphEditor.scroll); AddTypeMethodsToMenu(generic_menu, type, type_name); } DragAndDrop.PrepareStartDrag(); generic_menu.ShowAsContext(); } } break; case (EventType.KeyDown): switch (current.keyCode) { case KeyCode.Space: if (!current.control) { AdvancedSearchWindow.Init(position.size / 2.0f); current.Use(); } break; case KeyCode.Delete: DeleteSelectedNodes(); current.Use(); break; case KeyCode.Home: target_zoom = 1.0f; GraphEditor.scroll = Vector2.zero; current.Use(); break; case KeyCode.PageDown: GraphEditor.scroll -= new Vector2(0.0f, position.height); current.Use(); break; case KeyCode.PageUp: GraphEditor.scroll += new Vector2(0.0f, position.height); current.Use(); break; } break; } }
public void OnGUI() { bkp_zoom = GraphEditor.zoom; bkp_scroll = GraphEditor.scroll; GraphEditor.window = position; Color gui_background_color = GUI.backgroundColor; if (EditorApplication.isCompiling) { DrawLogoAnim(); ShowNotification(new GUIContent("Compiling, please wait...")); return; } if (internal_error) { DrawLogoAnim(); ShowNotification(new GUIContent("INTERNAL ERROR!\nPlease contact the support.")); GUILayout.BeginHorizontal(); if (GUILayout.Button("Retry")) { internal_error = false; } if (GUILayout.Button("Close Editor")) { editor.Close(); } GUILayout.EndHorizontal(); return; } try { bool dragging = GraphEditor.is_drag && GraphEditor.hover_node; if (GraphEditor.asset && GraphEditor.graph) { current = Event.current; GraphEditor.mouse_position = current.mousePosition; if (isDocked) { zoom_area = new Rect(0.0f, 19.0f, position.width, position.height); } else { zoom_area = new Rect(0.0f, 22.0f, position.width, position.height); } ClearHoverElements(); BeginZoomArea(); DrawScrollBackground(); if (GraphEditor.drag_port) { if (GraphEditor.drag_port is IInputPort) { Node.DrawConnection(GraphEditor.drag_port.rect.center, GraphEditor.mouse_position / GraphEditor.zoom, GraphEditor.drag_port.color, true); } else { Node.DrawConnection(GraphEditor.mouse_position / GraphEditor.zoom, GraphEditor.drag_port.rect.center, GraphEditor.drag_port.color, true); } if (GraphEditor.drag_port is ActionPort) { GUI.Label(new Rect((GraphEditor.mouse_position) / GraphEditor.zoom - Node.PORT_SIZE / 2.0f, Node.PORT_SIZE), GUIContent.none, Node.styles.on_input_action); } else { GUI.backgroundColor = GraphEditor.drag_port.color; GUI.Label(new Rect((GraphEditor.mouse_position) / GraphEditor.zoom - Node.PORT_SIZE / 2.0f, Node.PORT_SIZE), GUIContent.none, Node.styles.on_input_port); GUI.backgroundColor = gui_background_color; } } DrawNodes(); InputGUI(); EndZoomArea(); DrawSelectBox(); DrawWindowBorder(); DrawWindowHeader(); DrawToolbar(); if (dragging != (GraphEditor.is_drag && GraphEditor.hover_node)) { UndoManager.RecordObject(GraphEditor.asset, string.Format("{0} Move Nodes", GraphEditor.asset.name)); set_dirty = true; } if (set_dirty) { UndoManager.SetDirty(GraphEditor.asset); set_dirty = false; } } else { DrawLogoAnim(); } if (dragging || bkp_zoom != GraphEditor.zoom || bkp_scroll != GraphEditor.scroll) { bkp_zoom = GraphEditor.zoom; bkp_scroll = GraphEditor.scroll; } Repaint(); } catch (Exception except) { Debug.LogException(except); internal_error = true; } }