StoryDialogView.cs 32 KB

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