public IEnumerator TypeSentenceTest() { isTypeSentenceCoroutineRunning = true; Assert.IsTrue(isTypeSentenceCoroutineRunning); if (debugComponent) { Assert.IsTrue(debugComponent); Debug.Log("isTypeSentenceCoroutineRunning: " + isTypeSentenceCoroutineRunning); LogAssert.Expect(LogType.Log, "isTypeSentenceCoroutineRunning: " + isTypeSentenceCoroutineRunning); } DialogueTree.DialogueNode dialogueNode = dialogueNodeToPlay; Assert.AreEqual(dialogueNodeToPlay, dialogueNode); string nodeCharacterName = dialogueNode.nodeCharacterName; string nodeDialogueString = dialogueNode.nodeDialogueString; AudioClip nodeDialogueAudioClip = dialogueNode.nodeDialogueAudioClip; Assert.AreEqual(dialogueNode.nodeCharacterName, nodeCharacterName); Assert.AreEqual(dialogueNode.nodeDialogueString, nodeDialogueString); Assert.AreEqual(dialogueNode.nodeDialogueAudioClip, nodeDialogueAudioClip); // Set nodeCharacterName text fields with the nodeCharacterName of the person talking in the dialogueTree nameText.text = nodeCharacterName; nameVRText.text = nodeCharacterName; Assert.AreEqual(nodeCharacterName, nameText.text); Assert.AreEqual(nodeCharacterName, nameVRText.text); if (requireContinueButton) { Assert.IsTrue(requireContinueButton); inputContinueDialogueImage.gameObject.SetActive(false); inputContinueDialogueVRImage.gameObject.SetActive(false); Assert.IsTrue(inputContinueDialogueImage.gameObject.activeSelf); Assert.IsTrue(inputContinueDialogueVRImage.gameObject.activeSelf); } currentSentence = nodeDialogueString; Assert.AreEqual(nodeDialogueString, currentSentence); audioSource.Stop(); Assert.IsFalse(audioSource.isPlaying); if (playWithAudio) { Assert.IsTrue(playWithAudio); if (nodeDialogueAudioClip) { Assert.IsNotNull(nodeDialogueAudioClip); audioSource.PlayOneShot(nodeDialogueAudioClip, volume); Assert.IsTrue(audioSource.isPlaying); } else { Debug.LogError("No audioclip for string displayed! Please place audioclip in AudioClip List for respective string element."); LogAssert.Expect(LogType.Error, "No audioclip for string displayed! Please place audioclip in AudioClip List for respective string element."); } } else { Assert.IsFalse(playWithAudio); } if (instantPrintBegin) { Assert.IsTrue(instantPrintBegin); int punctutationCount = 0; Assert.AreEqual(0, punctutationCount); foreach (char letter in nodeDialogueString.ToCharArray()) { // If character is any form of punctutation, then delay next sentence. Otherwise, print normally. if (letter == ',' || letter == ';' || letter == '.' || letter == '?' || letter == '!') { Assert.IsTrue(letter == ',' || letter == ';' || letter == '.' || letter == '?' || letter == '!'); punctutationCount++; } } dialogueText.text = nodeDialogueString; // Display full sentence instantly dialogueVRText.text = nodeDialogueString; // Display full sentence instantly Assert.AreEqual(nodeDialogueString, dialogueText.text); Assert.AreEqual(nodeDialogueString, dialogueVRText.text); float fullSentenceDelay = (printLetterDelay * nodeDialogueString.Length) + (punctutationCount * sentenceDelay) + sentenceDelay; // (CharacterCount from current dialogueTreeElement * print delay time) + (number of punctuation characters * sentence delay time) + end of dialogueTreeElement delay time. Assert.AreEqual((printLetterDelay * nodeDialogueString.Length) + (punctutationCount * sentenceDelay) + sentenceDelay, fullSentenceDelay); if (debugComponent) { Assert.IsTrue(debugComponent); Debug.Log("fullSentenceDelay: " + fullSentenceDelay + ", nodeDialogueAudioClip.length: " + nodeDialogueAudioClip.length); LogAssert.Expect(LogType.Log, "fullSentenceDelay: " + fullSentenceDelay + ", nodeDialogueAudioClip.length: " + nodeDialogueAudioClip.length); } if (!requireContinueButton) { Assert.IsFalse(requireContinueButton); if (nodeDialogueAudioClip) { Assert.IsNotNull(nodeDialogueAudioClip); #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitForSeconds(nodeDialogueAudioClip.length)); #endif } else { Assert.IsNull(nodeDialogueAudioClip); #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitForSeconds(fullSentenceDelay)); #endif } isTypeSentenceCoroutineRunning = false; // This ensures that you can check if the coroutine is done. Assert.IsFalse(isTypeSentenceCoroutineRunning); DisplayNextSentenceTest(); } else { Assert.IsTrue(requireContinueButton); DisplayNextSentenceTest(); isTypeSentenceCoroutineRunning = false; // This ensures that you can check if the coroutine is done. Assert.IsFalse(isTypeSentenceCoroutineRunning); } } else { Assert.IsFalse(instantPrintBegin); dialogueText.text = ""; dialogueVRText.text = ""; Assert.AreEqual("", dialogueText.text); Assert.AreEqual("", dialogueVRText.text); foreach (char letter in nodeDialogueString.ToCharArray()) { string previousDialogueTextValue = dialogueText.text; string previousDialogueVRTextValue = dialogueVRText.text; dialogueText.text += letter; dialogueVRText.text += letter; Assert.AreEqual(dialogueText.text, previousDialogueTextValue + letter); Assert.AreEqual(dialogueVRText.text, previousDialogueVRTextValue + letter); // If character is any form of punctutation, then delay next sentence. Otherwise, print normally. if (letter == ',' || letter == ';' || letter == '.' || letter == '?' || letter == '!') { Assert.IsTrue(letter == ',' || letter == ';' || letter == '.' || letter == '?' || letter == '!'); #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitForSeconds(currentSentenceDelay)); // Delay next nodeDialogueString #endif } else { Assert.IsFalse(letter == ',' || letter == ';' || letter == '.' || letter == '?' || letter == '!'); #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitForSeconds(currentPrintLetterDelay)); // Delay character print #endif } } // If moving on with the next dialogue to type requires input, then if (!requireContinueButton) { Assert.IsFalse(requireContinueButton); // If last character is not any form of punctutation, then delay next sentence if (!(nodeDialogueString.EndsWith(",") || nodeDialogueString.EndsWith(";") || nodeDialogueString.EndsWith(".") || nodeDialogueString.EndsWith("?") || nodeDialogueString.EndsWith("!"))) { Assert.IsTrue(!(nodeDialogueString.EndsWith(",") || nodeDialogueString.EndsWith(";") || nodeDialogueString.EndsWith(".") || nodeDialogueString.EndsWith("?") || nodeDialogueString.EndsWith("!"))); #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitForSeconds(currentSentenceDelay)); #endif } #if UNITY_EDITOR yield return(null); // Used in edit mode only #else yield return(new WaitUntil(() => !audioSource.isPlaying)); // Wait until audioclip for the dialogue nodeDialogueString has stopped playing if it hasn't. #endif Assert.IsFalse(audioSource.isPlaying); isTypeSentenceCoroutineRunning = false; // This ensures that you can check if the coroutine is done. Assert.IsFalse(isTypeSentenceCoroutineRunning); DisplayNextSentenceTest(); } else { Assert.IsTrue(requireContinueButton); DisplayNextSentenceTest(); isTypeSentenceCoroutineRunning = false; // This ensures that you can check if the coroutine is done. Assert.IsFalse(isTypeSentenceCoroutineRunning); } } if (requireContinueButton) { Assert.IsTrue(requireContinueButton); inputContinueDialogueImage.gameObject.SetActive(true); inputContinueDialogueVRImage.gameObject.SetActive(true); Assert.IsTrue(inputContinueDialogueImage.gameObject.activeSelf); Assert.IsTrue(inputContinueDialogueVRImage.gameObject.activeSelf); // Update speed of animation with current settings inputContinueDialogueImage.GetComponent <Animator>().speed = inputContinueDialogueImageAnimationSpeed; inputContinueDialogueVRImage.GetComponent <Animator>().speed = inputContinueDialogueImageAnimationSpeed; Assert.AreEqual(inputContinueDialogueImageAnimationSpeed, inputContinueDialogueImage.GetComponent <Animator>().speed); Assert.AreEqual(inputContinueDialogueImageAnimationSpeed, inputContinueDialogueVRImage.GetComponent <Animator>().speed); } else { Assert.IsFalse(requireContinueButton); } if (debugComponent) { Assert.IsTrue(debugComponent); Debug.Log("isTypeSentenceCoroutineRunning: " + isTypeSentenceCoroutineRunning); LogAssert.Expect(LogType.Log, "isTypeSentenceCoroutineRunning: " + isTypeSentenceCoroutineRunning); } }
public void DisplayNextSentenceTest() { // 1 // Check to see if current nodeDialogueString is typing first if (isTypeSentenceCoroutineRunning) { Assert.IsTrue(isTypeSentenceCoroutineRunning); // 1a // Only used if input is required if (requireContinueButton) { Assert.IsTrue(requireContinueButton); // 1aa // Instant print the rest of the current nodeDialogueString if (instantPrintFinish) { Assert.IsTrue(instantPrintFinish); //StopAllCoroutines(); // Stop coroutine that is currently printing. dialogueText.text = currentSentence; dialogueVRText.text = currentSentence; Assert.AreEqual(currentSentence, dialogueText.text); Assert.AreEqual(currentSentence, dialogueVRText.text); isTypeSentenceCoroutineRunning = false; // Make sure this is false after nodeDialogueString is done typing. Assert.IsFalse(isTypeSentenceCoroutineRunning); } // 1ab else { Assert.IsFalse(instantPrintFinish); // 1aba // Change speed of the text without changing the value for the setting. Create private copy of the value. if (speedPrintFinish) { Assert.IsTrue(speedPrintFinish); // The fastest is actually one frame. currentPrintLetterDelay = 0.0f; currentSentenceDelay = 0.0f; Assert.AreEqual(0, currentPrintLetterDelay); Assert.AreEqual(0, currentSentenceDelay); } } // 1ac if (requireContinueButton) { Assert.IsTrue(requireContinueButton); inputContinueDialogueImage.gameObject.SetActive(true); inputContinueDialogueVRImage.gameObject.SetActive(true); // Update speed of animation with current settings inputContinueDialogueImage.GetComponent <Animator>().speed = inputContinueDialogueImageAnimationSpeed; inputContinueDialogueVRImage.GetComponent <Animator>().speed = inputContinueDialogueImageAnimationSpeed; Assert.IsTrue(inputContinueDialogueImage.gameObject.activeSelf); Assert.IsTrue(inputContinueDialogueVRImage.gameObject.activeSelf); Assert.AreEqual(inputContinueDialogueImageAnimationSpeed, inputContinueDialogueImage.GetComponent <Animator>().speed); Assert.AreEqual(inputContinueDialogueImageAnimationSpeed, inputContinueDialogueVRImage.GetComponent <Animator>().speed); } } return; } Assert.IsFalse(isTypeSentenceCoroutineRunning); // 2 // Reset delay times currentPrintLetterDelay = printLetterDelay; currentSentenceDelay = sentenceDelay; Assert.AreEqual(printLetterDelay, currentPrintLetterDelay); Assert.AreEqual(sentenceDelay, currentSentenceDelay); // 3 if (dialogueNodes.Count == 0) { Assert.AreEqual(0, dialogueNodes.Count); EndDialogue(); return; } Assert.AreNotEqual(0, dialogueNodes.Count); // 4 dialogueText.GetComponent <RectTransform>().sizeDelta = new Vector2(textDisplayWidth, dialogueText.GetComponent <RectTransform>().sizeDelta.y); dialogueVRText.GetComponent <RectTransform>().sizeDelta = new Vector2(textDisplayWidth, dialogueVRText.GetComponent <RectTransform>().sizeDelta.y); Assert.AreEqual(new Vector2(textDisplayWidth, dialogueText.GetComponent <RectTransform>().sizeDelta.y), dialogueText.GetComponent <RectTransform>().sizeDelta); Assert.AreEqual(new Vector2(textDisplayWidth, dialogueVRText.GetComponent <RectTransform>().sizeDelta.y), dialogueVRText.GetComponent <RectTransform>().sizeDelta); // 5 DialogueTree.DialogueNode dialogueNode = dialogueNodes.Peek(); int previousSentenceCount = dialogueNodes.Count; dialogueNodes.Dequeue(); Assert.AreEqual(previousSentenceCount - 1, dialogueNodes.Count); CollectionAssert.DoesNotContain(dialogueNodes, dialogueNode); // 6 if (debugComponent) { Assert.IsTrue(debugComponent); Debug.Log(dialogueNode.nodeCharacterName + ": " + dialogueNode.nodeDialogueString); LogAssert.Expect(LogType.Log, dialogueNode.nodeCharacterName + ": " + dialogueNode.nodeDialogueString); } // 7 //StopAllCoroutines(); // Stop coroutine before starting new one. // 8 //StartCoroutine(TypeSentenceTest(sentence, clip)); // Display or type one character at a time. // 9 dialogueNodeToPlay = dialogueNode; Assert.AreEqual(dialogueNode, dialogueNodeToPlay); }