Adding A Link Order Indicator to the Node Editor

Announcements, support questions, and discussion for the Dialogue System.
Post Reply
User avatar
digiwombat
Posts: 50
Joined: Sun Jun 16, 2019 4:59 am

Adding A Link Order Indicator to the Node Editor

Post by digiwombat »

Howdy pardners!

NOTICE: This is in 2.2.34+. No need to add it unless you're below that version.

I wanted to be able to see the order that choices would be displayed/processed in since some logic branches need to be processed before others in cases where more than one would succeed. Tony already added link order to the tooltips, but I'm an excessively lazy man, so I wanted it to be EVEN EASIER to see the order.

NOTE: This displays the Link order, not the visual display order in the node editor. You can change this order in the node inspector down at the bottom where it says "Links To:" and still arrange them however you want visually.

Anyway, it seemed pretty easy to achieve this, so I did it. It looks like this:

Image

Some quick caveats before I get to the code!

1. This duplicates some math from the Link drawing function, but since those vectors aren't passed back up and the link count isn't accessible from the DrawLink function, this is the easiest way to edit the files quickly to get the job done and make it easy to paste back in between updates.
2. Ideally, you would make this a toggle or something that shows up on button press (alt or ctrl or something like that), but it only draws on multi-link nodes so it's fine.
3. Double ideally, you'd want maybe some colors or something and possibly to add one to the index to make it 1-based for non-technical types so they don't get confused or upset. Changing the style of the label is going to require wiggling the Rect placement a bit in the last line.

OKAY! Onto the instructions:

Open up DialogueEditorWindowConversationNodeEditor.cs and scroll to link 431. It should be DrawLink and HandleConnectorEvents, between or after those lines (don't add it outside the close bracket for the for loop), add the following code:

Code: Select all

if(entry.outgoingLinks.Count > 1)
{
	Vector3 cross = Vector3.Cross((start - end).normalized, Vector3.forward);
	Vector3 diff = (end - start);
	Vector3 direction = diff.normalized;
	Vector3 mid = ((0.5f * diff) + start) - (0.5f * cross);
	Vector3 center = mid + direction;
	GUIContent content = new GUIContent(i.ToString());
	Vector2 size = EditorStyles.miniTextField.CalcSize(content);
	EditorGUI.LabelField(new Rect(center.x - 6, center.y - 28, size.x + 2, size.y + 2), i.ToString(), EditorStyles.miniTextField);
}
And that's it. Now you've got a quick view of the order things will be processed.
Last edited by digiwombat on Wed Feb 08, 2023 11:23 pm, edited 3 times in total.
User avatar
Tony Li
Posts: 21959
Joined: Thu Jul 18, 2013 1:27 pm

Re: Adding A Link Order Indicator to the Node Editor

Post by Tony Li »

Thanks! I'll look into adding this as an option in Menu > Show.
Post Reply