Option for Angled Connectors
Posted: Tue May 19, 2020 1:15 pm
Alright, one last editor goof off feature. I had some down time and I figured I'd write some code to handle angled brackets (as opposed to direct lines). Code below for anyone who wants to implement it.
I like angled connectors quite a lot due to how I lay out my conversations and I would quite like to see it as a menu option that I could turn on.
The code for it is pretty simple, though I don't bother with logic for wrapping the line from bottom to top if the destination node is above the other, though the logic for that would be generally pretty trivial (just some x and y checks).
First a screenshot:
The editor code requires a bool (angledConnectors) to be set via a menu item and draws angled or direct based on that (or just replace the normal draw code if you're editing it for fun). The meat of the code goes after Vector3 center = mid + direction; on line 135 in DialogueEditorWindowConversationNodeEditorBase.cs in the DrawLink function.
Obviously, you also would need to comment out the original DrawAAPolyLine call as well since it's handled on the else.
I like angled connectors quite a lot due to how I lay out my conversations and I would quite like to see it as a menu option that I could turn on.
The code for it is pretty simple, though I don't bother with logic for wrapping the line from bottom to top if the destination node is above the other, though the logic for that would be generally pretty trivial (just some x and y checks).
First a screenshot:
The editor code requires a bool (angledConnectors) to be set via a menu item and draws angled or direct based on that (or just replace the normal draw code if you're editing it for fun). The meat of the code goes after Vector3 center = mid + direction; on line 135 in DialogueEditorWindowConversationNodeEditorBase.cs in the DrawLink function.
Code: Select all
if (angledConnectors)
{
if (start.y != end.y && start.x != end.x)
{
Vector3 startDown = new Vector3(start.x, start.y + 35, 0);
Vector3 endUp = new Vector3(end.x, startDown.y, 0);
Handles.DrawAAPolyLine(connectionTexture, wide ? 16f : 4f, new Vector3[] { start, startDown });
Handles.DrawAAPolyLine(connectionTexture, wide ? 16f : 4f, new Vector3[] { startDown, endUp });
Handles.DrawAAPolyLine(connectionTexture, wide ? 16f : 4f, new Vector3[] { endUp, end });
cross = Vector3.Cross((startDown - endUp).normalized, Vector3.forward);
diff = endUp - startDown;
direction = diff.normalized;
mid = ((0.5f * diff) + startDown) - (0.5f * cross);
center = mid + direction;
}
else
{
Handles.DrawAAPolyLine(connectionTexture, wide ? 16f : 4f, new Vector3[] { start, end });
}
}
else
{
Handles.DrawAAPolyLine(connectionTexture, wide ? 16f : 4f, new Vector3[] { start, end });
}