StoryDialogView.cs 31 KB

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