// Start is called before the first frame update

    // Testing out possibility of automatically parsing dialogue
    // TODO define structure for dialogue and parse into this script
    private void OnValidate()
    {
        DialogueEditor.EditableConversation ec = nPCConversation.DeserializeForEditor();
        for (int i = 0; i < ec.SpeechNodes.Count; i++)
        {
            ec.SpeechNodes[i].Text = i + " success!";
        }
        nPCConversation.Serialize(ec);
    }
        private void Save(bool manual = false)
        {
            if (CurrentAsset != null)
            {
                EditableConversation conversation = new EditableConversation();

                // Prepare each node for serialization
                for (int i = 0; i < uiNodes.Count; i++)
                {
                    uiNodes[i].Info.PrepareForSerialization(CurrentAsset);
                }

                // Now that each node has been prepared for serialization:
                // - Register the UIDs of their parents/children
                // - Add it to the conversation
                for (int i = 0; i < uiNodes.Count; i++)
                {
                    uiNodes[i].Info.RegisterUIDs();

                    if (uiNodes[i] is UISpeechNode)
                    {
                        conversation.SpeechNodes.Add((uiNodes[i] as UISpeechNode).SpeechNode);
                    }
                    else if (uiNodes[i] is UIOptionNode)
                    {
                        conversation.Options.Add((uiNodes[i] as UIOptionNode).OptionNode);
                    }
                }

                // Serialize
                CurrentAsset.Serialize(conversation);

                // Null / clear everything. We aren't pointing to it anymore.
                if (!manual)
                {
                    CurrentAsset = null;
                    while (uiNodes.Count != 0)
                    {
                        uiNodes.RemoveAt(0);
                    }
                    CurrentlySelectedNode = null;
                }

#if UNITY_EDITOR
                if (!Application.isPlaying)
                {
                    UnityEditor.SceneManagement.EditorSceneManager.MarkSceneDirty(UnityEditor.SceneManagement.EditorSceneManager.GetActiveScene());
                }
#endif
            }
        }