public override void OnBodyGUI() { if (target.graph.nodes[target.graph.nodes.Count - 1] != target && createdInstance == null) { window.MoveNodeToTop(target); } Event e = Event.current; Vector2 mousePos = Event.current.mousePosition; GUILayout.BeginVertical(); for (int v = 0; v < blackboard.Values.Count; v++) { if (blackboard.Values[v] == null) { continue; } if (v >= blackboard.Values.Count) { return; } BlackboardObject value = blackboard.Values[v]; value.BlackboardListPosition = v; BlackboardObjectEditor bboEditor = BlackboardObjectEditor.GetEditor(value, window); EditorGUIUtility.labelWidth = 84; float height = 0; if (_bboSizes != null) { if (_bboSizes.Count == blackboard.Values.Count) { for (int i = 0; i < v; i++) { height += _bboSizes[blackboard.Values[v]].y; } } } Vector2 bboPos = new Vector2(0, 35 + height); GUILayout.BeginArea(new Rect(bboPos, new Vector2(GetWidth(), 100))); bool selected = NodeEditorWindow.current.SelectionCache.Contains(value); Color guiColor = GUI.color; if (selected) { GUIStyle style = new GUIStyle(bboEditor.GetBodyStyle()); GUIStyle highlightStyle = new GUIStyle(NodeEditorResources.styles.nodeHighlight); highlightStyle.padding = style.padding; style.padding = new RectOffset(); GUI.color = bboEditor.GetTint(); GUILayout.BeginVertical(style); GUI.color = NodeEditorPreferences.GetSettings().highlightColor; GUILayout.BeginVertical(new GUIStyle(highlightStyle)); } else { GUIStyle style = new GUIStyle(bboEditor.GetBodyStyle()); GUI.color = bboEditor.GetTint(); GUILayout.BeginVertical(style); } GUI.color = guiColor; EditorGUI.BeginChangeCheck(); bboEditor.OnHeaderGUI(); bboEditor.OnBodyGUI(); if (EditorGUI.EndChangeCheck()) { if (BlackboardObjectEditor.onUpdateBBO != null) { BlackboardObjectEditor.onUpdateBBO(value); } EditorUtility.SetDirty(value); bboEditor.serializedObject.ApplyModifiedProperties(); } GUILayout.EndVertical(); if (e.type == EventType.Repaint) { Vector2 size = GUILayoutUtility.GetLastRect().size; if (bboSizes.ContainsKey(value)) { bboSizes[value] = size; } else { bboSizes.Add(value, size); } } if (selected) { GUILayout.EndVertical(); } if (e.type != EventType.Layout) { //Check if we are hovering this node Vector2 bboSize = GUILayoutUtility.GetLastRect().size; Rect windowRect = new Rect(bboPos, bboSize); if (windowRect.Contains(mousePos)) { hoveredBBO = value; } } GUILayout.EndArea(); } for (int v = 0; v < blackboard.Values.Count; v++) { Vector2 size = new Vector2(); if (!bboSizes.TryGetValue(blackboard.Values[v], out size)) { continue; } try { GUILayout.Space(size.y); } catch { //I seriously don't know how to solve Getting control x pos in group issue } } try { if (GUILayout.Button("Add Variable")) { AddValueMenu.ShowAsContext(); } } catch { //I seriously don't know how to solve Getting control x pos in group issue } GUILayout.EndVertical(); }
public override void Controls(Event e) { switch (e.type) { case EventType.MouseDown: if (hoveredBBO != null && IsHoveringTitle(hoveredBBO)) { // If mousedown on node header, select or deselect if (!Selection.Contains(hoveredBBO)) { Selection.objects = new UnityEngine.Object[] { hoveredBBO }; } e.Use(); } break; case EventType.MouseDrag: if (e.button == 0) { if (hoveredBBO != null && IsHoveringTitle(hoveredBBO) && Selection.Contains(hoveredBBO)) { if (createdInstance == null) { createdInstance = BlackboardVariableInstance.Create(hoveredBBO, target.graph as BlackBoardGraph); mouseOffset = NodeEditorWindow.current.WindowToGridPosition(GetValuePosition(hoveredBBO)) - NodeEditorWindow.current.WindowToGridPosition(e.mousePosition); e.Use(); } else { createdInstance.position = mouseOffset + NodeEditorWindow.current.WindowToGridPosition(e.mousePosition); e.Use(); } } else if (hoveredBBO != null && Selection.Contains(hoveredBBO)) { if (createdInstance != null) { createdInstance.position = mouseOffset + NodeEditorWindow.current.WindowToGridPosition(e.mousePosition); e.Use(); } } } break; case EventType.MouseUp: if (e.button == 0) { if (hoveredBBO != null && createdInstance != null) { hoveredBBO = null; createdInstance = null; } } else if (e.button == 1 || e.button == 2) { if (hoveredBBO != null && IsHoveringTitle(hoveredBBO)) { if (!Selection.Contains(hoveredBBO)) { Selection.objects = new UnityEngine.Object[] { hoveredBBO } } ; GenericMenu menu = new GenericMenu(); BlackboardObjectEditor.GetEditor(hoveredBBO, window).AddContextMenuItems(menu); menu.DropDown(new Rect(Event.current.mousePosition, Vector2.zero)); e.Use(); // Fixes copy/paste context menu appearing in Unity 5.6.6f2 - doesn't occur in 2018.3.2f1 Probably needs to be used in other places. } } break; default: break; } }