IEnumerator DisplayNextSentence() { if (segments.Count == 0) { EndDialogue(); yield break; } DialogueSegment segment = segments.Dequeue(); nameText.text = segment.dialogueName; Coroutine typeSentenceRoutine = null; StartDialogue(); if (typeSentenceRoutine != null) { StopCoroutine(typeSentenceRoutine); } typeSentenceRoutine = StartCoroutine(TypeSentence(segment.dialogueText)); yield return(WaitForText()); pressSpace.SetActive(true); while (!Input.GetKeyDown(KeyCode.Space)) { yield return(null); } StartCoroutine(DisplayNextSentence()); }
public void Act(DialogueSegment dialogueSegment) { //particles if (dialogueSegment.particles != null) { Instantiate(dialogueSegment.particles); } //animations if (dialogueSegment.animation != null) { animator.Play(dialogueSegment.animation.name); } }
public void EnterDialogue() { listeningForSkips = false; startTime = Time.time; ClearTextBox(); currentDialogueSegmentIndex = 0; currentDialogueSegment = dialogueScene.segments[0]; currentTranslatedDialogueText = currentDialogueSegment.dialogueString; dialogueBox.SetActive(true); inDialogue = true; //start listening after 0.1f seconds Invoke("StartListeningForSkips", 0.1f); }
/// <summary> /// Tally up all the different items /// </summary> private void BuildPurchaseString() { //exit early: avoid dialogue when in dialogue DialogueManager dialogue = FindObjectOfType <DialogueManager>(); if (dialogue.inDialogue) { return; } //get total cost Counter counter = FindObjectOfType <Counter>(); float totalPrice = counter.GetTotalCost(); //get items list string purchases = "You are going to purchase "; ItemData[] items = counter.GetAllCurrentItems(); List <string> itemNames = new List <string>(); foreach (var item in items) { itemNames.Add(item.itemName); } //add commas to the items string and a period string itemsString = Commaize(itemNames); purchases += itemsString + "."; //format the price float ###,###.## string formattedPrice = totalPrice.ToString("N"); string costString = "Which will cost you " + formattedPrice + "€ alltogether."; //create dialogue scene by building it from dialogue segments DialogueSegment segment1 = new DialogueSegment(purchases); DialogueSegment segment2 = new DialogueSegment(costString); //combine the scene DialogueScene scene = new DialogueScene(new DialogueSegment[] { segment1, segment2 }); //display the dialogue dialogue.LoadDialogueScene(scene); dialogue.EnterDialogue(); }
// Update is called once per frame void LateUpdate() { if (inDialogue) { int length = Mathf.Min(currentTranslatedDialogueText.Length, (int)(lettersPerSecond * (Time.time - startTime))); //display letter after letter if (dialogueText.text != currentTranslatedDialogueText) { dialogueText.text = currentTranslatedDialogueText.Substring(0, length); } //Skip dialogue text if (GetValidSkip()) { //show all text if (dialogueText.text != currentTranslatedDialogueText) { dialogueText.text = currentTranslatedDialogueText; } else //if there are more dialogue segments to display, display a new one if (currentDialogueSegmentIndex < dialogueScene.segments.Length - 1) { currentDialogueSegmentIndex++; currentDialogueSegment = dialogueScene.segments[currentDialogueSegmentIndex]; currentTranslatedDialogueText = currentDialogueSegment.dialogueString; ClearTextBox(); } else { //dialogue is finished if (dialogueFinished != null) { dialogueFinished.Invoke(); dialogueFinished = null; } HideTextBox(); } } } }
// Update is called once per frame void LateUpdate() { if (inDialogue) { int length = Mathf.Min(currentTranslatedDialogueText.Length, (int)(lettersPerSecond * (Time.time - startTime))); //display letter after letter if (dialogueText.text != currentTranslatedDialogueText) { dialogueText.text = currentTranslatedDialogueText.Substring(0, length); HandleVoice(); } else { AudioManager.instance.StopEvent(currentDialogueSegment.dialogueSpeaker.voiceEvent, 0); } //Skip dialogue text if (GetValidSkip()) { //show all text if (dialogueText.text != currentTranslatedDialogueText) { dialogueText.text = currentTranslatedDialogueText; } else //if there are more dialogue segments to display, display a new one if (currentDialogueSegmentIndex < dialogueScene.dialogueSegments.Length - 1) { currentDialogueSegmentIndex++; currentDialogueSegment = dialogueScene.dialogueSegments[currentDialogueSegmentIndex]; currentTranslatedDialogueText = translator.GetTranslation(currentDialogueSegment.dialogueString); ClearTextBox(); UpdateSpeakerInfo(); } else { HideTextBox(); } } } }
private void InformToAddItems() { //create dialogue scene by building it from dialogue segments DialogueManager dialogue = FindObjectOfType <DialogueManager>(); //avoid dialogue while in dialogue if (dialogue.inDialogue) { return; } DialogueSegment segment1 = new DialogueSegment("You need to add something to the counter first."); DialogueSegment segment2 = new DialogueSegment("Click the items in the shelf on the left to add them."); //combine the scene DialogueScene scene = new DialogueScene(new DialogueSegment[] { segment1, segment2 }); //display the dialogue dialogue.LoadDialogueScene(scene); dialogue.EnterDialogue(); }
/// <summary> /// Notify the player that they have placed too many items on the counter /// </summary> public void NotifyTooManyItems() { //create dialogue scene by building it from dialogue segments DialogueManager dialogue = FindObjectOfType <DialogueManager>(); //avoid dialogue while in dialogue if (dialogue.inDialogue) { return; } DialogueSegment segment1 = new DialogueSegment("You can only have five items at once."); DialogueSegment segment2 = new DialogueSegment("Please remove an item on the counter by clicking on it."); //combine the scene DialogueScene scene = new DialogueScene(new DialogueSegment[] { segment1, segment2 }); //display the dialogue dialogue.LoadDialogueScene(scene); dialogue.EnterDialogue(); }
public void EnterDialogue() { if (GameController.instance != null) { //disable the players GameController.instance.player1.enabled = false; GameController.instance.player2.enabled = false; } listeningForSkips = false; startTime = Time.time; ClearTextBox(); currentDialogueSegmentIndex = 0; currentDialogueSegment = dialogueScene.dialogueSegments[0]; currentTranslatedDialogueText = translator.GetTranslation(currentDialogueSegment.dialogueString); UpdateSpeakerInfo(); gameplayUI.SetActive(false); dialogueBox.SetActive(true); inDialogue = true; //start listening after 0.1f seconds Invoke("StartListeningForSkips", 0.1f); }