示例#1
0
    private void Awake()
    {
        if (berthaDialogue == null)
        {
            berthaDialogue = GameObject.FindGameObjectWithTag("BerthaDialogue").GetComponent <DialogueText>();
        }

        if (ojnarDialogue == null)
        {
            ojnarDialogue = GameObject.FindGameObjectWithTag("OjnarDialogue").GetComponent <DialogueText>();
        }
        Debug.Assert(berthaDialogue != null, "You need to specify a Player with an attached Dialogue");
        Debug.Assert(ojnarDialogue != null, "You need to specify a Companion with an attached Dialogue");
    }
    // Play a given sequence
    IEnumerator PlayTextSequence(DialogueText dialogue)
    {
        int nextCharInput = 0;

        // Activate the triangle depending on the speaker
        //this.speakerImageP1.sprite = this.fighterIconDict[dialogue.iconName];
        this.speakerImage.sprite = dialogue.sprite;
        StartCoroutine("MoveInCharacter");
        this.backgroundBox.gameObject.SetActive(true);
        //this.backgroundBoxP2.gameObject.SetActive(false);

        while (this.currentText != dialogue.text)
        {
            yield return(new WaitForEndOfFrame());

            // Add chars to finalText based on ceil(speed)
            for (int i = 0; i < this.speed; i++)
            {
                if (nextCharInput < dialogue.text.Length)
                {
                    this.currentText += dialogue.text[nextCharInput];
                    nextCharInput++;
                }
            }

            this.targetDialogueText.text = this.currentText;
        }

        // Activate next text segment
        //this.nextButton.SetActive(true);
        float timeDelay = 1.0f;
        float timer     = 0.0f;

        while (timer < timeDelay)
        {
            yield return(new WaitForEndOfFrame());

            timer += Time.deltaTime;
        }

        this.GoToNextText();
    }
    // Validates a single conversations
    private bool validateConversation(Conversation _c)
    {
        // Local variables
        List <int>   textIDs = null;
        DialogueText text    = null;

        // Check parameter
        if (_c == null)
        {
            return(false);
        }

        // Start text available?
        if (_c.getTextByID(_c.StartTextID) == null)
        {
            Debug.LogError("The specified text start-ID of a conversation does not exist!");
            return(false);
        }

        // Validate all texts
        textIDs = _c.getTextIDs();
        foreach (int id in textIDs)
        {
            // Get text
            text = _c.getTextByID(id);

            // Validate
            if (validateText(_c, _c.getTextByID(id)) == false)
            {
                return(false);
            }

            // Initialize text
            if (text.initialize(this) == false)
            {
                Debug.LogError("Text initialization failed!");
                return(false);
            }
        }

        return(true);
    }
示例#4
0
    private IEnumerator ReadConversation()
    {
        FMODUnity.RuntimeManager.PlayOneShot(conversationSoundList[0]);
        isReading = true;

        while (conversationList.Count > 0)
        {
            if (currentDialogueText == null || currentDialogueText.IsReading == false)
            {
                currentDialogue = conversationList[0].Dialogues[currentDialogueIndex];

                if (currentDialogue.DialogueOwner == CharacterDialogue.BERTHA)
                {
                    currentDialogueText = berthaDialogue;
                }
                else if (currentDialogue.DialogueOwner == CharacterDialogue.OJNAR)
                {
                    currentDialogueText = ojnarDialogue;
                }

                if (currentDialogueText.IsReading == false)
                {
                    currentDialogueText.ReadDialogue(currentDialogue);
                    currentDialogueIndex += 1;
                }

                if (currentDialogueIndex == conversationList[0].Dialogues.Count)
                {
                    conversationList.RemoveAt(0);
                    conversationSoundList.RemoveAt(0);
                    currentDialogueIndex = 0;
                    isReading            = false;
                }
            }
            yield return(new WaitForSeconds(0.1f));
        }
        if (slowDown == true)
        {
            StartCoroutine(ChangePlayerSpeed(SpeedChange.UP));
        }
    }
    /// <summary>
    /// In the start method we fetch our cached instances from the scene.
    /// We initialize our sentences array and we display the first sentence in the dialogue.
    /// </summary>
    void Start()
    {
        //get canvas with the script interactionCanvas
        canvas = FindObjectOfType <InteractionCanvas>();
        //get this object's text mesh pro component
        tmpro = GetComponent <TextMeshProUGUI>();

        //load text file from the resources folder. Has to be from the resources folder.
        //txt = Resources.Load("TextFiles/" + owner.GetFileName()) as TextAsset; unsused for now

        //Loading the dialogue manager associated to our owner. Because we only have a reference to the owner's prefab, it will search for the file with the name that is stated in the prefab, not the instance
        d = Resources.Load("TextFiles/" + owner.GetFileName()) as DialogueText;

        //get all sentences in our dialogueText object
        sentences = d.sentences;//txt.text.Split('\n'); <---Previous way to do it

        //start index at second position because we will show the first one on instantiation
        currIndex = 1;
        //on creation show first sentence
        StartCoroutine(ShowText(sentences[0]));
    }
示例#6
0
    /**
     * Set the active text instance
     */
    private bool setTextByID(int _id)
    {
        // Get start text, text-part
        m_currentTextPartIndex = -1;
        m_text = m_conversation.getTextByID(_id);
        if (m_text == null)
        {
            Debug.LogError("Invalid text FSM-state (" + gameObject.name + "). Specified text has not been found!");
            return(false);
        }

        // Delete choices and close window
        if (m_window != null)
        {
            m_window.removeAnswers();
            m_window.closeDialogWindow();
        }

        // Update text on next update run
        m_isHandleNextTextPart = true;

        return(true);
    }
示例#7
0
    public void OnGUI()
    {
        if (!DialogueAvailable)
        {
            return;
        }

        GUI.skin = skin;

        Background.DrawMe();
        SpeakerName.DrawMe();
        SpeakerText.DrawMe();

        bool userWantsToAdvance = NextButton.IsClicked() ||
                                  Input.GetButtonUp("Interact");

        if (Time.time >= _nextAdvance &&
            userWantsToAdvance)
        {
            DialogueText text = _currentThread.AdvanceSpeakerText();
            if (text != default(DialogueText))
            {
                PresentLine(text);
            }

            if (_currentThread.TextExhausted)
            {
                if (DebugMode)
                {
                    Debug.Log("Dialog text is exhausted.");
                }

                PlayerHasControl(true);
                HideElements();
            }
        }
    }
示例#8
0
    private IEnumerator FadeInOrOutDialogue(DialogueText dialogueText, Dialogue dialogue, FadeInOrOut fadeInOrOut)
    {
        float textColorFadeTime = 0;

        if (fadeInOrOut == FadeInOrOut.IN)
        {
            dialogueText.Text.text = dialogue.DialogueText;
        }
        while (textColorFadeTime <= 1 + fadeSmoothness)
        {
            if (fadeInOrOut == FadeInOrOut.IN)
            {
                dialogueText.Text.color = Color.Lerp(Color.clear, dialogueText.OriginalColor, textColorFadeTime);
                background.color        = Color.Lerp(Color.clear, originalBGColor, textColorFadeTime);
            }
            else
            {
                dialogueText.Text.color = Color.Lerp(dialogueText.OriginalColor, Color.clear, textColorFadeTime);
                background.color        = Color.Lerp(originalBGColor, Color.clear, textColorFadeTime);
            }
            textColorFadeTime += Time.deltaTime / dialogue.FadeTime;
            yield return(new WaitForSeconds(fadeSmoothness));
        }
    }
示例#9
0
    private void PresentLine(DialogueText text)
    {
        SpeakerName.Text = text.SpeakerName;
        SpeakerText.Text = text.SpeakerText;

        if(text.BGMOverride != null)
            _maestro.ChangeTunes(text.BGMOverride);

        if(text.OneShotClip != null)
            _maestro.PlaySoundEffect(text.OneShotClip);

        if(!string.IsNullOrEmpty(text.ConversationEvent))
        {
            Debug.Log("Sending message " + text.ConversationEvent + " to own scripts...");
            gameObject.SendMessage(text.ConversationEvent, SendMessageOptions.RequireReceiver);
        }

        if(!string.IsNullOrEmpty(text.ConversationGift))
            _ambassador.GainItem(text.ConversationGift);

        if(text.AltersProgression)
            _ambassador.UpdateThread(text.QuestThreadName, text.ResultingQuestThreadPhase);

        if(text.CausesSelfDestruct)
            Destroy(_currentThread.CallingGameObject);
    }
示例#10
0
 public RenderTextTask(IEnumerator <Instruction> instructions, DialogueText text) : base(instructions) =>
     this.text = text;
        public override void HandleDialogueTextBegin(DialogueText dialogueText)
        {
            base.HandleDialogueTextBegin(dialogueText);

            Dispatch(dialogueText);
        }
    // Parses a text
    private static DialogueText parseText(XmlNode _node)
    {
        // Local variables
        int             textID             = -1;
        int             nextTextID         = -1;
        string          exitValue          = "";
        string          funcValueShowParts = "";
        DialogueText    text       = null;
        XmlNode         xmlNode    = null;
        XmlNode         xmlNodeAtt = null;
        TextPart        part       = null;
        Choice          choice     = null;
        List <TextPart> partList   = new List <TextPart>();
        List <Choice>   choiceList = new List <Choice>();

        // Get attribute: id
        xmlNodeAtt = _node.Attributes.GetNamedItem("id");
        if (xmlNodeAtt == null)
        {
            Debug.LogError("Dialogue texts need IDs!");
            return(null);
        }
        textID = int.Parse(xmlNodeAtt.Value);

        // Get attribute: next text ID
        xmlNodeAtt = _node.Attributes.GetNamedItem("nextText");
        if (xmlNodeAtt != null)
        {
            nextTextID = int.Parse(xmlNodeAtt.Value);
        }

        // Get attribute: exit value
        xmlNodeAtt = _node.Attributes.GetNamedItem("exit");
        if (xmlNodeAtt != null)
        {
            exitValue = xmlNodeAtt.Value;
        }

        // Get attribute: show parts
        xmlNodeAtt = _node.Attributes.GetNamedItem("showParts");
        if (xmlNodeAtt != null)
        {
            funcValueShowParts = xmlNodeAtt.Value;
        }

        // Find first text/choice node
        xmlNode = _node.FirstChild;
        if (xmlNode == null)
        {
            Debug.LogError("No text-parts or choices has been found!");
            return(null);
        }

        // Parse all text-parts/choices
        do
        {
            // Skipable?
            if (isNodeSkipable(xmlNode) == false)
            {
                // Text-part?
                if (xmlNode.Name.Equals("part") == true)
                {
                    // Parse
                    part = parseTextPart(xmlNode);
                    if (part == null)
                    {
                        return(null);
                    }

                    // Add to list
                    partList.Add(part);
                }

                // Choice?
                else if (xmlNode.Name.Equals("choice") == true)
                {
                    // Parse
                    choice = parseChoice(xmlNode);
                    if (choice == null)
                    {
                        return(null);
                    }

                    // Add to list
                    choiceList.Add(choice);
                }

                // Unknown (exclude known standard strings)
                else
                {
                    Debug.LogWarning("Unknown XML node with a text (" + xmlNode.Name + ")");
                }
            }

            // Next sibling
            xmlNode = xmlNode.NextSibling;
        }while (xmlNode != null);

        // Create text
        text = new DialogueText(textID, nextTextID, exitValue, funcValueShowParts, choiceList, partList);

        return(text);
    }
示例#13
0
    public static void ExecuteEvent(DialogueText dialogueText)
    {
        ClearPreviousEvent();

        currentDialogue = dialogueText;
        inDialogue      = true;

        //Debug.Log("Indexing characters in dialogue...");
        characters = new Dictionary <string, GameObject>();        // string name, GameObject reference to character
        foreach (List <SpeechLine> lines in currentDialogue.lines) // find characters speaking to get references to them
        {
            foreach (SpeechLine line in lines)
            {
                //Debug.Log(line.speakerName);
                if (!characters.ContainsKey(line.speakerName)) // if this character hasn't been added yet
                {
                    // find and add the character object reference to the dictionary
                    characters.Add(line.speakerName, GameObject.Find(line.speakerName));
                }
            }
        }

        // apply dialogue effects
        ApplyDialogueEffects();

        // spawn text boxes above the entities for each character
        //Debug.Log("Spawning text boxes...");
        uiElements = new Dictionary <string, GameObject>();
        foreach (KeyValuePair <string, GameObject> entry in characters)
        {
            if (!string.IsNullOrEmpty(entry.Key))
            {
                GameObject currTextBox;

                if (entry.Key.Contains("RU"))
                {
                    //firefly boxes
                    if (dialogueText.interactionEffects.Contains("STATIC"))
                    {
                        inStaticDialogue = true;
                        GameObject.Find("UICanvases").GetComponent <CanvasManager>().SetGamestateByCanvasName("DialogueCanvas");
                        currTextBox = GameObject.Instantiate(DialogueEventController.dialogueBoxFireflyPrefab, DialogueEventController.dialogueCanvas.transform);
                    }
                    else // default to moving box
                    {
                        inStaticDialogue = false;
                        currTextBox      = GameObject.Instantiate(DialogueEventController.dialogueBoxFollowFireflyPrefab, DialogueEventController.dialogueCanvas.transform);
                        currTextBox.GetComponent <DialogueBoxFollow>().characterToFollow = entry.Value;
                    }
                }
                else // cat boxes
                {
                    if (dialogueText.interactionEffects.Contains("STATIC"))
                    {
                        inStaticDialogue = true;
                        GameObject.Find("UICanvases").GetComponent <CanvasManager>().SetGamestateByCanvasName("DialogueCanvas");
                        currTextBox = GameObject.Instantiate(DialogueEventController.dialogueBoxPrefab, DialogueEventController.dialogueCanvas.transform);
                    }
                    else // default to moving box
                    {
                        inStaticDialogue = false;
                        currTextBox      = GameObject.Instantiate(DialogueEventController.dialogueBoxFollowPrefab, DialogueEventController.dialogueCanvas.transform);
                        currTextBox.GetComponent <DialogueBoxFollow>().characterToFollow = entry.Value;
                    }
                }


                currTextBox.SetActive(false); // hide when not in use

                // set their nameplate
                foreach (Transform elem in currTextBox.GetComponentsInChildren <Transform>())
                {
                    if (elem.gameObject.tag == "Nameplate")
                    {
                        //Debug.Log("Setting " + entry.Key + "'s nameplate...");
                        elem.gameObject.GetComponent <TMP_Text>().text = entry.Key;
                    }
                }

                uiElements.Add(entry.Key, currTextBox);
            }
        }

        // show first text
        lineNum = 0;
        ShowLine(currentDialogue.lines[lineNum][0]);

        if (CheckIfNextHasOptions(lineNum)) // check if next dialogue has options; if it is, show it at the same time (with synopsis)
        {
            //Debug.Log("Showing options...");
            inBranch = true;
            lineNum++;
            // show options
            ShowOptions(currentDialogue.lines[lineNum]);
        }
    }
示例#14
0
    public static void ProgressDialogue()
    {
        if (lineNum + 1 < currentDialogue.lines.Count)
        {
            // progress dialogue if there are still lines
            lineNum++;

            if (CheckIfNextHasOptions(lineNum)) // check if next dialogue has options; if it is, show it at the same time (with synopsis)
            {
                // detect if next line is kiki
                string nextSpeaker = "";
                foreach (SpeechLine line in currentDialogue.lines[lineNum + 1])
                {
                    if (!string.IsNullOrEmpty(line.speakerName))
                    {
                        nextSpeaker = line.speakerName;
                        break;
                    }
                }

                // if it's branching, fetch the option route
                if (nextSpeaker == "KIKI")
                {
                    inBranch   = true;
                    isChoosing = true;
                    ShowLine(currentDialogue.lines[lineNum][0]);
                    ShowOptions(currentDialogue.lines[lineNum + 1]);
                }
                else
                {
                    foreach (SpeechLine line in currentDialogue.lines[lineNum])
                    {
                        if (line.optionNum == currOptionNum)
                        {
                            // show this dialogue if it matches the option num chosen
                            isChoosing = false;
                            ShowLine(line);
                            continue;
                        }
                    }
                }
            }
            else if (CheckIfThisHasOptions(lineNum))
            {
                foreach (SpeechLine line in currentDialogue.lines[lineNum])
                {
                    if (line.optionNum == currOptionNum)
                    {
                        // show this dialogue if it matches the option num chosen
                        isChoosing = false;
                        ShowLine(line);
                        continue;
                    }
                }
            }
            else
            {
                inBranch      = false;
                currOptionNum = -1;
                // show next dialogue
                ShowLine(currentDialogue.lines[lineNum][0]);
            }
        }
        else
        {
            // once you're out of lines, stop any effects
            //Debug.Log("Completing dialogue. Cleaning up...");
            RevertDialogueEffects();

            // clean up the UI elements
            foreach (GameObject elem in uiElements.Values)
            {
                GameObject.Destroy(elem);
            }

            // flush dialogue event vars
            inDialogue      = false;
            lineNum         = -1;
            currentDialogue = null;
            characters.Clear();
        }
    }
示例#15
0
 public Instruction(Character attacker, Character target, Attack attack, Announcer announcer, int turnCounter, DialogueText dialogueTextObject, SfxManager sfx
                    , Text blueChunk, Text redChunk)
 {
     this.attacker     = attacker;
     this.target       = target;
     this.attack       = attack;
     this.announcer    = announcer;
     this.turnCounter  = turnCounter;
     this.dialogueText = dialogueTextObject;
     this.sfx          = sfx;
     this.blueChunk    = blueChunk;
     this.redChunk     = redChunk;
 }
    // Parses a conversation
    private static Conversation parseConversation(XmlNode _node)
    {
        // Local variables
        int                 conversationID      = -1;
        string              conversationStartID = "";
        Conversation        conversation        = null;
        XmlNode             xmlNodeText         = null;
        XmlNode             xmlNodeAtt          = null;
        DialogueText        text     = null;
        List <DialogueText> textList = new List <DialogueText>();

        // Get attribute: id
        xmlNodeAtt = _node.Attributes.GetNamedItem("id");
        if (xmlNodeAtt == null)
        {
            Debug.LogError("Conversations need IDs!");
            return(null);
        }
        conversationID = int.Parse(xmlNodeAtt.Value);

        // Get attribute: start
        xmlNodeAtt = _node.Attributes.GetNamedItem("start");
        if (xmlNodeAtt == null)
        {
            Debug.LogError("Conversations need a start text ID!");
            return(null);
        }
        conversationStartID = xmlNodeAtt.Value;

        // Find first text node
        xmlNodeText = _node.SelectSingleNode("text");
        if (xmlNodeText == null)
        {
            Debug.LogError("No texts has been found!");
            return(null);
        }

        // Parse all texts
        do
        {
            // Skipable?
            if (isNodeSkipable(xmlNodeText) == false)
            {
                // Parse
                text = parseText(xmlNodeText);
                if (text == null)
                {
                    return(null);
                }

                // Add to list
                textList.Add(text);
            }

            // Next sibling
            xmlNodeText = xmlNodeText.NextSibling;
        }while (xmlNodeText != null);

        // Create conversation
        conversation = new Conversation(conversationID, conversationStartID, textList);

        return(conversation);
    }
示例#17
0
    // Validates a single text
    private bool validateText(Conversation _c, DialogueText _t)
    {
        // Local variables
        List <int> choiceIDs = null;
        TextPart   part      = null;
        Choice     choice    = null;

        // Check parameter
        if (_t == null)
        {
            return(false);
        }

        // Validate all text-parts
        for (int i = 0; i < _t.TextPartCount; ++i)
        {
            // Get text-part
            part = _t.getTextPartByIndex(i);
            if (part == null)
            {
                Debug.LogError("Invalid text-part!");
                return(false);
            }

            // Validate time
            if (part.DisplayTime <= 0)
            {
                Debug.LogError("Text-part has an invalid display time: " + part.DisplayTime);
                return(false);
            }
        }

        // Validate all choices
        choiceIDs = _t.getChoicesIDs();
        foreach (int id in choiceIDs)
        {
            // Get choice
            choice = _t.getChoiceByID(id);
            if (choice == null)
            {
                Debug.LogError("ID of the choice is invalid!");
                return(false);
            }

            // Next text AND exit value defined?
            if (choice.ExitValue != null && choice.ExitValue.Equals("") == false && choice.NextTextID != -1)
            {
                Debug.LogError("Choice can have a next target OR an exit value, not both!");
                return(false);
            }

            // Next target available (only if not script generated)?
            else if (choice.IsNextTextIDFunctionGenerated == false && choice.NextTextID != -1)
            {
                if (_c.getTextByID(choice.NextTextID) == null)
                {
                    Debug.LogError("Choice's target ID has not been found!");
                    return(false);
                }
            }

            // Initialize choice
            if (choice.initialize(this) == false)
            {
                Debug.LogError("Choice initialization failed!");
                return(false);
            }
        }

        // Auto generated/executed choice available?
        if (_t.AutoChoiceType != DialogueText.ChoiceType.CHOICE_NONE && choiceIDs.Count > 0)
        {
            Debug.LogWarning("Auto generated/executed choice in text (" + _t.TextID + ") will be overwritten by choices");
        }

        return(true);
    }
示例#18
0
    private void AcquireTextFromAvailableEntities()
    {
        if (_textProviders == null ||
            _textProviders.Length == 0)
        {
            return;
        }

        EntityText availableEntity = _textProviders.FirstOrDefault(t => t.CanTalk == true);

        if (DebugMode)
        {
            Debug.Log("There is " + (availableEntity == default(EntityText) ? "no" : "an") + " NPC that can talk.");
        }

        // Code Case: We no longer have an entity, but we still show there being dialogue.
        // User Case: Player has left a trigger with text still shown.
        // Desired Result: Stop showing text, reset line counter.
        if (availableEntity == default(EntityText) &&
            DialogueAvailable)
        {
            if (DebugMode)
            {
                Debug.Log("User has left a text trigger, so hide text.");
            }

            _currentThread.ResetIndex();
            DialogueAvailable = false;
            HideElements();
        }
        // Code Case: We have an entity, and we do not see any current dialogue.
        // User Case: Player has initiated a conversation sequence.
        // Desired Result: Start showing text, set line counter to first item, set speaker name.
        //                 Also, lock the player's player control script.
        else if (availableEntity != default(EntityText) &&
                 (!DialogueAvailable))
        {
            if (DebugMode)
            {
                Debug.Log("Player has initiated a conversation.");
            }

            _currentThread = availableEntity.CurrentThread(_ambassador.SequenceCounters);
            _currentThread.ResetIndex();

            DialogueText currentText = _currentThread.GetCurrentText();
            if (currentText != null)
            {
                PresentLine(currentText);
                DialogueAvailable = true;

                PlayerHasControl(false);
                ShowElements();
            }
        }

        // Code Case: We have both an entity and show dialogue
        // User Case: An conversation is on-going
        // Desired Result: Do not mess with it!

        // Code Case: We have no entity and show no dialogue [Default State]
        // User Case: User is doing some non-conversation activity
        // Desired Result: Do nothing.
    }