private void CleanDanglingChildren(SceneTextNode nodeToDelete)
 {
     foreach (SceneTextNode node in GetAllNodes())
     {
         node.RemoveChild(nodeToDelete.name);
     }
 }
 public void DeleteNode(SceneTextNode nodeToDelete)
 {
     Undo.RecordObject(this, "Delete Dialogue Node");
     nodes.Remove(nodeToDelete);
     OnValidate();
     CleanDanglingChildren(nodeToDelete);
     Undo.DestroyObjectImmediate(nodeToDelete);
 }
        public void CreateNode(SceneTextNode parent)
        {
            SceneTextNode newNode = MakeNode(parent);

            Undo.RegisterCreatedObjectUndo(newNode, "Created Dialogue Node");
            Undo.RecordObject(this, "Added Dialogue Node");
            AddNode(newNode);
        }
 public IEnumerable <SceneTextNode> GetAllChildren(SceneTextNode parentNode)
 {
     foreach (string childID in parentNode.GetChildren())
     {
         if (nodeLookup.ContainsKey(childID))
         {
             yield return(nodeLookup[childID]);
         }
     }
 }
        private SceneTextNode MakeNode(SceneTextNode parent)
        {
            SceneTextNode newNode = CreateInstance <SceneTextNode>();

            newNode.name = Guid.NewGuid().ToString();
            if (parent != null)
            {
                parent.AddChild(newNode.name);
                newNode.SetVariableText(!parent.IsVariableText());
                newNode.SetPosition(parent.GetRect().position + newNodeOffset);
            }

            return(newNode);
        }
        public void OnBeforeSerialize()
        {
#if UNITY_EDITOR
            if (nodes.Count == 0)
            {
                SceneTextNode newNode = MakeNode(null);
                AddNode(newNode);
            }

            if (AssetDatabase.GetAssetPath(this) != "")
            {
                foreach (SceneTextNode node in GetAllNodes())
                {
                    if (AssetDatabase.GetAssetPath(node) == "")
                    {
                        AssetDatabase.AddObjectToAsset(node, this);
                    }
                }
            }
#endif
        }
 private void AddNode(SceneTextNode newNode)
 {
     nodes.Add(newNode);
     OnValidate();
 }