StoryDialogView.cs 27 KB

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