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