コード例 #1
0
    public static void OnConversationEnded(this NPCConversation conversation, UnityAction action)
    {
        // Deserialize the conversation for modification
        EditableConversation editableConversation = conversation.DeserializeForEditor();

        // Filter all speech nodes that have no speech node after and have no options after
        IEnumerable <EditableSpeechNode> leaves = editableConversation.SpeechNodes
                                                  .Where(node => node.SpeechUID == EditableConversation.INVALID_UID && (node.OptionUIDs == null || node.OptionUIDs.Count <= 0));

        // For each event associated with the leaf, make that leaf end the conversation when finished
        foreach (EditableSpeechNode leaf in leaves)
        {
            NodeEventHolder eventHolder = conversation.GetNodeData(leaf.ID);
            eventHolder.Event.AddListener(action);
        }
    }
コード例 #2
0
    private EditableSpeechNode CreateSpeechNode(NPCConversation conversation, EditableConversation editableConversation, string text, float xPos, float yPos, bool isRoot, UnityAction callback)
    {
        // Create a new speech node
        EditableSpeechNode speechNode = new EditableSpeechNode()
        {
            Text       = text,
            Name       = npcName,
            Icon       = npcIcon,
            TMPFont    = npcFont,
            ID         = conversation.CurrentIDCounter,
            EditorInfo = new EditableConversationNode.EditorArgs()
            {
                xPos   = xPos,
                yPos   = yPos,
                isRoot = isRoot
            }
        };

        // Setup the node event.
        NodeEventHolder nodeEvent = conversation.GetNodeData(conversation.CurrentIDCounter);

        nodeEvent.Icon    = npcIcon;
        nodeEvent.TMPFont = npcFont;

        // If the callback is not null that add it to the event
        if (callback != null)
        {
            nodeEvent.Event.AddListener(callback);
        }

        // Add this to the list of speech nodes
        editableConversation.SpeechNodes.Add(speechNode);

        // Update the counter
        conversation.CurrentIDCounter++;

        // Return the speech node
        return(speechNode);
    }
コード例 #3
0
    public void Respond()
    {
        if (GameManager.Instance)
        {
            // Deserialize the conversation for modification
            EditableConversation editableConversation = conversation.DeserializeForEditor();

            // Filter all speech nodes that have no speech node after and have no options after
            IEnumerable <EditableSpeechNode> leaves = editableConversation.SpeechNodes
                                                      .Where(node => node.SpeechUID == EditableConversation.INVALID_UID && (node.OptionUIDs == null || node.OptionUIDs.Count <= 0));

            // For each event associated with the leaf, make that leaf end the conversation when finished
            foreach (EditableSpeechNode leaf in leaves)
            {
                NodeEventHolder eventHolder = conversation.GetNodeData(leaf.ID);
                eventHolder.Event.AddListener(OnConversationEnded);
            }

            // Say the given conversation on the dialogue manager
            DialogueManager dialogue = GameManager.Instance.m_dialogueManager;
            dialogue.SetNewDialogue(conversation);
        }
    }