StoryDialogView.cs 28 KB

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