StoryDialogView.cs 32 KB

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