private void ShowSaveLoadButtons()
    {
        GUILayout.BeginHorizontal();

        if (GUILayout.Button("Save") && tree != null && tree.root.Data != null)
        {
            savedTree = savedTree.ExportInstance(tree);
            EditorUtility.SetDirty(savedTree);

            CalculateNodeIDs();

            Debug.Log("Saved tree");
        }

        if (GUILayout.Button("Load"))
        {
            Cleanup();
            lastSavedTree = savedTree;
            SerializableTree treeInstance = savedTree.InstantiateTree();
            tree = treeInstance.ImportTree();
            if (tree == null)
            {
                tree = DialogueTester.CreateTestTree(treeInstance.gameObject.transform);
                Debug.Log("Created new tree");
            }
        }

        GUILayout.EndHorizontal();
    }
Ejemplo n.º 2
0
 public static void RedirectDialogue(SerializableTree dialogue)
 {
     Instance.ClearDialogue();
     if (DlgInstance != null)
     {
         DlgInstance.CleanupTempInstance();
     }
     StartDialogue(dialogue);
     redirected = true;
 }
Ejemplo n.º 3
0
    /// <summary>
    /// Load a DialogueTree from the given SerializableTree.
    /// </summary>
    public static DialogueTree LoadDialogue(SerializableTree dialogue)
    {
        SerializableTree dlg;

        if (dialogue.TryInstantiateTree(out dlg))
        {
            DlgInstance = dlg;
        }

        return(dlg.ImportTree());
    }
Ejemplo n.º 4
0
    void OnGUI()
    {
        GUILayout.BeginVertical();
        scrollPosTree = GUILayout.BeginScrollView(scrollPosTree, GUILayout.Height(currentScrollViewHeight));

        EditorGUIUtility.hierarchyMode = true;
        EditorGUI.indentLevel++;

        GUI.SetNextControlName("DummyControl");
        GUI.Button(new Rect(0, 0, 0, 0), "", GUIStyle.none);

        savedTree = (SerializableTree)EditorGUILayout.ObjectField("Dialogue Tree", savedTree, typeof(SerializableTree), false);

        if (savedTree == null || (lastSavedTree != null && savedTree != lastSavedTree))
        {
            tree  = null;
            nodes = null;
        }
        if (savedTree != null)
        {
            if (GUILayout.Button("Save") && tree != null)
            {
                savedTree.ExportTree(tree);
                EditorUtility.SetDirty(savedTree);
                Debug.Log("Saved tree");
            }

            if (GUILayout.Button("Load"))
            {
                lastSavedTree = savedTree;
                tree          = savedTree.ImportTree();
                if (tree == null)
                {
                    tree = DialogueTester.CreateTestTree();
                    Debug.Log("Created new tree");
                }
            }
        }

        if (savedTree != null && tree != null)
        {
            if (nodes == null)
            {
                nodes  = new Dictionary <int, NodeGUI>();
                nextID = 0;
            }
            NodeGUI.RenderNode(this, tree.root);


            NodeGUI gui = GetNodeAtPoint(Event.current.mousePosition);
            if (gui != null)
            {
                switch (Event.current.type)
                {
                case EventType.MouseDown:
                    if (contextMenuShown)
                    {
                        GUI.FocusControl("DummyControl");
                        dataInEditor     = null;
                        contextMenuShown = false;
                        Event.current.Use();
                    }
                    break;

                case EventType.MouseUp:
                    if (Event.current.button == 1)
                    {
                        GenerateContextMenu(gui);
                        Event.current.Use();
                    }
                    break;
                }
            }

            GUILayout.EndScrollView();
            ResizableSplit();
            scrollPosEditor = GUILayout.BeginScrollView(scrollPosEditor, GUILayout.Height(this.position.height - currentScrollViewHeight));

            NodeGUI focused = GetNodeGUI(GUI.GetNameOfFocusedControl());
            if (focused != null && focused.node != null)
            {
                dataInEditor = focused.node.Data;
                if (focused.node.Data == null)
                {
                    Debug.Log("Data is null... :(");
                }
            }
            if (dataInEditor != null)
            {
                SerializedObject   editor = new SerializedObject(this);
                SerializedProperty data   = editor.FindProperty("dataInEditor");
                EditorGUILayout.PropertyField(data);
            }

            GUILayout.EndScrollView();
            GUILayout.EndVertical();
            Repaint();
        }
    }
Ejemplo n.º 5
0
 /// <summary>
 /// Begin the given dialogue tree.
 /// </summary>
 public static bool StartDialogue(SerializableTree dialogue)
 {
     return(StartDialogue(LoadDialogue(dialogue)));
 }
Ejemplo n.º 6
0
 public static DialogueTree LoadDialogue(SerializableTree dialogue)
 {
     return(dialogue.ImportTree());
 }
    void OnGUI()
    {
        GUILayout.BeginVertical();

        EditorGUIUtility.hierarchyMode = true;
        indentLevel = 1;

        GUI.SetNextControlName(DUMMY_CONTROL);
        GUI.Button(new Rect(0, 0, 0, 0), "", GUIStyle.none);

        savedTree = (SerializableTree)EditorGUILayout.ObjectField("Dialogue Tree", savedTree, typeof(SerializableTree), true);

        CheckTreeHasChanged();

        if (savedTree != null)
        {
            ShowSaveLoadButtons();

            scrollPos = GUILayout.BeginScrollView(scrollPos);

            if (tree != null && tree.root.Data != null)
            {
                if (nodes == null)
                {
                    nodes  = new Dictionary <int, NodeGUI>();
                    nextID = 0;
                }
                NodeGUI.RenderAllNodes(this, tree.root);
                forceExpandNodes = null;

                HandleMouseClick();

                if (focusedWindow == this)
                {
                    NodeGUI focused = GetNodeGUI(GUI.GetNameOfFocusedControl());
                    if (nodeToSelect != null)
                    {
                        if (focused == GetNodeGUI(nodeToSelect))
                        {
                            nodeToSelect = null;
                        }
                        else
                        {
                            SelectNode(nodeToSelect);
                        }
                    }
                    else if (focused != null && focused.node != null)
                    {
                        HandleButtonPress(focused);
                    }
                    else
                    {
                        dataInEditor = null;
                    }

                    if (dataInEditor != null)
                    {
                        Selection.activeGameObject = dataInEditor.gameObject;
                    }
                }
            }
            GUILayout.EndScrollView();
        }
        GUILayout.EndVertical();
    }