public static List <Talk> TextFileToTalks(string path) { List <Talk> talks = null; using (var fin = new FileStream(path, FileMode.Open, FileAccess.Read)) { talks = new List <Talk>(); var rxName = new Regex(@"^\[(.+?)\]"); var rxEmptyLine = new Regex(@"^\s*$"); var castName = ""; var baseParam = new List <TalkParam>(); float baseWait = 0.0f; var sr = new StreamReader(fin); string line; while ((line = sr.ReadLine()) != null) { var matcheName = rxName.Match(line); if (matcheName.Success) { castName = matcheName.Groups[1].Value; var cast = RemoteTalkProvider.FindCast(castName); if (cast != null) { baseParam = TalkParam.Clone(cast.paramInfo).ToList(); } else { baseParam.Clear(); } TalkParam.Merge(baseParam, ExtractTalkParams(ref line, ref baseWait)); } else if (!rxEmptyLine.IsMatch(line)) { var param = TalkParam.Clone(baseParam); float wait = -1.0f; TalkParam.Merge(param, ExtractTalkParams(ref line, ref wait, true)); if (wait < 0.0f) { wait = baseWait; } var talk = new Talk(); talk.castName = castName; talk.param = param.ToArray(); talk.wait = wait; talk.text = line; talks.Add(talk); } } } return(talks); }
public void Stop() { if (isPlaying) { if (m_prevProvider != null) { m_prevProvider.Stop(); } isPlaying = false; m_current = null; m_prevProvider = null; } }
void UpdateTalk() { if (!isPlaying || !isActiveAndEnabled) { return; } #if UNITY_EDITOR var delta = (float)(EditorApplication.timeSinceStartup - m_prevTime); m_prevTime = EditorApplication.timeSinceStartup; #else var delta = Time.deltaTime; #endif if (m_prevProvider == null || m_prevProvider.isReady) { if (m_talkPos >= m_talks.Count) { isPlaying = false; } else { if (m_current != null && m_wait < m_current.wait) { m_wait += delta; } else { m_current = m_talks[m_talkPos++]; if (m_current != null) { var provider = m_current.provider; if (provider != null) { provider.Play(m_current); } m_prevProvider = provider; m_wait = 0.0f; } } } #if UNITY_EDITOR Misc.RefreshWindows(); #endif } }