private void DrawGUINodeGraph()
{
background.Draw(graphRegion, scrollPos);
using(var scrollScope = new EditorGUILayout.ScrollViewScope(scrollPos) ) {
scrollPos = scrollScope.scrollPosition;
// draw node window x N.
{
BeginWindows();
nodes.ForEach(node => node.DrawNode());
EndWindows();
}
// draw connection input point marks.
foreach (var node in nodes) {
node.DrawConnectionInputPointMark(currentEventSource, modifyMode == ModifyMode.CONNECTING);
}
// draw connections.
foreach (var con in connections) {
var keyEnum = s_assetStreamMap.Keys.Where(c => c.Id == con.Id);
if (keyEnum.Any()) {
var assets = s_assetStreamMap[keyEnum.First()];
con.DrawConnection(nodes, assets);
} else {
con.DrawConnection(nodes, new Dictionary<string, List<Asset>>());
}
}
// draw connection output point marks.
foreach (var node in nodes) {
node.DrawConnectionOutputPointMark(currentEventSource, modifyMode == ModifyMode.CONNECTING, Event.current);
}
// draw connecting line if modifing connection.
switch (modifyMode) {
case ModifyMode.CONNECTING: {
// from start node to mouse.
DrawStraightLineFromCurrentEventSourcePointTo(Event.current.mousePosition, currentEventSource);
break;
}
case ModifyMode.SELECTING: {
GUI.DrawTexture(new Rect(selection.x, selection.y, Event.current.mousePosition.x - selection.x, Event.current.mousePosition.y - selection.y), selectionTex);
break;
}
}
// handle Graph GUI events
HandleGraphGUIEvents();
// set rect for scroll.
if (nodes.Any()) {
GUILayoutUtility.GetRect(new GUIContent(string.Empty), GUIStyle.none, GUILayout.Width(spacerRectRightBottom.x), GUILayout.Height(spacerRectRightBottom.y));
}
}
if(Event.current.type == EventType.Repaint) {
var newRgn = GUILayoutUtility.GetLastRect();
if(newRgn != graphRegion) {
graphRegion = newRgn;
Repaint();
}
}
}