StoryDialogView.cs 27 KB

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