StoryDialogView.cs 31 KB

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