void Menu()
 {
     using (new EditorGUILayout.HorizontalScope())
     {
         if (GUILayout.Button("Load From File"))
         {
             LoadDLGFromFile();
         }
         if (GUILayout.Button("Save To File"))
         {
             SaveDLGToFile();
         }
         if (GUILayout.Button("Node View"))
         {
             DialogGraph dg = new DialogGraph();
             dg.LoadDLG(dlg);
             Debug.Log(dg);
             NodeEditorWindow.Open(dg);
         }
         if (GUILayout.Button("Export JSON"))
         {
             ExportPCLines();
         }
     }
 }
    void LoadDialogGraph()
    {
        dataPath = Application.dataPath + "/Resources/dialogGraph.dat";

        if (File.Exists(dataPath))
        {
            try
            {
                BinaryFormatter bf = new BinaryFormatter();
                FileStream      fs = File.Open(dataPath, FileMode.Open);

                graph = (DialogGraph)bf.Deserialize(fs);
                fs.Close();
            }
            catch (Exception e)
            {
                Debug.Log(e.Message);
                initDialogGraph();
            }
        }
        else
        {
            initDialogGraph();
        }
    }
    // Use this for initialization
    void Start()
    {
        _message = " Hello World!";

        //Graph g = new Graph(Application.dataPath +"/"+"Dialogs/test_dialog.xml");
        _dialogGraph = new DialogGraph(
            Application.dataPath + "/" + "Dialogs/test_dialog.xml",
            Application.dataPath + "/" + "Dialogs/test_dialog_content.xml"
            );

        if (!!_GUIDialogWindow)
        {
            _GUIDialogWindow._show = true;
        }

        mainDialog = GameObject.FindGameObjectWithTag("mainDialog");
        if (!!mainDialog)
        {
            _dialogGO = mainDialog.GetComponent <DialogWindow>();
            mainDialog.SetActive(false);
            _inDialog = false;
        }

        // Init dialog to 0 so the first nextmessage reads the right ID.
        _currentDialogNodeID = 0;
    }
        public FormDialogPlayer(DialogInfo dialog)
        {
            Debug.Assert(dialog != null);

            InitializeComponent();
            _playerProgress.Visible = false;

            _graph = dialog.Graph;
            _path.Push(_graph.RootNode);

            LoadControls();
        }
 public void RenderCreateDialog()
 {
     EditorGUILayout.LabelField("File Name");
     dialogObjName = EditorGUILayout.TextField(dialogObjName);
     if (GUILayout.Button("Create New"))
     {
         if (!string.IsNullOrEmpty(dialogObjName))
         {
             DialogObject dObj = DialogObject.CreateInstance <DialogObject>();
             dObj.name = dialogObjName;
             DialogGraph graph = DialogGraph.CreateInstance <DialogGraph>();
             graph.dialogObject = dObj;
             AssetDatabase.CreateAsset(graph, "Assets/DialogSystem/Editor/Resources/" + dialogObjName + ".asset");
             AssetDatabase.CreateAsset(dObj, "Assets/DialogSystem/Resources/" + dialogObjName + ".asset");
             graphs.Add(graph);
             dialogObjName = "";
         }
     }
 }
    void initDialogGraph()
    {
        graph = new DialogGraph();

        DialogNode d1  = new DialogNode("npc1q1", "where");
        DialogNode d2  = new ResponseNode("q1a1", "bigbrother");
        DialogNode d3  = new ResponseNode("q1a2", "here");
        DialogNode d4  = new DialogNode("npc1q2", "voteout");
        DialogNode d5  = new ResponseNode("q2a1", "watchfordrama");
        DialogNode d6  = new DialogNode("npc1q3", "blind");
        DialogNode d7  = new ResponseNode("q3a1", "surprised");
        DialogNode d11 = new ResponseNode("q3a2", "getperscription");
        DialogNode d8  = new DialogNode("npc1q4", "thedrama");
        DialogNode d9  = new DialogNode("npc1q5", "uhh");
        DialogNode d10 = new DialogNode("npc1q6", "notold");

        graph.Root = d1;
        graph.Add(d1);
        graph.Add(d2);
        graph.Add(d3);
        graph.Add(d4);
        graph.Add(d5);
        graph.Add(d6);
        graph.Add(d7);
        graph.Add(d8);
        graph.Add(d9);
        graph.Add(d10);
        graph.Add(d11);
        graph.AddLink(d1, d2);
        graph.AddLink(d1, d3);
        graph.AddLink(d2, d4);
        graph.AddLink(d4, d5);
        graph.AddLink(d5, d8);
        graph.AddLink(d3, d6);
        graph.AddLink(d6, d7);
        graph.AddLink(d6, d11);
        graph.AddLink(d7, d9);
        graph.AddLink(d11, d10);
        //graph.AddLink(d11, d1);
    }
    public override void OnGUI()
    {
        //GUILayout.BeginArea(new Rect(new Vector2(0, 0), box));
        if (graph == null)
        {
            graph = target as DialogGraph;
        }
        if (dialogObj == null)
        {
            dialogObj = (target as DialogGraph).dialogObject;
        }
        if (dialogObj == null)
        {
            return;
        }
        EditorGUILayout.BeginHorizontal(EditorStyles.toolbar, GUILayout.MinHeight(20), GUILayout.MaxHeight(20));
        options = EditorGUILayout.Toggle("Options", options, GUILayout.MaxWidth(100));
        if (GUILayout.Button("Save", EditorStyles.toolbarButton))
        {
            if (dialogObj.name != graph.name)
            {
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(dialogObj), graph.name);
                AssetDatabase.RenameAsset(AssetDatabase.GetAssetPath(graph), dialogObj.name);
            }
            window.Save();
            AssetDatabase.SaveAssets();
        }
        if (GUILayout.Button("Add Node", EditorStyles.toolbarButton))
        {
            graph.AddNode(typeof(DialogNode));
        }
        if (GUILayout.Button("Add Event", EditorStyles.toolbarButton))
        {
            graph.AddNode(typeof(DialogEventNode));
        }
        graph.name = EditorGUILayout.TextField(graph.name, EditorStyles.toolbarTextField);

        EditorGUILayout.EndHorizontal();
        EditorGUILayout.BeginHorizontal();
        EditorGUILayout.BeginVertical(EditorStyles.helpBox, GUILayout.MaxWidth(150));
        if (options)
        {
            Debug.Log("options enabled");
            EditorGUILayout.BeginVertical(EditorStyles.helpBox);
            //dialogObj.name = EditorGUILayout.TextField("Name", dialogObj.name);
            SerializedObject so = new SerializedObject(dialogObj);
            dialogObj.canExit     = EditorGUILayout.Toggle("Can Exit", dialogObj.canExit);
            dialogObj.startDialog = EditorGUILayout.IntField("Entry", dialogObj.startDialog);
            if (dialogObj.fallBacks == null)
            {
                dialogObj.fallBacks = new int[0];
            }
            if (fallbacks = EditorGUILayout.Foldout(options, "Fallbacks"))
            {
                EditorGUILayout.BeginHorizontal();
                if (GUILayout.Button("+"))
                {
                    List <int> fb = new List <int>(dialogObj.fallBacks);
                    fb.Add(0);
                    dialogObj.fallBacks = fb.ToArray();
                }
                if (GUILayout.Button("-"))
                {
                    List <int> fb = new List <int>(dialogObj.fallBacks);
                    if (fb.Count > 0)
                    {
                        fb.Remove(fb[fb.Count - 1]);
                    }
                    dialogObj.fallBacks = fb.ToArray();
                }
                EditorGUILayout.EndHorizontal();
                for (int i = 0; i < dialogObj.fallBacks.Length; i++)
                {
                    dialogObj.fallBacks[i] = EditorGUILayout.IntField("ID" + i.ToString(), dialogObj.fallBacks[i]);
                }
            }
            EditorGUILayout.EndVertical();
        }
        EditorGUILayout.EndHorizontal();
        EditorGUILayout.EndVertical();
        EditorUtility.SetDirty(dialogObj);
        base.OnGUI();
    }
 public void OpenDialog(DialogGraph dg)
 {
     XNodeEditor.NodeEditorWindow.Open(dg);
 }
Beispiel #9
0
 public StatefulDialog(DialogGraph graph)
 {
     _currentNode = graph.StartNode;
 }
 void Awake()
 {
     modalPanel = ModalPanel.Instance();
     dg         = DialogManager.Instance.Graph;
 }