private DialogueNode MakeNode(DialogueNode parent) { var newNode = CreateInstance <DialogueNode>(); newNode.name = Guid.NewGuid().ToString(); if (parent != null) { parent.AddChild(newNode.name); newNode.SetPlayerSpeaking(!parent.IsPlayerSpeaking()); newNode.SetPosition(parent.GetRect().position + newNodeOffset); } return(newNode); }
public void CreateNode(DialogueNode parent) { DialogueNode newNode = CreateInstance <DialogueNode>(); newNode.name = Guid.NewGuid().ToString(); Undo.RegisterCreatedObjectUndo(newNode, "Created Dialogue Node"); if (parent != null) { parent.AddChild(newNode.name); newNode.SetIsPlayerSpeaking(!parent.IsPlayerSpeaking()); newNode.SetPosition(parent.GetRect().position + newNodeOffset); } if (AssetDatabase.GetAssetPath(this) != "") { Undo.RecordObject(this, "Added Dialogue Node"); } nodes.Add(newNode); OnValidate(); }
public void CreateNewNode(DialogueNode parent) { if (AssetDatabase.GetAssetPath(this) != "") { Undo.RecordObject(this, "Added New Dialogue Node"); } //dont use the new keyword to create a new SO (as we do for a regular class), //we call CreateInstance<T> to create an instance of a scriptable object //DialogueNode node = new DialogueNode(); DialogueNode node = CreateInstance <DialogueNode>(); node.name = System.Guid.NewGuid().ToString(); nodes.Add(node); if (parent != null) { parent.AddChild(node.name); node.SetRectPosition(parent.RectPosition.position + newNodeOffset); if (!parent.IsPlayerSpeaking()) { node.SetIsPlayerSpeaking(true); } } //unity will actually combine both undos into 1 step Undo.RegisterCompleteObjectUndo(node, "Create New Dialogue Node"); //moved to callback OnBeforeSerialize. Otherwise it may try to add a node to a new Dialogue before Dialogue is saved. //AssetDatabase.AddObjectToAsset(node, this); OnValidate(); }