IEnumerator DialogueOptionsRoutine(DialogueChunk dialogueChunk) { for (int i = 0; i < dialogueChunk.responses.Length; i++) { GetOptionTexts()[i].color = GetOptionTexts()[i].color.SetA(1f); GetOptionTexts()[i].text = dialogueChunk.responses[i].response; } EventSystem.current.firstSelectedGameObject = _optionButtons[0].gameObject; EventSystem.current.SetSelectedGameObject(EventSystem.current.firstSelectedGameObject); yield return(new WaitForSeconds(0.2f)); while (true) { if (EventSystem.current.currentSelectedGameObject == null) { EventSystem.current.firstSelectedGameObject = _optionButtons[0].gameObject; EventSystem.current.SetSelectedGameObject(EventSystem.current.firstSelectedGameObject); } else { List <Player> players = PlayerManager.GetSpawnedPlayers(); for (int j = 0; j < players.Count; j++) { Player player = players[j]; if (player.GetInfo().IsHuman()) { PlayerManualInput manualInput = (player.GetInput() as PlayerManualInput); if (manualInput && manualInput.JumpPressed()) { goto selectedOption; } } } } yield return(null); } selectedOption: // Mark which dialogue option we've chosen for (int i = 0; i < _optionButtons.Length; i++) { if (EventSystem.current.currentSelectedGameObject == _optionButtons[i].gameObject) { dialogueChunk.chosenResponseID = i; break; } } for (int i = 0; i < dialogueChunk.responses.Length; i++) { _optionButtons[i].gameObject.SetActive(false); } }
public void StartDialogueChunk(DialogueChunk dialogueChunk) { if (dialogueText == null) { return; } isDialoguing = true; dialogueDisplay.gameObject.SetActive(true); currentDialogueChunk = dialogueChunk; dialogueText.Clear(); foreach (string sentence in dialogueChunk.stenences) { dialogueText.Enqueue(sentence); } ShowNextDialogueText(); }
//Called when the player uses the "ask about" box, to see if they inputed a valid keyword. If so, set up the related chunk. public void tryNewChunk(string check) { string[] buffer; foreach (DialogueChunk chunk in formattedScript) { if (chunk.headerDialogue.TryGetValue(check.ToLower(), out buffer)) { returnToMainView(); currentDialogue = buffer; foreach (Button button in buttons) { button.gameObject.SetActive(false); } buttons[4].gameObject.SetActive(true); buttons[5].gameObject.SetActive(true); currentChunk = chunk; currentOptions = new string[currentChunk.chosenOptions.Length]; int i = 0; EnableInteraction(); foreach (string key in currentChunk.dialogueOptions.Keys) { currentOptions[i] = key; buttons[i].interactable = true; dialogueAndOpts[i + 1].text = key; i++; } EnableInteraction(); dialogueAndOpts[0].text = formatNewLine(currentDialogue[0]); if (currentDialogue.Length > 1) { DisableInteraction(); nextLine = 1; } return; } } print("New Chunk Failed, we'll get em next time"); }
private void EndDialogue() { isDialoguing = false; currentDialogueChunk = null; dialogueDisplay.gameObject.SetActive(false); }
IEnumerator ReadChunkRoutine(DialogueChunk dialogueChunk, PlayerNPCInput npc, GameSound voiceEventOverride) { bool hasNPC = (npc != null); if (_showWidgetRoutine != null) { StopCoroutine(_showWidgetRoutine); } _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(true)); yield return(_showWidgetRoutine); if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Choice) { _optionLayout.SetActive(true); for (int i = 0; i < dialogueChunk.responses.Length; i++) { _optionButtons[i].gameObject.SetActive(true); GetOptionTexts()[i].color = GetOptionTexts()[i].color.SetA(0f); GetOptionTexts()[i].text = dialogueChunk.responses[i].response; } } string dialogueText = LocUtils.Translate(dialogueChunk.dialogueTerm); foreach (KeyValuePair <string, string> kvp in _locDynamicText) { if (dialogueText.Contains(kvp.Key)) { dialogueText = dialogueText.Replace(kvp.Key, LocUtils.Translate(kvp.Value)); } } if (_textSpeed > Mathf.Epsilon) { _lineText.text = dialogueText; if (_resetMouthRoutine != null) { StopCoroutine(_resetMouthRoutine); _resetMouthRoutine = null; } GameSound dialogueSound = voiceEventOverride; if (dialogueSound == GameSound.NONE) { string soundName = "SFX_UI_Dialogue_" + dialogueChunk.character.ToString(); if (Enum.IsDefined(typeof(GameSound), soundName)) { dialogueSound = (GameSound)Enum.Parse(typeof(GameSound), soundName); } } GameSounds.PostEvent2D(dialogueSound); float lineStartTime = Time.time; for (int i = 0; i < dialogueText.Length; i++) { // Skip rich text if (dialogueText[i] == '<') { while (dialogueText[i] != '>') { i++; } i++; } _lineText.ScaleCharacter(i); float timer = 0; while (timer < _textSpeed) { if (hasNPC && npc.GetPlayer().HasMouthBlend()) { float timeSinceLineState = Time.time - lineStartTime; float mouthBlendWeight = (Mathf.Sin(timeSinceLineState * _mouthFlapSpeed * Mathf.PI) * 0.5f + 0.5f) * 100f; if (npc.GetPlayer().GetSkinnedMeshRenderer()) { npc.GetPlayer().GetSkinnedMeshRenderer().SetBlendShapeWeight(npc.GetPlayer().GetMouthBlendIndex(), mouthBlendWeight); } } if (!GameManager.GSM.IsStateActive(GameStateType.PauseMenu) && InputManager.ActiveDevice.AnyButtonWasPressed) { _lineText.ForceAllScaled(); goto lineFinished; } timer += Time.deltaTime; yield return(null); } } lineFinished: if (hasNPC && npc.GetPlayer().HasMouthBlend()) { _resetMouthRoutine = StartCoroutine(ResetMouthRoutine(npc)); } if (dialogueSound != GameSound.NONE) { GameSounds.PostEvent2D(dialogueSound, EventAction.StopSound); } } else { _lineText.text = dialogueText; } if (dialogueChunk.chunkType == DialogueChunk.ChunkType.Default) { _continuePrompt.SetActive(true); yield return(null); while (!InputManager.ActiveDevice.AnyButtonWasPressed) { yield return(null); } if (_continuePrompt != null) { _continuePrompt.SetActive(false); } } else { yield return(StartCoroutine(DialogueOptionsRoutine(dialogueChunk))); } _lineText.text = string.Empty; if (_showWidgetRoutine != null) { StopCoroutine(_showWidgetRoutine); } _showWidgetRoutine = StartCoroutine(ShowWidgetRoutine(false)); yield return(_showWidgetRoutine); _readChunkRoutine = null; }