public ENCAPSULATED_TEXT(string tag, string[] allSpeechAndTagsArray, int arrayProgress) { this.tag = tag; //this.endingTag = GenerateEndingTag(); GenerateEndingTag(); this.allSpeechAndTagArray = allSpeechAndTagsArray; this.arrayProgress = arrayProgress; if (allSpeechAndTagsArray.Length - 1 > arrayProgress) { string nextPart = allSpeechAndTagsArray[arrayProgress + 1]; bool isATag = ((arrayProgress + 1) & 1) != 0; if (!isATag) { targetText = nextPart; } else { subEncapsulator = new ENCAPSULATED_TEXT(string.Format("<{0}>", nextPart), allSpeechAndTagsArray, arrayProgress + 1); } //increment progress so the next attempted part is updated. this.arrayProgress++; } }
IEnumerator Construction() { int runsThisFrame = 0; string[] speechAndTags = useEncapsulation ? TagManager.SplitByTags(targetText) : new string[1] { targetText }; //Is this additive, make sure we include additive text _currentText = preText; //make a storage for the building text so we don't change what is already made. so we can sandwich it between tags. string curText = ""; //build the text by moving through each part for (int a = 0; a < speechAndTags.Length; a++) { string section = speechAndTags[a]; //tags will always be odd indexed bool isATag = (a & 1) != 0; //Sexy bitwise manipulation, this guy knows his stuff if (isATag && useEncapsulation) { if (!isTMPro) { curText = _currentText; ENCAPSULATED_TEXT encapsulation = new ENCAPSULATED_TEXT(string.Format("<{0}>", section), speechAndTags, a); while (!encapsulation.isDone) { bool stepped = encapsulation.Step(); _currentText = curText + encapsulation.displayText; //Only yield if a step was taken in building the string if (stepped) { runsThisFrame++; int maxRunsPerFrame = skip ? 5 : charactersPerFrame; if (runsThisFrame == maxRunsPerFrame) { runsThisFrame = 0; yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * speed)); } } } a = encapsulation.speechAndTagsArrayProgress + 1; } else { string tag = string.Format("<{0}>", section); _currentText += tag; yield return(new WaitForEndOfFrame()); } //Increment by one to bypass the text that was used in the encapsulation } else //not a tag or not using encap. build like regular text. { for (int i = 0; i < section.Length; i++) { _currentText += section[i]; runsThisFrame++; int maxRunsPerFrame = skip ? 5 : charactersPerFrame; if (runsThisFrame == maxRunsPerFrame) { runsThisFrame = 0; yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * speed)); } } } } buildProcess = null; }
///<summary> /// Take the next step in the construction rocess. returns true if a step was taken. returns false if a step must be made from a lower level encapsulator. /// </summary> public bool Step() { //a completed encapsulation should not step any further. Return true so if there is an error, yielding may occur if (isDone) { return(true); } if (subEncapsulator != null && !subEncapsulator.isDone) { return(subEncapsulator.Step()); } //this encapsulator needs to finish its text else { //this encapsulator has reached the end of its text if (currentText == targetText) { //If there is still more dialogue to build if (allSpeechAndTagsArray.Length > arrayProgress + 1) { string nextPart = allSpeechAndTagsArray[arrayProgress + 1]; bool isATag = ((arrayProgress + 1) & 1) != 0; if (isATag) { //if the tag we have just reached is the terminator for this encapsulator, close it if (string.Format("<{0}>", nextPart) == endingTag) { _isDone = true; if (encapsulator != null) { string taggedText = tag + currentText + endingTag; encapsulator.currentText += taggedText; encapsulator.targetText += taggedText; //update array progress to get past the current text AND the ending tag. +2 UpdateArrayProgress(2); } } //If the tag we reached is not the terminator for this encapsulator, then a sub encapsulator must be created. else { subEncapsulator = new ENCAPSULATED_TEXT(string.Format("<{0}>", nextPart), allSpeechAndTagsArray, arrayProgress + 1); subEncapsulator.encapsulator = this; //have the encapsulators keep up with the current progress UpdateArrayProgress(); } } //If the next part is not a tag, then this is an extension to be added to the encapsulator's target. else { targetText += nextPart; UpdateArrayProgress(); } } //Finished dialogue. Close else { _isDone = true; } } //if there is still more to build else { currentText += targetText[currentText.Length]; //update the display text. which means we have to update any encapsulators if this is a sub encapsulator UpdateDisplay(""); return(true); } } return(false); }
IEnumerator Construction() { int runsThisFrame = 0; string[] speechAndTags = useEncapsulation ? TagManager.SplitByTags(targetText) : new string[1] { targetText }; //if this is aditive,make sure to include aditive text _currentText = preText; //make a storage variable so we dont chnage whats been made already string curTxt = ""; //build text by moving through each part for (int a = 0; a < speechAndTags.Length; a++) { string section = speechAndTags[a]; //tags will always be odd indexed bool isATag = (a & 1) != 0; if (isATag && useEncapsulation) { if (!isTMPro) { curTxt = _currentText; ENCAPSULATED_TEXT encapsulation = new ENCAPSULATED_TEXT(string.Format("<{0}>", section), speechAndTags, a); while (!encapsulation.isDone) { bool stepped = encapsulation.Step(); _currentText = curTxt + encapsulation.displayText; //only yield if a step was taken in building the string if (stepped) { runsThisFrame++; int maxRunsPerFrame = skip ? 5 : charactersPerFrame; if (runsThisFrame == maxRunsPerFrame) { runsThisFrame = 0; yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * speed)); } } } a = encapsulation.speechAndTagsArrayProgress + 1; } else { string tag = string.Format("<{0}>", section); _currentText += tag; yield return(new WaitForEndOfFrame()); } } else { for (int i = 0; i < section.Length; i++) { _currentText += section[i]; runsThisFrame++; int maxRunsPerFrame = skip ? 5 : charactersPerFrame; if (runsThisFrame == maxRunsPerFrame) { runsThisFrame = 0; yield return(new WaitForSeconds(skip ? 0.01f : 0.01f * speed)); } } } } buildProcess = null; }
public bool Step() { if (isDone) { return(true); } if (subEncapsulator != null && !subEncapsulator.isDone) { return(subEncapsulator.Step()); } else { if (currentText == targetText) { if (allSpeechAndTagArray.Length > arrayProgress + 1) { string nextPart = allSpeechAndTagArray[arrayProgress + 1]; bool isATag = ((arrayProgress + 1) & 1) != 0; if (isATag) { if (string.Format("<{0}>", nextPart) == endingTag) { _isDone = true; if (encapsulator != null) { string taggedText = (tag + currentText + endingTag); encapsulator.currentText += taggedText; encapsulator.targetText += taggedText; UpdateArrayProgress(2); } } else { subEncapsulator = new ENCAPSULATED_TEXT(string.Format("<{0}>", nextPart), allSpeechAndTagArray, arrayProgress + 1); subEncapsulator.encapsulator = this; UpdateArrayProgress(); } } else { targetText += nextPart; UpdateArrayProgress(); } } else { _isDone = true; } } else { currentText += targetText[currentText.Length]; UpdateDisplay(""); return(true); } } return(false); }