private IEnumerator FlashLetterInWordCoroutine(LetterData letterToFlash, Color color)
{
if (letterData is LL_WordData) {
var splitLetters = ArabicAlphabetHelper.SplitWord(AppManager.I.DB, ((LL_WordData)letterData).Data);
int charPosition = 0;
List<int> foundLetterIndices = new List<int>();
for (int index = 0; index < splitLetters.Count; ++index) {
if (splitLetters[index].letter.Id == letterToFlash.Id) {
foundLetterIndices.Add(charPosition);
}
charPosition += splitLetters[index].letter.GetStringForDisplay().Length;
}
if (foundLetterIndices.Count != 0) {
string originalText = ((LL_WordData)letterData).TextForLivingLetter;
letterObjectView.Label.SetText(originalText);
float timeElapsed = 0f;
int numCompletedCycles = 0;
float halfDuration = FLASH_CYCLE_DURATION * 0.5f;
string preparedText = ArabicAlphabetHelper.ProcessArabicString(originalText);
preparedText = originalText;
while (numCompletedCycles < NUM_FLASH_CYCLES) {
float interpolant = timeElapsed < halfDuration
? timeElapsed / halfDuration
: 1 - ((timeElapsed - halfDuration) / halfDuration);
string tagStart = "<color=#" + GenericHelper.ColorToHex(Color.Lerp(Color.black, color, interpolant)) + ">";
string tagEnd = "</color>";
string composedString = "";
for (int i = 0; i < foundLetterIndices.Count; i++) {
int startIdx = i == 0 ? 0 : foundLetterIndices[i - 1] + letterToFlash.GetStringForDisplay().Length;
int endIdx = foundLetterIndices[i] - 1;
composedString += preparedText.Substring(startIdx, endIdx - startIdx + 1);
composedString += tagStart;
composedString += preparedText.Substring(foundLetterIndices[i], letterToFlash.GetStringForDisplay().Length);
composedString += tagEnd;
}
composedString += preparedText.Substring(foundLetterIndices[foundLetterIndices.Count - 1] + letterToFlash.GetStringForDisplay().Length);
letterObjectView.Label.SetText(composedString);
timeElapsed += Time.fixedDeltaTime;
if (timeElapsed >= FLASH_CYCLE_DURATION) {
numCompletedCycles++;
timeElapsed = 0f;
}
yield return new WaitForFixedUpdate();
}
letterObjectView.Label.SetText(originalText);
}
}
flashLetterInWordCoroutine = null;
}