StoryDialogView.cs 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891
  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. HideAllDialogUI();
  324. // Init resource
  325. _currentStepCfg = storyDialogCfg;
  326. UpdateMusic(storyDialogCfg.musicRes);
  327. UpdateBg(storyDialogCfg.bgRes);
  328. UpdatePic(storyDialogCfg.picRes);
  329. UpdateAnim(storyDialogCfg.aniRes);
  330. UpdateRoleObj(storyDialogCfg.name);
  331. PlayEffect(storyDialogCfg.effectInfoArr);
  332. PlayShake(storyDialogCfg.shakeInfoArr);
  333. string content = storyDialogCfg.content;
  334. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  335. while (StoryDialogDataManager.Instance.waitBgChange)
  336. {
  337. //Debug.Log("等待背景转换");
  338. yield return new WaitForEndOfFrame();
  339. }
  340. if(StoryDialogDataManager.Instance.dialogShowDelay > 0)
  341. {
  342. yield return new WaitForSeconds(StoryDialogDataManager.Instance.dialogShowDelay);
  343. StoryDialogDataManager.Instance.dialogShowDelay = 0f;
  344. }
  345. _canClickBtnNext = true;
  346. if (content.IndexOf("//") >= 0)
  347. {
  348. showList(content);
  349. }
  350. else
  351. {
  352. Timers.inst.StartCoroutine(ShowDialog(storyDialogCfg));
  353. }
  354. }
  355. private void showList(string content)
  356. {
  357. StopAutoPlay();
  358. _ui.m_btnAutoPlay.enabled = false;
  359. _wordTextField = null;
  360. _ui.m_list.visible = true;
  361. _ui.m_list.RemoveChildrenToPool();
  362. string[] list = Regex.Split(content, "//");
  363. _ui.m_list.itemRenderer = (int index, GObject item) =>
  364. {
  365. string itemInfo = list[index];
  366. string[] itemInfoList = Regex.Split(itemInfo, "=");
  367. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  368. dialogItem.m_txtContent.text = itemInfoList[0];
  369. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  370. UI_ListDialogItem.ProxyEnd();
  371. };
  372. _ui.m_list.numItems = list.Length;
  373. }
  374. private void HideAllDialogUI()
  375. {
  376. _ui.m_dialogText.target.visible = false;
  377. _ui.m_dialogName.target.visible = false;
  378. _ui.m_dialogHead.target.visible = false;
  379. _ui.m_list.visible = false;
  380. }
  381. /// <summary>
  382. /// 初始化对话框/语音/CG等
  383. /// </summary>
  384. /// <param name="storyDialogCfg"></param>
  385. /// <returns></returns>
  386. private IEnumerator ShowDialog(StoryDialogCfg storyDialogCfg)
  387. {
  388. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  389. {
  390. GameController.ShowCreateRole();
  391. StoryDialogDataManager.Instance.waiting = true;
  392. while (StoryDialogDataManager.Instance.waiting)
  393. {
  394. yield return new WaitForEndOfFrame();
  395. }
  396. if (_autoPlay)
  397. {
  398. _ui.m_btnAutoPlay.selected = false;
  399. OnClickBtnAutoPlay();
  400. }
  401. }
  402. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  403. _ui.m_btnAutoPlay.enabled = true;
  404. _ui.m_list.visible = false;
  405. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  406. string words = content;
  407. string roleName = storyDialogCfg.name;
  408. string headRes = storyDialogCfg.head;
  409. string headAniRes = storyDialogCfg.headAni;
  410. string[] effectInfo = storyDialogCfg.effectInfoArr;
  411. VoiceManager.Instance.StopVoice();
  412. // 如果配置了语音,读取语音
  413. VoiceManager.Instance.LoadRes(ResPathUtil.GetVoicePath(storyDialogCfg.voiceRes));
  414. _wordList = Regex.Split(words, "&&");
  415. // 有对话
  416. if (_wordList.Length > 0 && !_wordList[0].Equals(""))
  417. {
  418. if (roleName == "self")
  419. {
  420. roleName = RoleDataManager.roleName;
  421. }
  422. //回顾
  423. if (roleName != null)
  424. {
  425. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  426. }
  427. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  428. {
  429. //显示对话框半身像
  430. _ui.m_dialogHead.target.visible = true;
  431. _ui.m_dialogHead.m_txtName.text = roleName;
  432. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  433. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  434. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  435. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  436. {
  437. //独立动画
  438. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  439. _ui.m_dialogHead.m_comphead.target.visible = true;
  440. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  441. }
  442. else
  443. {
  444. //换装
  445. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  446. _ui.m_dialogHead.m_comphead.target.visible = false;
  447. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  448. if (storyDialogCfg.suitId > 0)
  449. {
  450. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  451. }
  452. else
  453. {
  454. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  455. if (_dressUpObjUI.dressUpObj.actionId > 0)
  456. {
  457. _dressUpObjUI.dressUpObj.CancelAction(true, new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  458. }
  459. }
  460. if (headAniCfg != null && headAniCfg.faceId > 0)
  461. {
  462. //表情
  463. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, true);
  464. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  465. }
  466. }
  467. _wordTextField = _ui.m_dialogHead.m_txtContent;
  468. _arrow = _ui.m_dialogHead.m_iconNext;
  469. lastTextFieldType = "head";
  470. }
  471. else if (!string.IsNullOrEmpty(headRes))
  472. {
  473. _ui.m_dialogHead.target.visible = true;
  474. _ui.m_dialogHead.m_txtName.text = roleName;
  475. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  476. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  477. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  478. _wordTextField = _ui.m_dialogHead.m_txtContent;
  479. _arrow = _ui.m_dialogHead.m_iconNext;
  480. lastTextFieldType = "head";
  481. }
  482. else if (!string.IsNullOrEmpty(roleName))
  483. {
  484. _ui.m_dialogName.target.visible = true;
  485. if (IsTeaParty)
  486. {
  487. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  488. var teapartyRoleCfg = TeapartyRoleCfgArray.Instance.GetCfgsByid(LeagueDataManager.Instance.TeaPartyId);
  489. int roleIndex = Convert.ToInt32(roleName);
  490. _ui.m_dialogName.m_txtName.text = teapartyRoleCfg[roleIndex - 1].name;
  491. _ui.m_dialogName.m_bgType.selectedIndex = 1;
  492. _ui.m_dialogName.m_showArrow.selectedIndex = 1;
  493. if (roleIndex <= roleContainerList.Count && roleContainerList[roleIndex - 1].MaxScoreRoleName != null && roleContainerList[roleIndex - 1].MaxScoreRoleName != "" && _ui.m_dialogName.m_txtName.text != "")
  494. {
  495. _ui.m_comPlayName.visible = true;
  496. _ui.m_txtPlayName.text = roleContainerList[roleIndex - 1].MaxScoreRoleName;
  497. if (_ui.m_txtPlayName.text == RoleDataManager.roleName)
  498. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  499. }
  500. else
  501. _ui.m_comPlayName.visible = false;
  502. }
  503. else
  504. {
  505. _ui.m_dialogName.m_bgType.selectedIndex = 0;
  506. _ui.m_dialogName.m_showArrow.selectedIndex = 0;
  507. _ui.m_dialogName.m_txtName.text = roleName;
  508. }
  509. _wordTextField = _ui.m_dialogName.m_txtContent;
  510. _arrow = _ui.m_dialogName.m_iconNext;
  511. if (!lastTextFieldType.Equals("name"))
  512. {
  513. lastTextFieldType = "name";
  514. StoryDialogDataManager.Instance.waiting = true;
  515. _ui.m_t0.Play(() =>
  516. {
  517. StoryDialogDataManager.Instance.waiting = false;
  518. });
  519. }
  520. }
  521. else
  522. {
  523. if (IsTeaParty)
  524. _ui.m_dialogText.m_showArrow.selectedIndex = 1;
  525. else
  526. _ui.m_dialogText.m_showArrow.selectedIndex = 0;
  527. _ui.m_dialogText.target.visible = true;
  528. _wordTextField = _ui.m_dialogText.m_txtContent;
  529. _arrow = _ui.m_dialogText.m_iconNext;
  530. lastTextFieldType = "text";
  531. _ui.m_comPlayName.visible = false;
  532. }
  533. _wordIndex = 0;
  534. _typingEffect = new TypingFadeEffectPro(_wordTextField);
  535. _typingEffect.typeFinishedAction = ShowCurrentWords;
  536. ShowNextDialog();
  537. }
  538. else
  539. {
  540. OnStepComplete();
  541. //if (effectInfo.Length > 0)
  542. //{
  543. // // 等待CG播放完毕直接进入下一段
  544. // Timers.inst.StartCoroutine(WaitCGAnimFinish(effectInfo[0], int.Parse(effectInfo[1])));
  545. //}
  546. //// 播放效果等
  547. //else
  548. //{
  549. // OnStepComplete();
  550. //}
  551. }
  552. }
  553. private void ShowNextDialog()
  554. {
  555. if (_wordList != null && _wordList.Length > _wordIndex)
  556. {
  557. string itemInfo = _wordList[_wordIndex];
  558. string[] itemInfoList = Regex.Split(itemInfo, "=");
  559. _currentWords = itemInfoList[0];
  560. if (itemInfoList.Length > 1)
  561. {
  562. _wordTextField.data = itemInfoList[1];
  563. }
  564. else
  565. {
  566. _wordTextField.data = null;
  567. }
  568. Timers.inst.StartCoroutine(StartShowLetters());
  569. }
  570. else
  571. {
  572. OnStepComplete();
  573. }
  574. }
  575. private void ShowCurrentWords()
  576. {
  577. //_arrow.target.visible = true;
  578. //Timers.inst.Remove(UpdateLetters);
  579. StopTyping();
  580. _typingEffect?.Cancel();
  581. _wordTextField.text = _currentWords;
  582. _dialogListLookBack.Add(_currentWords);
  583. _isShowLetters = false;
  584. _wordIndex++;
  585. if (_autoPlay)
  586. {
  587. int interval = (int)Mathf.Max(VoiceManager.Instance.GetClipLength(), GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay);
  588. Timers.inst.Add(interval, 1, ShowNextWords);
  589. }
  590. }
  591. private void ShowNextWords(object param = null)
  592. {
  593. if (_wordTextField != null)
  594. {
  595. if (_isShowLetters)
  596. {
  597. ShowCurrentWords();
  598. }
  599. else
  600. {
  601. string stepID = (string)_wordTextField.data;
  602. if (stepID != null)
  603. {
  604. OnStepComplete(stepID);
  605. }
  606. else
  607. {
  608. ShowNextDialog();
  609. }
  610. }
  611. }
  612. }
  613. private IEnumerator StartShowLetters()
  614. {
  615. _isShowLetters = true;
  616. _arrow.target.visible = false;
  617. _wordTextField.verticalAlign = VertAlignType.Top;
  618. _wordTextField.text = "";
  619. _canClickBtnNext = false;
  620. while (StoryDialogDataManager.Instance.waitPicFade || StoryDialogDataManager.Instance.waiting)
  621. {
  622. //Debug.Log("等待立绘/动画结束");
  623. yield return new WaitForEndOfFrame();
  624. }
  625. _canClickBtnNext = true;
  626. _wordTextField.text = _currentWords;
  627. StartTyping();
  628. }
  629. /// <summary>
  630. /// 开启打字机显示
  631. /// </summary>
  632. private void StartTyping()
  633. {
  634. _typingEffect.SetSpeed(_speedAutoPlay);
  635. _typingEffect.Start();
  636. // 如果配置了语音,则播放语音
  637. VoiceManager.Instance.PlayVoice();
  638. }
  639. private void StopTyping()
  640. {
  641. _typingEffect.Cancel();
  642. }
  643. private void UpdateBg(string value)
  644. {
  645. if (value.Length > 0)
  646. {
  647. SceneController.UpdateDialogBg(value, _sceneObject);
  648. }
  649. }
  650. private void UpdatePic(string value)
  651. {
  652. if(value.Length > 0 && !IsTeaParty)
  653. {
  654. SceneController.UpdateDialogPic(value, _sceneObject);
  655. }
  656. }
  657. private void UpdateAnim(string value)
  658. {
  659. if (value.Length > 0 && !IsTeaParty)
  660. {
  661. if (value == "0")
  662. {
  663. SceneController.ControlBgVisible(_sceneObject, true);
  664. }
  665. else
  666. {
  667. SceneController.ControlBgVisible(_sceneObject, false);
  668. }
  669. SceneController.UpdateDialogAnim(value, ref _animObject);
  670. }
  671. }
  672. private void UpdateRoleObj(string value)
  673. {
  674. if (IsTeaParty)
  675. {
  676. var roleContainerList = LeagueDataManager.Instance.RoleContainerList;
  677. MyDressUpHelper.dressUpObj.setSceneObj(_sceneObject, false, false);
  678. for (int i = 0; i < roleContainerList.Count; i++)
  679. {
  680. if (value == (i + 1).ToString() && roleContainerList[i].EquipIds.Count > 0)
  681. {
  682. MyDressUpHelper.dressUpObj.PutOnItemList(roleContainerList[i].EquipIds);
  683. return;
  684. }
  685. }
  686. MyDressUpHelper.dressUpObj.PutOnDefaultDressUpData(IsTeaParty);
  687. }
  688. }
  689. private void UpdateMusic(string value)
  690. {
  691. if (value.Length > 0)
  692. {
  693. if (value == "0")
  694. {
  695. MusicManager.Instance.Stop();
  696. }
  697. else
  698. {
  699. MusicManager.Instance.PlayCroutine(ResPathUtil.GetMusicPath(value, "mp3"));
  700. }
  701. }
  702. }
  703. private void PlayEffect(string[] infos)
  704. {
  705. }
  706. private void PlayShake(int[] shakeInfoArr)
  707. {
  708. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  709. {
  710. Vector3 position = _sceneObject.transform.position;
  711. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  712. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  713. _sceneObject.transform.position = position;
  714. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  715. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  716. float interval = (float)shakeInfoArr[4] / 1000;
  717. float duration = (float)shakeInfoArr[5] / 1000;
  718. int repeat = Mathf.RoundToInt(duration / interval);
  719. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  720. }
  721. }
  722. private void UpdateShake(object param)
  723. {
  724. float[] attenuations = param as float[];
  725. float attenuationX = attenuations[0];
  726. float attenuationY = attenuations[1];
  727. Vector3 position = _sceneObject.transform.position;
  728. bool done = false;
  729. bool doneX = false;
  730. float absX = Mathf.Abs(position.x);
  731. if (absX > attenuationX)
  732. {
  733. int dir = (int)(position.x / absX);
  734. position.x = Mathf.Abs(position.x) - attenuationX;
  735. position.x *= -1 * dir;
  736. }
  737. else
  738. {
  739. doneX = true;
  740. position.x = 0;
  741. }
  742. bool doneY = false;
  743. float absY = Mathf.Abs(position.y);
  744. if (absY > attenuationY)
  745. {
  746. int dir = (int)(position.y / absY);
  747. position.y = Mathf.Abs(position.y) - attenuationY;
  748. position.y *= -1 * dir;
  749. }
  750. else
  751. {
  752. doneY = true;
  753. position.y = 0;
  754. }
  755. done = doneX && doneY;
  756. _sceneObject.transform.position = position;
  757. if (done)
  758. {
  759. Timers.inst.Remove(UpdateShake);
  760. }
  761. }
  762. private void Over(bool isSkip = true)
  763. {
  764. if (_onCompleteStoryDialogCall != null)
  765. {
  766. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  767. }
  768. }
  769. private void UpdateSpeedUpBtn()
  770. {
  771. if (_speedAutoPlay > 1)
  772. {
  773. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  774. }
  775. else
  776. {
  777. _ui.m_btnSpeedUp.text = "";
  778. }
  779. _typingEffect?.SetSpeed(_speedAutoPlay);
  780. }
  781. private void StopAutoPlay()
  782. {
  783. _autoPlay = false;
  784. _ui.m_btnAutoPlay.selected = false;
  785. Timers.inst.Remove(ShowNextWords);
  786. }
  787. private IEnumerator WaitCGAnimFinish(string resName, int times = 1)
  788. {
  789. GameObject cg = PrefabManager.Instance.InstantiateSync("test");
  790. Animator animator = cg.GetComponentInChildren<Animator>();
  791. AnimatorStateInfo info = animator.GetCurrentAnimatorStateInfo(0);
  792. yield return new WaitForSeconds(info.length * times);
  793. //while (info.normalizedTime < 0.95)
  794. //{
  795. // info = animator.GetCurrentAnimatorStateInfo(0);
  796. // yield return new WaitForSeconds(0.1f);
  797. //}
  798. PrefabManager.Instance.Restore(cg);
  799. OnStepComplete();
  800. }
  801. }
  802. }