So the way that new nodes were added to the top left was bothering me. I tinkered with adding it to right where the mouse is. It was strange, it would add the first new node there, but any other nodes from that parent would go like… between the mouse position and top left. I spat out debug logs and sure enough it really thought my mouse was elsewhere.
However, I actually like the solution I used better anyway. Set it just next to the parent node so you can then move it where you want:
(here is a bigger version that is easier to see: Dropbox - nodeedit.mp4 - Simplify your life)
This was simple, but from what I could tell I needed to add a couple new variables to Dialogue.cs to keep track of what was being added.
private DialogueNode newestNode = null;
private DialogueNode newestNodeParent = null;
Then for when you create a node there:
public void CreateNode(DialogueNode parent)
{
DialogueNode newNode = new DialogueNode();
newNode.uniqueID = Guid.NewGuid().ToString();
parent.children.Add(newNode.uniqueID);
nodes.Add(newNode);
newestNode = newNode;
newestNodeParent = parent;
OnValidate(); //Manually Call OnValidate to get lookup updated.
}
Then to get those nodes:
public DialogueNode GetNewestNode()
{
return newestNode;
}
public DialogueNode GetNewestNodeParent()
{
return newestNodeParent;
}
Finally back in DialogueEditor.cs:
private void AddRemoveNodesCheck()
{
if (creatingNode != null) //Check for a new node to create from button press on node(needs to run AFTER iteration above)
{
Undo.RecordObject(selectedDialogue, "Added Dialogue Node");
selectedDialogue.CreateNode(creatingNode);
// Set the newest node right next to parent.
selectedDialogue.GetNewestNode().rect.x = selectedDialogue.GetNewestNodeParent().rect.xMax;
selectedDialogue.GetNewestNode().rect.y = selectedDialogue.GetNewestNodeParent().rect.center.y;
creatingNode = null;
}
.... (the delete code)
So there you go. I hope this helps and I am open to feedback on how this could be done better. (Also notice my personalized touches on how it looks and how I code it. For some reason I want to see the last 12 digits of the GUID. It makes me feel warm and safe). *UPDATE I actually added a Nickname field to the DialogueNode class. Now it displays that nickname and if it is empty it displays the last 12 of GUID:
if(node.nickname == “”) EditorGUILayout.LabelField(node.name.Substring(node.name.Length - 12), EditorStyles.centeredGreyMiniLabel);
else EditorGUILayout.LabelField(node.nickname, EditorStyles.centeredGreyMiniLabel);
Also a big update I made is using TextArea for the text field and the Inspector string field as well. So much better to see it all (and forcing WordWrap on is a must).