//--------------------------------------
        // Construct User-Facing Conversation Object and Nodes
        //--------------------------------------

        private Conversation ConstructConversationObject(EditableConversation ec)
        {
            // Create a conversation object
            Conversation conversation = new Conversation();

            // Construct the parameters
            CreateParameters(ec, conversation);

            // Create a dictionary to store our created nodes by UID
            Dictionary <int, SpeechNode> speechByID  = new Dictionary <int, SpeechNode>();
            Dictionary <int, OptionNode> optionsByID = new Dictionary <int, OptionNode>();

            // Create a Dialogue and Option node for each in the conversation
            // Put them in the dictionary
            for (int i = 0; i < ec.SpeechNodes.Count; i++)
            {
                SpeechNode node = CreateSpeechNode(ec.SpeechNodes[i]);
                speechByID.Add(ec.SpeechNodes[i].ID, node);
            }

            for (int i = 0; i < ec.Options.Count; i++)
            {
                OptionNode node = CreateOptionNode(ec.Options[i]);
                optionsByID.Add(ec.Options[i].ID, node);
            }

            // Now that we have every node in the dictionary, reconstruct the tree
            // And also look for the root
            ReconstructTree(ec, conversation, speechByID, optionsByID);

            return(conversation);
        }
        ////////////////////////////////////////////

        //--------------------------------------
        // Set state
        //--------------------------------------

        private void SetState(eState newState)
        {
            // Exit
            switch (m_state)
            {
            case eState.TransitioningOptionsOff:
                m_selectedOption = null;
                break;

            case eState.TransitioningDialogueBoxOn:
                SetColorAlpha(DialogueBackground, 1);
                SetColorAlpha(NpcIcon, 1);
                SetColorAlpha(NameText, 1);
                break;
            }

            m_state     = newState;
            m_stateTime = 0f;

            // Enter
            switch (m_state)
            {
            case eState.TransitioningDialogueBoxOn:
            {
                SetColorAlpha(DialogueBackground, 0);
                SetColorAlpha(NpcIcon, 0);
                SetColorAlpha(NameText, 0);

                DialogueText.text = "";
                NameText.text     = m_pendingDialogue.Name;
                NpcIcon.sprite    = m_pendingDialogue.Icon != null ? m_pendingDialogue.Icon : BlankSprite;
            }
            break;

            case eState.ScrollingText:
            {
                SetColorAlpha(DialogueText, 1);

                if (m_targetScrollTextCount == 0)
                {
                    SetState(eState.TransitioningOptionsOn);
                    return;
                }
            }
            break;

            case eState.TransitioningOptionsOn:
            {
                for (int i = 0; i < m_uiOptions.Count; i++)
                {
                    m_uiOptions[i].gameObject.SetActive(true);
                }
            }
            break;
            }
        }
Beispiel #3
0
 public void OptionSelected(OptionNode option)
 {
     m_selectedOption = option;
     DoParamAction(option);
     if (option.Event != null)
     {
         option.Event.Invoke();
     }
     SetState(eState.TransitioningOptionsOff);
 }
Beispiel #4
0
        private OptionNode CreateOptionNode(EditableOptionNode editableNode)
        {
            OptionNode option = new OptionNode();

            option.Text    = editableNode.Text;
            option.TMPFont = editableNode.TMPFont;

            CopyParamActions(editableNode, option);

            return(option);
        }
 public void InitButton(OptionNode option)
 {
     // Set font
     if (option.TMPFont != null)
     {
         TextMesh.font = option.TMPFont;
     }
     else
     {
         TextMesh.font = null;
     }
 }
Beispiel #6
0
        private OptionNode CreateOptionNode(EditableOptionNode editableNode)
        {
            OptionNode option = new OptionNode();

            option.Text    = editableNode.Text;
            option.TMPFont = editableNode.TMPFont;

            CopyParamActions(editableNode, option);

            NodeEventHolder holder = this.GetNodeData(editableNode.ID);

            if (holder != null)
            {
                option.Event = holder.Event;
            }

            return(option);
        }
Beispiel #7
0
        public Node  MoveNext(out Current current)
        {
            NodePort exitPort = GetOutputPort("Output");

            if (!exitPort.IsConnected)
            {
                current = Current.Start;
                Debug.Log("Start节点未连接");
                return(this);
            }


            Node node = exitPort.Connection.node;

            //性能较低
            //if (node.GetType()==typeof(ChatNode))
            //{
            //	current = Current.Chat;
            //}


            ChatNode cnode = node as ChatNode;

            if (cnode != null)
            {
                current = Current.Chat;
                return(cnode);
            }

            current = Current.Start;

            OptionNode onode = node as OptionNode;

            if (onode != null)
            {
                current = Current.Option;
                return(onode);
            }

            return(this);
        }
Beispiel #8
0
        public Node  MoveNext(int index, out Current current)
        {
            Node temp = this;

            foreach (var port in DynamicOutputs)
            {
                if (port.fieldName == "options" + " " + index.ToString())
                {
                    if (!port.IsConnected)
                    {
                        current = Current.Null;

                        return(temp);
                    }
                    //如果连上了,返回连上的Node
                    temp = port.Connection.node;

                    ChatNode cnode = temp as ChatNode;
                    if (cnode != null)
                    {
                        current = Current.Chat;
                        return(cnode);
                    }
                    OptionNode onode = temp as OptionNode;
                    if (onode != null)
                    {
                        current = Current.Option;
                        return(onode);
                    }
                    current = Current.Option;
                    return(temp);
                }
            }
            current = Current.Option;
            return(temp);
        }
Beispiel #9
0
 public void EndButtonSelected()
 {
     m_selectedOption = null;
     SetState(eState.TransitioningOptionsOff);
 }
Beispiel #10
0
        private void ReconstructTree(EditableConversation ec, Conversation conversation, Dictionary <int, SpeechNode> dialogues, Dictionary <int, OptionNode> options)
        {
            // Speech nodes
            List <EditableSpeechNode> editableSpeechNodes = ec.SpeechNodes;

            for (int i = 0; i < editableSpeechNodes.Count; i++)
            {
                EditableSpeechNode editableNode = editableSpeechNodes[i];
                SpeechNode         speechNode   = dialogues[editableNode.ID];

                // Connections
                List <EditableConnection> editableConnections = editableNode.Connections;
                for (int j = 0; j < editableConnections.Count; j++)
                {
                    int childID = editableConnections[j].NodeUID;

                    // Construct node->Speech
                    if (editableConnections[j].ConnectionType == EditableConnection.eConnectiontype.Speech)
                    {
                        SpeechConnection connection = new SpeechConnection(dialogues[childID]);
                        CopyConnectionConditions(editableConnections[j], connection);
                        speechNode.Connections.Add(connection);
                    }
                    // Construct node->Option
                    else if (editableConnections[j].ConnectionType == EditableConnection.eConnectiontype.Option)
                    {
                        OptionConnection connection = new OptionConnection(options[childID]);
                        CopyConnectionConditions(editableConnections[j], connection);
                        speechNode.Connections.Add(connection);
                    }
                }

                // Root?
                if (editableNode.EditorInfo.isRoot)
                {
                    conversation.Root = dialogues[editableNode.ID];
                }
            }


            // Option nodes
            List <EditableOptionNode> editableOptionNodes = ec.Options;

            for (int i = 0; i < editableOptionNodes.Count; i++)
            {
                EditableOptionNode editableNode = editableOptionNodes[i];
                OptionNode         optionNode   = options[editableNode.ID];

                // Connections
                List <EditableConnection> editableConnections = editableNode.Connections;
                for (int j = 0; j < editableConnections.Count; j++)
                {
                    int childID = editableConnections[j].NodeUID;

                    // Construct node->Speech
                    if (editableConnections[j].ConnectionType == EditableConnection.eConnectiontype.Speech)
                    {
                        SpeechConnection connection = new SpeechConnection(dialogues[childID]);
                        CopyConnectionConditions(editableConnections[j], connection);
                        optionNode.Connections.Add(connection);
                    }
                }
            }
        }
 public void OptionSelected(OptionNode option)
 {
     m_selectedOption = option;
     DoParamAction(option);
     SetState(eState.TransitioningOptionsOff);
 }
Beispiel #12
0
 public OptionConnection(OptionNode node)
 {
     OptionNode = node;
 }
 public void SetAsEndConversation()
 {
     m_option      = null;
     TextMesh.text = "End.";
 }
 public void SetOption(OptionNode option)
 {
     m_option      = option;
     TextMesh.text = option.Text;
 }
        public Conversation Deserialize()
        {
            // Deserialize an editor-version (containing all info) that
            // we will use to construct the user-facing Conversation data structure.
            EditableConversation ec = this.DeserializeForEditor();

            // Create a conversation.
            Conversation conversation = new Conversation();
            // Create a dictionary to store our created nodes by UID
            Dictionary <int, SpeechNode> dialogues = new Dictionary <int, SpeechNode>();
            Dictionary <int, OptionNode> options   = new Dictionary <int, OptionNode>();

            // Create a Dialogue and Option node for each in the conversation
            // Put them in the dictionary
            for (int i = 0; i < ec.SpeechNodes.Count; i++)
            {
                SpeechNode node = new SpeechNode();
                node.Name = ec.SpeechNodes[i].Name;
                node.Text = ec.SpeechNodes[i].Text;
                node.AutomaticallyAdvance           = ec.SpeechNodes[i].AdvanceDialogueAutomatically;
                node.AutoAdvanceShouldDisplayOption = ec.SpeechNodes[i].AutoAdvanceShouldDisplayOption;
                node.TimeUntilAdvance = ec.SpeechNodes[i].TimeUntilAdvance;
                node.TMPFont          = ec.SpeechNodes[i].TMPFont;
                node.Icon             = ec.SpeechNodes[i].Icon;
                node.Audio            = ec.SpeechNodes[i].Audio;
                node.Volume           = ec.SpeechNodes[i].Volume;
                node.Options          = new List <OptionNode>();
                if (this.GetNodeData(ec.SpeechNodes[i].ID) != null)
                {
                    node.Event = this.GetNodeData(ec.SpeechNodes[i].ID).Event;
                }

                dialogues.Add(ec.SpeechNodes[i].ID, node);
            }
            for (int i = 0; i < ec.Options.Count; i++)
            {
                OptionNode node = new OptionNode();
                node.Text    = ec.Options[i].Text;
                node.TMPFont = ec.Options[i].TMPFont;

                options.Add(ec.Options[i].ID, node);
            }

            // Now that we have every node in the dictionary, reconstruct the tree
            // And also look for the root
            for (int i = 0; i < ec.SpeechNodes.Count; i++)
            {
                // Connect dialogue to options
                for (int j = 0; j < ec.SpeechNodes[i].OptionUIDs.Count; j++)
                {
                    dialogues[ec.SpeechNodes[i].ID].Options.Add(options[ec.SpeechNodes[i].OptionUIDs[j]]);
                }

                // Connect dialogue to following dialogue
                if (ec.SpeechNodes[i].SpeechUID != EditableConversation.INVALID_UID)
                {
                    dialogues[ec.SpeechNodes[i].ID].Dialogue = dialogues[ec.SpeechNodes[i].SpeechUID];
                }

                // Check if root
                if (ec.SpeechNodes[i].EditorInfo.isRoot)
                {
                    conversation.Root = dialogues[ec.SpeechNodes[i].ID];
                }
            }

            for (int i = 0; i < ec.Options.Count; i++)
            {
                // Connect option to following dialogue
                if (dialogues.ContainsKey(ec.Options[i].SpeechUID))
                {
                    options[ec.Options[i].ID].Dialogue = dialogues[ec.Options[i].SpeechUID];
                }
            }

            return(conversation);
        }