public void ShowQuestionNode(DialogueDataNode node, List <DataGraphNode> answers, OnAnswer onAnswer)
    {
        content.text = node.text;

        next.gameObject.SetActive(false);
        answersPanel.gameObject.SetActive(true);

        for (int i = 0; i < answerButtons.Length; i++)
        {
            if (i >= answers.Count)
            {
                answerButtons[i].gameObject.SetActive(false);
                continue;
            }


            answerButtons[i].GetComponentInChildren <Text>().text = ((DialogueDataNode)answers[i]).text;
            answerButtons[i].gameObject.SetActive(true);

            answerButtons[i].onClick.RemoveAllListeners();

            DialogueDataNode answer = (DialogueDataNode)answers[i];
            answerButtons[i].onClick.AddListener(() =>
            {
                onAnswer(answer);
            });
        }
    }
Beispiel #2
0
    protected virtual void OnConditionNode(bool result)
    {
        List <DataGraphNode> connections = dialog.GetNodeConnections(currentConversationNode);

        if (connections.Count < 2)
        {
            Debug.LogWarning("Dialogue condition node is not setup corectly");
        }

        ProcessAction(currentConversationNode);

        DialogueDataNode onTrue  = (DialogueDataNode)connections[0];
        DialogueDataNode onFalse = onTrue.type == DialogueDataNode.Type.OnFalse ? onTrue : (DialogueDataNode)connections[1];

        if (onTrue == onFalse)
        {
            onTrue = (DialogueDataNode)connections[1];
        }

        if (result)
        {
            ProcessAction(onTrue);

            currentConversationNode = (DialogueDataNode)dialog.GetNodeConnections(onTrue)[0];
        }
        else
        {
            ProcessAction(onFalse);

            currentConversationNode = (DialogueDataNode)dialog.GetNodeConnections(onFalse)[0];
        }
        ProcessCurrentNode();
    }
    public void ShowTextNode(DialogueDataNode node, UnityAction onNext)
    {
        content.text = node.text;

        next.gameObject.SetActive(true);
        answersPanel.gameObject.SetActive(false);

        next.onClick.RemoveAllListeners();
        next.onClick.AddListener(onNext);
    }
Beispiel #4
0
    protected virtual void ProcessAction(DialogueDataNode node)
    {
        switch (node.actionOnComplete)
        {
        case DialogueDataNode.Action.None:
            return;

        case DialogueDataNode.Action.AddItem:
            Inventory.instance.Add(node.actionItem);
            break;
        }
    }
Beispiel #5
0
    protected virtual void OnNext()
    {
        if (currentConversationNode.type != DialogueDataNode.Type.Text && currentConversationNode.type != DialogueDataNode.Type.StartDialogue)
        {
            return;
        }

        List <DataGraphNode> connections = dialog.GetNodeConnections(currentConversationNode);

        ProcessAction(currentConversationNode);

        currentConversationNode = (DialogueDataNode)connections[0];
        ProcessCurrentNode();
    }
Beispiel #6
0
    protected virtual bool ProcessCondition(DialogueDataNode node)
    {
        switch (node.condition)
        {
        case DialogueDataNode.Condition.None:
            return(true);

        case DialogueDataNode.Condition.HasItem:
            return(Inventory.instance.HasItem(node.conditionItem));
        }

        Debug.LogWarning("Unprocessed Condition");
        return(false);
    }
Beispiel #7
0
    protected virtual void OnAnswer(DialogueDataNode answer)
    {
        if (currentConversationNode.type != DialogueDataNode.Type.Question)
        {
            return;
        }

        ProcessAction(currentConversationNode);
        ProcessAction(answer);

        List <DataGraphNode> connections = dialog.GetNodeConnections(answer);

        currentConversationNode = (DialogueDataNode)connections[0];
        ProcessCurrentNode();
    }
    public override bool IsNodeAllowed(bool isNewNode = false)
    {
        DialogueDataNode nd = (DialogueDataNode)dataNode;

        if (nd.type == DialogueDataNode.Type.StartDialogue)
        {
            DialogueDataGraph graph = (DialogueDataGraph)currentEditor.GetData();

            if (graph.startDialogue != null && graph.startDialogue != nd)
            {
                return(false);
            }
        }

        return(true);
    }
Beispiel #9
0
    protected override void Interact()
    {
        base.Interact();

        if (!conversationStarted && dialog.Size > 0)
        {
            Debug.Log("Conversation Stated");
            currentConversationNode = (DialogueDataNode)dialog.startDialogue;

            if (currentConversationNode == null)
            {
                return;
            }

            conversationStarted = true;
            OnNext();
        }
    }
Beispiel #10
0
    protected override void OnNodeEditorDataChange()
    {
        DialogueDataGraph dialogueGraph = (DialogueDataGraph)dataGraph;

        if (dialogueGraph.nodes.Count > 0)
        {
            dialogueGraph.nodes.ForEach(node =>
            {
                DialogueDataNode dialogueDataNode = (DialogueDataNode)node;

                if (dialogueDataNode.type == DialogueDataNode.Type.StartDialogue && dialogueGraph.startDialogue == null)
                {
                    dialogueGraph.startDialogue = dialogueDataNode;
                }
            });
        }

        base.OnNodeEditorDataChange();
    }
Beispiel #11
0
    public override void OnInspectorGUI()
    {
        DialogueDataNode dNode = (DialogueDataNode)target;

        dNode.type = (DialogueDataNode.Type)EditorGUILayout.EnumPopup(dNode.type);

        if (dNode.type != DialogueDataNode.Type.Condition &&
            dNode.type != DialogueDataNode.Type.StartDialogue &&
            dNode.type != DialogueDataNode.Type.EndDialogue &&
            dNode.type != DialogueDataNode.Type.OnFalse &&
            dNode.type != DialogueDataNode.Type.OnTrue)
        {
            EditorGUILayout.LabelField("Text");
            dNode.text = EditorGUILayout.TextArea(dNode.text);
        }

        if (dNode.type == DialogueDataNode.Type.Condition || dNode.type == DialogueDataNode.Type.Answer)
        {
            EditorGUILayout.LabelField("Condition");
            dNode.condition = (DialogueDataNode.Condition)EditorGUILayout.EnumPopup(dNode.condition);

            if (dNode.condition == DialogueDataNode.Condition.HasItem)
            {
                EditorGUILayout.LabelField("Item");
                dNode.conditionItem = EditorGUILayout.ObjectField(dNode.conditionItem, typeof(Item)) as Item;
            }
        }

        EditorGUILayout.LabelField("Action on Complete");
        dNode.actionOnComplete = (DialogueDataNode.Action)EditorGUILayout.EnumPopup(dNode.actionOnComplete);

        if (dNode.actionOnComplete == DialogueDataNode.Action.AddItem)
        {
            EditorGUILayout.LabelField("Item");
            dNode.actionItem = EditorGUILayout.ObjectField(dNode.actionItem, typeof(Item)) as Item;
        }
    }
Beispiel #12
0
    public override bool IsConnectionAllowed(Node other, bool isNewConnection = false)
    {
        DialogueDataNode     dNode       = (DialogueDataNode)dataNode;
        DialogueDataNode     otherDNode  = (DialogueDataNode)other.dataNode;
        DialogueDataGraph    graph       = (DialogueDataGraph)currentEditor.GetData();
        List <DataGraphNode> connections = graph.GetNodeConnections(dNode);
        int connectionCount = connections.Count;

        if (otherDNode.type == DialogueDataNode.Type.StartDialogue)
        {
            return(false);
        }


        switch (dNode.type)
        {
        case DialogueDataNode.Type.EndDialogue:
            return(false);

        case DialogueDataNode.Type.StartDialogue:
            if (otherDNode.type == DialogueDataNode.Type.Answer ||
                otherDNode.type == DialogueDataNode.Type.OnTrue ||
                otherDNode.type == DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 0 : 1))
            {
                return(false);
            }
            break;

        case DialogueDataNode.Type.Text:
            if (otherDNode.type == DialogueDataNode.Type.Answer ||
                otherDNode.type == DialogueDataNode.Type.OnTrue ||
                otherDNode.type == DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 0 : 1))
            {
                return(false);
            }
            break;

        case DialogueDataNode.Type.Question:
            if (otherDNode.type != DialogueDataNode.Type.Answer || connectionCount > (isNewConnection ? 3 : 4))
            {
                return(false);
            }
            break;

        case DialogueDataNode.Type.Answer:
            if (otherDNode.type == DialogueDataNode.Type.Answer ||
                otherDNode.type == DialogueDataNode.Type.OnTrue ||
                otherDNode.type == DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 0 : 1))
            {
                return(false);
            }
            break;

        case DialogueDataNode.Type.Condition:
            if (otherDNode.type != DialogueDataNode.Type.OnTrue && otherDNode.type != DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 1 : 2))
            {
                return(false);
            }

            if (isNewConnection)
            {
                if (connections.Count > 0)
                {
                    DialogueDataNode left = (DialogueDataNode)connections[0];
                    if (left.type == otherDNode.type)
                    {
                        return(false);
                    }
                }
            }
            else
            {
                if (connections.Count > 1)
                {
                    DialogueDataNode left  = (DialogueDataNode)connections[0];
                    DialogueDataNode right = (DialogueDataNode)connections[1];
                    if (left.type == right.type)
                    {
                        return(false);
                    }
                }
            }
            break;

        case DialogueDataNode.Type.OnTrue:
            if (otherDNode.type == DialogueDataNode.Type.Answer ||
                otherDNode.type == DialogueDataNode.Type.OnTrue ||
                otherDNode.type == DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 0 : 1))
            {
                return(false);
            }
            break;

        case DialogueDataNode.Type.OnFalse:
            if (otherDNode.type == DialogueDataNode.Type.Answer ||
                otherDNode.type == DialogueDataNode.Type.OnTrue ||
                otherDNode.type == DialogueDataNode.Type.OnFalse)
            {
                return(false);
            }
            if (connectionCount > (isNewConnection ? 0 : 1))
            {
                return(false);
            }
            break;
        }

        return(true);
    }