public static StoryPara[] GetStoryParas(TextAsset textAsset) { string strStory = textAsset.text; List <StoryPara> list = new List <StoryPara>(); while (!strStory.Equals(string.Empty)) { string line = string.Empty; int index = Mathf.Min(strStory.IndexOf('\r'), strStory.IndexOf('\n')); if (index < 0) { line = strStory; strStory = string.Empty; } else { line = strStory.Substring(0, index); strStory = strStory.Substring(index + 1); } if (line != string.Empty) { string[] contents = line.Split('|'); float x = float.Parse(contents[0]); float y = float.Parse(contents[1]); string text = contents[2]; for (int i = 3; i < contents.Length; i++) { text += '\n' + contents[i]; } StoryPara para = new StoryPara(x, y, text); list.Add(para); } } return(list.ToArray()); }
private void Awake() { story = StoryPara.GetStoryParas(textAsset); }
IEnumerator ShowPara() { StoryPara para = currentStory[currentPara]; if (!para.IsTag) { storyBoard.AddText(para.x, para.y); currentChar = 0; float time = 0f; float efxTime = 0f; bool isSpeedUp = false; while (currentChar < para.Length) { yield return(null); if (STBInput.GetButtonDown("Next")) { isSpeedUp = true; } if (STBInput.GetButtonUp("Next")) { isSpeedUp = false; } if (STBInput.GetButton("Skip")) { currentChar = para.Length - 1; } time += Time.deltaTime * (isSpeedUp ? 5f : 1f); efxTime += Time.deltaTime; if (time > TEXT_GAP) { currentChar++; if (efxTime >= TEXT_GAP) { SoundManager.instance.PlayUiEfx(UiEfx.TEXT); while (efxTime >= TEXT_GAP) { efxTime -= TEXT_GAP; } } storyBoard.SetText(para.Substring(currentChar)); if (para.GetChar(currentChar - 1).Equals('\n')) { time -= TEXT_GAP * 5f; } else { time -= TEXT_GAP; } } } isParaOver = true; paraEndMark.Set(GetActPos(storyBoard.GetEndPosition())); currentPara++; para = currentStory[currentPara]; } if (para.IsTag) { currentPara++; if (para.IsBgmPlay) { SoundManager.instance.PlayBgm(bgm, 2f); } if (para.IsBgmStop) { SoundManager.instance.StopBgm(1f); } if (para.IsPageEnd) { paraEndMark.Hide(); pageEndMark.Set(); isPageOver = true; yield break; } if (para.IsClipEnd) { OnSceneEnd(); yield break; } if (!isParaOver) { StartCoroutine(ShowPara()); } } }