public void LoadScreen(string screenName) { Initialize(); screenName = screenName.ToLower(); ClearScreen(); if (!screens.ContainsKey(screenName)) { Debug.LogError("Story Screen named [" + screenName + "] was not found!"); return; } currentScreen = screens[screenName]; StoryManager.MarkStoryAsRead(screenName); isScreenFinished = false; isFinished = false; Background.sprite = currentScreen.BackgroundImage != null ? currentScreen.BackgroundImage : StoryManager.Instance.DefaultBackground; if (currentScreen.Music != null) { FMODManager.Play(currentScreen.Music.Value); } else if (currentScreen.StopMusic) { FMODManager.StopMusic(); } gameObject.SetActive(true); }
void Update() { if (isFinished) { return; } MoveBackground(); if (!isScreenFinished && !paused) { var SecondsPerPart = 1f / StoryManager.Instance.CharsPerSecond; bool isTimeForNewChar = Time.time - LastPartTime - LastPartDelay > SecondsPerPart; while (isFastingForward || isTimeForNewChar) { char nextChar = currentScreen.Dialog[currBit]; int lastDialogCharIndex = (currentScreen.Dialog.Length - 1); //Handle command if (nextChar == '[') { while (nextChar == '[') { //found a command, don't count this char for typing //try to get all character until finding a ']' to end the command List <char> commandChars = new List <char>(); currBit++; bool foundCommandEnd = false; for (; currBit <= lastDialogCharIndex; currBit++) { nextChar = currentScreen.Dialog[currBit]; if (nextChar == ']') { foundCommandEnd = true; //skip ']' and set the char after it as the next char if (currBit < lastDialogCharIndex) { currBit++; nextChar = currentScreen.Dialog[currBit]; } else { //Last char in dialog was a ']' //no need to type anymore. isScreenFinished = true; } break; } else { commandChars.Add(currentScreen.Dialog[currBit]); } } if (!foundCommandEnd) { throw new System.InvalidOperationException("Invalid dialog syntx! command was opened with a [ character, but never closed with a ] character."); } var commandParts = new string(commandChars.ToArray()) .Split(':') .Select(x => x.Trim().ToLower()) .Where(x => x != string.Empty) .ToArray(); var result = RunCommand(commandParts); if (isScreenFinished || paused || result.IsStopping) { return; } } } else //handle next char { //skip sounds if fasting forward if (!isFastingForward) { FMODClip[] clipsSource; switch (nextChar) { case ' ': case '\n': case '\t': case '\r': clipsSource = null; LastPartDelay = 0f; break; case ',': clipsSource = currentCharacterSound.RandomizedBits; LastPartDelay = StoryManager.Instance.CommaDelay; break; case '.': clipsSource = currentCharacterSound.RandomizedBits; LastPartDelay = StoryManager.Instance.PeriodDelay; break; case '?': if (currentCharacterSound.AskBits != null && currentCharacterSound.AskBits.Length > 0) { clipsSource = currentCharacterSound.AskBits; } else { clipsSource = currentCharacterSound.RandomizedBits; } LastPartDelay = StoryManager.Instance.PeriodDelay; break; case '!': if (currentCharacterSound.SayBits != null && currentCharacterSound.SayBits.Length > 0) { clipsSource = currentCharacterSound.SayBits; } else { clipsSource = currentCharacterSound.RandomizedBits; } LastPartDelay = StoryManager.Instance.PeriodDelay; break; default: clipsSource = currentCharacterSound.RandomizedBits; LastPartDelay = 0f; break; } if (clipsSource != null && clipsSource.Length > 0) { FMODManager.Play(clipsSource[Random.Range(0, clipsSource.Length - 1)]); } } //DialogTextOld.text += nextChar; DialogText.text += nextChar; currBit++; LastPartTime = Time.time; } //stop loop //if we're fasting forward and the dialog was not paused, continue loop isTimeForNewChar = false; if (paused) { isFastingForward = false; } } } }