StoryDialogView.cs 32 KB

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