StoryDialogView.cs 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849
  1. using FairyGUI;
  2. using UnityEngine;
  3. using UI.Main;
  4. using System.Collections;
  5. using System.Collections.Generic;
  6. using System.Text.RegularExpressions;
  7. using System;
  8. namespace GFGGame
  9. {
  10. public delegate void OnCompleteStoryDialogCall(bool isSkip, object param);
  11. public class StoryDialogView : BaseView
  12. {
  13. private UI_StoryDialogUI _ui;
  14. private UI_CompArrow _arrow;
  15. private GameObject _sceneObject;
  16. private EffectUI _effectUI1;
  17. private DressUpObjUI _dressUpObjUI;
  18. private GTextField _wordTextField;
  19. //剧情完成回调
  20. private OnCompleteStoryDialogCall _onCompleteStoryDialogCall;
  21. private object _onCompleteStoryDialogCallParam;
  22. //回顾
  23. private List<string> _dialogListLookBack;
  24. //自动播放
  25. private int _speedAutoPlay = 1;
  26. private bool _autoPlay = false;
  27. //剧情状态
  28. private List<StoryDialogCfg> _stepListToRead;
  29. private StoryDialogCfg _currentStepCfg;
  30. private string _nextStepId;
  31. private string[] _wordList;
  32. private int _wordIndex = 0;
  33. private bool _isShowLetters;
  34. private bool _canClickBtnNext;
  35. private string _currentWords;
  36. private string _storyStartID;
  37. private string lastTextFieldType; // 上一段文本框的类型
  38. private bool IsTeaParty; //是否是茶话会里的对话
  39. TypingFadeEffectPro _typingEffect;
  40. //屏幕效果中
  41. private Action<object> _onScreenEffectComplete;
  42. public override void Dispose()
  43. {
  44. if (_sceneObject != null)
  45. {
  46. PrefabManager.Instance.Restore(_sceneObject);
  47. _sceneObject = null;
  48. }
  49. _dressUpObjUI?.Dispose();
  50. _dressUpObjUI = null;
  51. _wordTextField = null;
  52. _arrow = null;
  53. _isShowLetters = false;
  54. EffectUIPool.Recycle(_effectUI1);
  55. _effectUI1 = null;
  56. _onScreenEffectComplete = null;
  57. _typingEffect = null;
  58. if (_ui != null)
  59. {
  60. _ui.Dispose();
  61. _ui = null;
  62. }
  63. base.Dispose();
  64. }
  65. protected override void OnInit()
  66. {
  67. base.OnInit();
  68. packageName = UI_StoryDialogUI.PACKAGE_NAME;
  69. _ui = UI_StoryDialogUI.Create();
  70. viewCom = _ui.target;
  71. isfullScreen = true;
  72. isReturnView = true;
  73. _ui.m_dialogText.target.visible = false;
  74. _ui.m_dialogName.target.visible = false;
  75. _ui.m_dialogHead.target.visible = false;
  76. _ui.m_list.visible = false;
  77. _ui.m_btnNext.width = GRoot.inst.width;
  78. _ui.m_btnNext.height = GRoot.inst.height;
  79. _ui.m_btnNext.AddRelation(GRoot.inst, RelationType.Size);
  80. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  81. _ui.m_btnNext.onClick.Add(OnClickBtnNext);
  82. _ui.m_btnLookBack.onClick.Add(OnClickBtnLookBack);
  83. _ui.m_btnSkip.onClick.Add(OnBtnSkip);
  84. _ui.m_list.onClickItem.Add(OnClickListItem);
  85. _ui.m_btnSpeedUp.onClick.Add(OnClickBtnSpeedUp);
  86. _ui.m_btnAutoPlay.onClick.Add(OnClickBtnAutoPlay);
  87. }
  88. protected override void OnShown()
  89. {
  90. base.OnShown();
  91. if (_sceneObject == null)
  92. {
  93. _sceneObject = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetPrefabPath("SceneStoryDialog"));
  94. }
  95. if (_dressUpObjUI == null)
  96. {
  97. _dressUpObjUI = new DressUpObjUI();
  98. }
  99. _speedAutoPlay = FightDataManager.Instance.dialogSpeed;
  100. lastTextFieldType = "";
  101. UpdateSpeedUpBtn();
  102. _dialogListLookBack = new List<string>();
  103. object[] datas = viewData as object[];
  104. _storyStartID = (string)datas[0];
  105. bool skipable = (bool)datas[1];
  106. _onCompleteStoryDialogCall = (OnCompleteStoryDialogCall)datas[2];
  107. if (datas.Length > 3)
  108. {
  109. _onCompleteStoryDialogCallParam = datas[3];
  110. }
  111. IsTeaParty = (bool)datas[4];
  112. _autoPlay = IsTeaParty;
  113. if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP && !InstanceZonesDataManager.CheckLevelPass(MainStoryDataManager.currentLevelCfgId))
  114. {
  115. // 临时设置都可以跳过对话
  116. skipable = false;
  117. }
  118. else
  119. {
  120. skipable = true;
  121. }
  122. _ui.m_btnSkip.visible = skipable;
  123. ShowNextStep(_storyStartID);
  124. _ui.m_c1.selectedIndex = 0;
  125. _ui.m_btnAutoPlay.selected = false;
  126. if (_storyStartID == MainStoryDataManager.priorId)
  127. {
  128. _ui.m_c1.selectedIndex = 1;
  129. OnClickBtnAutoPlay();
  130. _speedAutoPlay = 1;
  131. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  132. }
  133. if (IsTeaParty)
  134. {
  135. _ui.m_c1.selectedIndex = 2;
  136. }
  137. _ui.m_btnBack.visible = InstanceZonesDataManager.CheckLevelPass(100001001);
  138. StoryDialogDataManager.Instance.Clear();
  139. }
  140. protected override void OnHide()
  141. {
  142. base.OnHide();
  143. Timers.inst.Remove(UpdateShake);
  144. Timers.inst.Remove(OnScreenEffectComplete);
  145. Timers.inst.Remove(ShowNextWords);
  146. ScreenBlackController.Instance.HideBlack();
  147. StopAutoPlay();
  148. if (_sceneObject != null)
  149. {
  150. PrefabManager.Instance.Restore(_sceneObject);
  151. _sceneObject = null;
  152. }
  153. _dressUpObjUI.dressUpObj.TakeOffAll();
  154. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  155. _onCompleteStoryDialogCall = null;
  156. _onCompleteStoryDialogCallParam = null;
  157. StoryDialogDataManager.Instance.Clear();
  158. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 3);
  159. }
  160. protected override void TryCompleteGuide()
  161. {
  162. base.TryCompleteGuide();
  163. GuideController.TryCompleteGuide(ConstGuideId.ENTER_CHAPTER_5, 3);
  164. }
  165. private void OnClickBtnBack()
  166. {
  167. Over(false);
  168. }
  169. private void OnClickBtnNext()
  170. {
  171. if (!_canClickBtnNext || IsTeaParty)
  172. {
  173. return;
  174. }
  175. StopAutoPlay();
  176. if (_onScreenEffectComplete != null)
  177. {
  178. Timers.inst.Remove(OnScreenEffectComplete);
  179. _onScreenEffectComplete.Invoke(null);
  180. }
  181. else
  182. {
  183. ShowNextWords();
  184. }
  185. }
  186. private void OnClickBtnLookBack()
  187. {
  188. StopAutoPlay();
  189. if (_ui.m_btnSkip.visible)
  190. {
  191. ViewManager.Show<StoryLookBackView>(_storyStartID);
  192. }
  193. else
  194. {
  195. ViewManager.Show<StoryLookBackView>(_dialogListLookBack);
  196. }
  197. }
  198. private void OnBtnSkip()
  199. {
  200. Over(true);
  201. }
  202. private void OnClickListItem(EventContext context)
  203. {
  204. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(context.data as GObject);
  205. _dialogListLookBack.Add(dialogItem.m_txtContent.text);
  206. string stepID = (string)dialogItem.target.data;
  207. if (stepID == null)
  208. {
  209. stepID = "0";
  210. }
  211. UI_ListDialogItem.ProxyEnd();
  212. OnStepComplete(stepID);
  213. }
  214. private void OnClickBtnSpeedUp()
  215. {
  216. //如果没有自动播放先开始自动播放
  217. if (!_autoPlay)
  218. {
  219. _ui.m_btnAutoPlay.selected = true;
  220. OnClickBtnAutoPlay();
  221. }
  222. _speedAutoPlay = _speedAutoPlay * 2;
  223. if (_speedAutoPlay > GameConst.MAX_SPEED_AUTO_PLAY)
  224. {
  225. _speedAutoPlay = 1;
  226. }
  227. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  228. UpdateSpeedUpBtn();
  229. }
  230. private void OnClickBtnAutoPlay()
  231. {
  232. _autoPlay = _ui.m_btnAutoPlay.selected;
  233. if (_autoPlay)
  234. {
  235. ShowNextWords();
  236. }
  237. }
  238. private void InitStepListById(string dialogID)
  239. {
  240. var temp = StoryDialogCfgArray.Instance.GetCfgsByid(dialogID);
  241. _stepListToRead = new List<StoryDialogCfg>(temp);
  242. }
  243. private void ShowNextStep(string nextStepId)
  244. {
  245. if (nextStepId != null)
  246. {
  247. InitStepListById(nextStepId);
  248. }
  249. if (_stepListToRead != null && _stepListToRead.Count > 0)
  250. {
  251. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  252. _stepListToRead.RemoveAt(0);
  253. Timers.inst.StartCoroutine(InitStepContent(storyDialogCfg));
  254. }
  255. else
  256. {
  257. Over();
  258. }
  259. }
  260. private void OnStepComplete(string nextStepId = null)
  261. {
  262. _nextStepId = nextStepId;
  263. _ui.m_dialogText.target.visible = false;
  264. _ui.m_dialogName.target.visible = false;
  265. _ui.m_dialogHead.target.visible = false;
  266. float delay = 0;
  267. //屏幕效果
  268. if (_currentStepCfg != null)
  269. {
  270. if (_currentStepCfg.blackScreenDur > 0)
  271. {
  272. delay = _currentStepCfg.blackScreenDur;
  273. ScreenBlackController.Instance.ShowBlack(delay, this.viewCom, 0);
  274. }
  275. else if (_currentStepCfg.blankScreenDur > 0)
  276. {
  277. delay = _currentStepCfg.blankScreenDur;
  278. UpdatePic("0");
  279. }
  280. }
  281. if (delay > 0)
  282. {
  283. //转换成秒
  284. delay = delay / 1000f;
  285. _onScreenEffectComplete = OnScreenEffectComplete;
  286. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  287. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  288. }
  289. else
  290. {
  291. OnScreenEffectComplete();
  292. }
  293. }
  294. private void OnScreenEffectComplete(object param = null)
  295. {
  296. _onScreenEffectComplete = null;
  297. if (_nextStepId == "0")
  298. {
  299. Over();
  300. }
  301. else
  302. {
  303. ShowNextStep(_nextStepId);
  304. }
  305. }
  306. private IEnumerator InitStepContent(StoryDialogCfg storyDialogCfg)
  307. {
  308. _canClickBtnNext = false;
  309. StoryDialogDataManager.Instance.waitPicFade = false;
  310. HideAllDialogUI();
  311. // Init resource
  312. _currentStepCfg = storyDialogCfg;
  313. UpdateMusic(storyDialogCfg.musicRes);
  314. UpdateBg(storyDialogCfg.bgRes);
  315. UpdatePic(storyDialogCfg.picRes);
  316. UpdateRoleObj(storyDialogCfg.name);
  317. PlayEffect(storyDialogCfg.effectInfoArr);
  318. PlayShake(storyDialogCfg.shakeInfoArr);
  319. string content = storyDialogCfg.content;
  320. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  321. while (StoryDialogDataManager.Instance.waitBgChange)
  322. {
  323. //Debug.Log("等待背景转换");
  324. yield return new WaitForEndOfFrame();
  325. }
  326. if(StoryDialogDataManager.Instance.dialogShowDelay > 0)
  327. {
  328. yield return new WaitForSeconds(StoryDialogDataManager.Instance.dialogShowDelay);
  329. StoryDialogDataManager.Instance.dialogShowDelay = 0f;
  330. }
  331. _canClickBtnNext = true;
  332. if (content.IndexOf("//") >= 0)
  333. {
  334. showList(content);
  335. }
  336. else
  337. {
  338. Timers.inst.StartCoroutine(ShowDialog(storyDialogCfg));
  339. }
  340. }
  341. private void showList(string content)
  342. {
  343. StopAutoPlay();
  344. _ui.m_btnAutoPlay.enabled = false;
  345. _wordTextField = null;
  346. _ui.m_list.visible = true;
  347. _ui.m_list.RemoveChildrenToPool();
  348. string[] list = Regex.Split(content, "//");
  349. _ui.m_list.itemRenderer = (int index, GObject item) =>
  350. {
  351. string itemInfo = list[index];
  352. string[] itemInfoList = Regex.Split(itemInfo, "=");
  353. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  354. dialogItem.m_txtContent.text = itemInfoList[0];
  355. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  356. UI_ListDialogItem.ProxyEnd();
  357. };
  358. _ui.m_list.numItems = list.Length;
  359. }
  360. private void HideAllDialogUI()
  361. {
  362. _ui.m_dialogText.target.visible = false;
  363. _ui.m_dialogName.target.visible = false;
  364. _ui.m_dialogHead.target.visible = false;
  365. _ui.m_list.visible = false;
  366. }
  367. //private int num = 0;
  368. /// <summary>
  369. /// 初始化对话框/语音/CG等
  370. /// </summary>
  371. /// <param name="storyDialogCfg"></param>
  372. /// <returns></returns>
  373. private IEnumerator ShowDialog(StoryDialogCfg storyDialogCfg)
  374. {
  375. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  376. {
  377. GameController.ShowCreateRole();
  378. StoryDialogDataManager.Instance.waiting = true;
  379. while (StoryDialogDataManager.Instance.waiting)
  380. {
  381. yield return new WaitForEndOfFrame();
  382. }
  383. if (_autoPlay)
  384. {
  385. _ui.m_btnAutoPlay.selected = false;
  386. OnClickBtnAutoPlay();
  387. }
  388. }
  389. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  390. _ui.m_btnAutoPlay.enabled = true;
  391. _ui.m_list.visible = false;
  392. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  393. string words = content;
  394. string roleName = storyDialogCfg.name;
  395. string headRes = storyDialogCfg.head;
  396. string headAniRes = storyDialogCfg.headAni;
  397. string[] effectInfo = storyDialogCfg.effectInfoArr;
  398. VoiceManager.Instance.StopVoice();
  399. // 如果配置了语音,读取语音
  400. VoiceManager.Instance.LoadRes(ResPathUtil.GetCardSoundPath("test", "wav"));
  401. _wordList = Regex.Split(words, "&&");
  402. //++num;
  403. // 没有对话
  404. if (_wordList.Length == 0)
  405. //if (num == 1)
  406. {
  407. // 等待CG播放完毕直接进入下一段
  408. //Timers.inst.StartCoroutine(WaitCGAnimFinish());
  409. }
  410. // 有对话
  411. else
  412. {
  413. if (roleName == "self")
  414. {
  415. roleName = RoleDataManager.roleName;
  416. }
  417. //回顾
  418. if (roleName != null)
  419. {
  420. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  421. }
  422. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  423. {
  424. //显示对话框半身像
  425. _ui.m_dialogHead.target.visible = true;
  426. _ui.m_dialogHead.m_txtName.text = roleName;
  427. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  428. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  429. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  430. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  431. {
  432. //独立动画
  433. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  434. _ui.m_dialogHead.m_comphead.target.visible = true;
  435. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  436. }
  437. else
  438. {
  439. //换装
  440. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  441. _ui.m_dialogHead.m_comphead.target.visible = false;
  442. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  443. if (storyDialogCfg.suitId > 0)
  444. {
  445. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  446. }
  447. else
  448. {
  449. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  450. if (_dressUpObjUI.dressUpObj.actionId > 0)
  451. {
  452. _dressUpObjUI.dressUpObj.CancelAction(true, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  453. }
  454. }
  455. if (headAniCfg != null && headAniCfg.faceId > 0)
  456. {
  457. //表情
  458. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, true);
  459. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  460. }
  461. }
  462. _wordTextField = _ui.m_dialogHead.m_txtContent;
  463. _arrow = _ui.m_dialogHead.m_iconNext;
  464. lastTextFieldType = "head";
  465. }
  466. else if (!string.IsNullOrEmpty(headRes))
  467. {
  468. _ui.m_dialogHead.target.visible = true;
  469. _ui.m_dialogHead.m_txtName.text = roleName;
  470. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  471. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  472. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  473. _wordTextField = _ui.m_dialogHead.m_txtContent;
  474. _arrow = _ui.m_dialogHead.m_iconNext;
  475. lastTextFieldType = "head";
  476. }
  477. else if (!string.IsNullOrEmpty(roleName))
  478. {
  479. _ui.m_dialogName.target.visible = true;
  480. if (IsTeaParty)
  481. {
  482. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  483. var teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId);
  484. int roleIndex = Convert.ToInt32(roleName);
  485. _ui.m_dialogName.m_txtName.text = teapartyRoleCfg[roleIndex - 1].name;
  486. _ui.m_dialogName.m_bgType.selectedIndex = 1;
  487. _ui.m_dialogName.m_showArrow.selectedIndex = 1;
  488. if (roleIndex <= roleContainerList.Count && roleContainerList[roleIndex - 1].MaxScoreRoleName != null && roleContainerList[roleIndex - 1].MaxScoreRoleName != "" && _ui.m_dialogName.m_txtName.text != "")
  489. {
  490. _ui.m_comPlayName.visible = true;
  491. _ui.m_txtPlayName.text = roleContainerList[roleIndex - 1].MaxScoreRoleName;
  492. if (_ui.m_txtPlayName.text == RoleDataManager.roleName)
  493. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  494. }
  495. else
  496. _ui.m_comPlayName.visible = false;
  497. }
  498. else
  499. {
  500. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  501. _ui.m_dialogName.m_showArrow.selectedIndex = 0;
  502. _ui.m_dialogName.m_txtName.text = roleName;
  503. }
  504. _wordTextField = _ui.m_dialogName.m_txtContent;
  505. _arrow = _ui.m_dialogName.m_iconNext;
  506. if (!lastTextFieldType.Equals("name"))
  507. {
  508. lastTextFieldType = "name";
  509. StoryDialogDataManager.Instance.waiting = true;
  510. _ui.m_t0.Play(() =>
  511. {
  512. StoryDialogDataManager.Instance.waiting = false;
  513. });
  514. }
  515. }
  516. else
  517. {
  518. if (IsTeaParty)
  519. _ui.m_dialogText.m_showArrow.selectedIndex = 1;
  520. else
  521. _ui.m_dialogText.m_showArrow.selectedIndex = 0;
  522. _ui.m_dialogText.target.visible = true;
  523. _wordTextField = _ui.m_dialogText.m_txtContent;
  524. _arrow = _ui.m_dialogText.m_iconNext;
  525. lastTextFieldType = "text";
  526. _ui.m_comPlayName.visible = false;
  527. }
  528. _wordIndex = 0;
  529. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  530. _typingEffect.typeFinishedAction = ShowCurrentWords;
  531. ShowNextDialog();
  532. }
  533. }
  534. private void ShowNextDialog()
  535. {
  536. if (_wordList != null && _wordList.Length > _wordIndex)
  537. {
  538. string itemInfo = _wordList[_wordIndex];
  539. string[] itemInfoList = Regex.Split(itemInfo, "=");
  540. _currentWords = itemInfoList[0];
  541. if (itemInfoList.Length > 1)
  542. {
  543. _wordTextField.data = itemInfoList[1];
  544. }
  545. else
  546. {
  547. _wordTextField.data = null;
  548. }
  549. Timers.inst.StartCoroutine(StartShowLetters());
  550. }
  551. else
  552. {
  553. OnStepComplete();
  554. }
  555. }
  556. private void ShowCurrentWords()
  557. {
  558. //_arrow.target.visible = true;
  559. //Timers.inst.Remove(UpdateLetters);
  560. StopTyping();
  561. _typingEffect?.Cancel();
  562. _wordTextField.text = _currentWords;
  563. _dialogListLookBack.Add(_currentWords);
  564. _isShowLetters = false;
  565. _wordIndex++;
  566. if (_autoPlay)
  567. {
  568. int interval = (int)Mathf.Max(VoiceManager.Instance.GetClipLength(), GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay);
  569. Timers.inst.Add(interval, 1, ShowNextWords);
  570. }
  571. }
  572. private void ShowNextWords(object param = null)
  573. {
  574. if (_wordTextField != null)
  575. {
  576. if (_isShowLetters)
  577. {
  578. ShowCurrentWords();
  579. }
  580. else
  581. {
  582. string stepID = (string)_wordTextField.data;
  583. if (stepID != null)
  584. {
  585. OnStepComplete(stepID);
  586. }
  587. else
  588. {
  589. ShowNextDialog();
  590. }
  591. }
  592. }
  593. }
  594. private IEnumerator StartShowLetters()
  595. {
  596. _isShowLetters = true;
  597. _arrow.target.visible = false;
  598. _wordTextField.verticalAlign = VertAlignType.Top;
  599. _wordTextField.text = "";
  600. _canClickBtnNext = false;
  601. while (StoryDialogDataManager.Instance.waitPicFade || StoryDialogDataManager.Instance.waiting)
  602. {
  603. //Debug.Log("等待立绘/动画结束");
  604. yield return new WaitForEndOfFrame();
  605. }
  606. _canClickBtnNext = true;
  607. _wordTextField.text = _currentWords;
  608. StartTyping();
  609. }
  610. /// <summary>
  611. /// 开启打字机显示
  612. /// </summary>
  613. private void StartTyping()
  614. {
  615. _typingEffect.SetSpeed(_speedAutoPlay);
  616. _typingEffect.Start();
  617. // 如果配置了语音,则播放语音
  618. VoiceManager.Instance.PlayVoice();
  619. }
  620. private void StopTyping()
  621. {
  622. _typingEffect.Cancel();
  623. }
  624. private void UpdateBg(string value)
  625. {
  626. if (value.Length > 0)
  627. {
  628. SceneController.UpdateDialogBg(value, _sceneObject);
  629. }
  630. }
  631. private void UpdatePic(string value)
  632. {
  633. if(value.Length > 0 && !IsTeaParty)
  634. {
  635. SceneController.UpdateDialogPic(value, _sceneObject);
  636. }
  637. }
  638. private void UpdateRoleObj(string value)
  639. {
  640. if (IsTeaParty)
  641. {
  642. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  643. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  644. for (int i = 0; i < roleContainerList.Count; i++)
  645. {
  646. if (value == (i + 1).ToString() && roleContainerList[i].EquipIds.Count > 0)
  647. {
  648. MyDressUpHelper.dressUpObj.PutOnItemList(roleContainerList[i].EquipIds);
  649. return;
  650. }
  651. }
  652. MyDressUpHelper.dressUpObj.PutOnDefaultDressUpData(IsTeaParty);
  653. }
  654. }
  655. private void UpdateMusic(string value)
  656. {
  657. if (value.Length > 0)
  658. {
  659. if (value == "0")
  660. {
  661. MusicManager.Instance.Stop();
  662. }
  663. else
  664. {
  665. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"));
  666. }
  667. }
  668. }
  669. private void PlayEffect(string[] infos)
  670. {
  671. }
  672. private void PlayShake(int[] shakeInfoArr)
  673. {
  674. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  675. {
  676. Vector3 position = _sceneObject.transform.position;
  677. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  678. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  679. _sceneObject.transform.position = position;
  680. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  681. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  682. float interval = (float)shakeInfoArr[4] / 1000;
  683. float duration = (float)shakeInfoArr[5] / 1000;
  684. int repeat = Mathf.RoundToInt(duration / interval);
  685. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  686. }
  687. }
  688. private void UpdateShake(object param)
  689. {
  690. float[] attenuations = param as float[];
  691. float attenuationX = attenuations[0];
  692. float attenuationY = attenuations[1];
  693. Vector3 position = _sceneObject.transform.position;
  694. bool done = false;
  695. bool doneX = false;
  696. float absX = Mathf.Abs(position.x);
  697. if (absX > attenuationX)
  698. {
  699. int dir = (int)(position.x / absX);
  700. position.x = Mathf.Abs(position.x) - attenuationX;
  701. position.x *= -1 * dir;
  702. }
  703. else
  704. {
  705. doneX = true;
  706. position.x = 0;
  707. }
  708. bool doneY = false;
  709. float absY = Mathf.Abs(position.y);
  710. if (absY > attenuationY)
  711. {
  712. int dir = (int)(position.y / absY);
  713. position.y = Mathf.Abs(position.y) - attenuationY;
  714. position.y *= -1 * dir;
  715. }
  716. else
  717. {
  718. doneY = true;
  719. position.y = 0;
  720. }
  721. done = doneX && doneY;
  722. _sceneObject.transform.position = position;
  723. if (done)
  724. {
  725. Timers.inst.Remove(UpdateShake);
  726. }
  727. }
  728. private void Over(bool isSkip = true)
  729. {
  730. if (_onCompleteStoryDialogCall != null)
  731. {
  732. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  733. }
  734. }
  735. private void UpdateSpeedUpBtn()
  736. {
  737. if (_speedAutoPlay > 1)
  738. {
  739. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  740. }
  741. else
  742. {
  743. _ui.m_btnSpeedUp.text = "";
  744. }
  745. _typingEffect?.SetSpeed(_speedAutoPlay);
  746. }
  747. private void StopAutoPlay()
  748. {
  749. _autoPlay = false;
  750. _ui.m_btnAutoPlay.selected = false;
  751. Timers.inst.Remove(ShowNextWords);
  752. }
  753. private IEnumerator WaitCGAnimFinish()
  754. {
  755. GameObject cg = PrefabManager.Instance.InstantiateSync(ResPathUtil.GetStoryDialogCGPath("cg_shenjiao"));
  756. Animator animator = cg.GetComponentInChildren<Animator>();
  757. AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
  758. yield return new WaitForSeconds(info.length);
  759. //while (info.normalizedTime < 0.95)
  760. //{
  761. // info = animator.GetCurrentAnimatorStateInfo(0);
  762. // yield return new WaitForSeconds(0.1f);
  763. //}
  764. PrefabManager.Instance.Restore(cg);
  765. OnStepComplete();
  766. }
  767. }
  768. }