StoryDialogView.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733
  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. 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. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneStoryDialog"));
  73. }
  74. protected override void OnInit()
  75. {
  76. base.OnInit();
  77. _ui.m_dialogText.target.visible = false;
  78. _ui.m_dialogName.target.visible = false;
  79. _ui.m_dialogHead.target.visible = false;
  80. _ui.m_list.visible = false;
  81. _ui.m_btnNext.width = GRoot.inst.width;
  82. _ui.m_btnNext.height = GRoot.inst.height;
  83. _ui.m_btnNext.AddRelation(GRoot.inst, RelationType.Size);
  84. _ui.m_btnBack.onClick.Add(OnClickBtnBack);
  85. _ui.m_btnNext.onClick.Add(OnClickBtnNext);
  86. _ui.m_btnLookBack.onClick.Add(OnClickBtnLookBack);
  87. _ui.m_btnSkip.onClick.Add(OnBtnSkip);
  88. _ui.m_list.onClickItem.Add(OnClickListItem);
  89. _ui.m_btnSpeedUp.onClick.Add(OnClickBtnSpeedUp);
  90. _ui.m_btnAutoPlay.onClick.Add(OnClickBtnAutoPlay);
  91. }
  92. protected override void OnShown()
  93. {
  94. base.OnShown();
  95. if (_sceneObject == null)
  96. {
  97. _sceneObject = GameObject.Instantiate(_scenePrefab);
  98. }
  99. if (_dressUpObjUI == null)
  100. {
  101. _dressUpObjUI = new DressUpObjUI();
  102. }
  103. _speedAutoPlay = FightDataManager.Instance.dialogSpeed;
  104. _autoPlay = false;
  105. lastTextFieldType = "";
  106. UpdateSpeedUpBtn();
  107. _dialogListLookBack = new List<string>();
  108. object[] datas = viewData as object[];
  109. _storyStartID = (string)datas[0];
  110. bool skipable = (bool)datas[1];
  111. _onCompleteStoryDialogCall = (OnCompleteStoryDialogCall)datas[2];
  112. if (datas.Length > 3)
  113. {
  114. _onCompleteStoryDialogCallParam = datas[3];
  115. }
  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. _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. GameObject.Destroy(_sceneObject);
  150. _sceneObject = null;
  151. }
  152. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  153. _onCompleteStoryDialogCall = null;
  154. _onCompleteStoryDialogCallParam = null;
  155. StoryDialogDataManager.Instance.Clear();
  156. }
  157. private void OnClickBtnBack()
  158. {
  159. // this.Hide();
  160. ViewManager.GoBackFrom(typeof(StoryDialogView).FullName);
  161. // Over(false);
  162. }
  163. private void OnClickBtnNext()
  164. {
  165. if (!_canClickBtnNext)
  166. {
  167. return;
  168. }
  169. StopAutoPlay();
  170. if (_onScreenEffectComplete != null)
  171. {
  172. Timers.inst.Remove(OnScreenEffectComplete);
  173. _onScreenEffectComplete.Invoke(null);
  174. }
  175. else
  176. {
  177. ShowNextWords();
  178. }
  179. }
  180. private void OnClickBtnLookBack()
  181. {
  182. StopAutoPlay();
  183. if (_ui.m_btnSkip.enabled)
  184. {
  185. ViewManager.Show<StoryLookBackView>(_storyStartID);
  186. }
  187. else
  188. {
  189. ViewManager.Show<StoryLookBackView>(_dialogListLookBack);
  190. }
  191. }
  192. private void OnBtnSkip()
  193. {
  194. Over(true);
  195. }
  196. private void OnClickListItem(EventContext context)
  197. {
  198. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(context.data as GObject);
  199. _dialogListLookBack.Add(dialogItem.m_txtContent.text);
  200. string stepID = (string)dialogItem.target.data;
  201. if (stepID == null)
  202. {
  203. stepID = "0";
  204. }
  205. UI_ListDialogItem.ProxyEnd();
  206. OnStepComplete(stepID);
  207. }
  208. private void OnClickBtnSpeedUp()
  209. {
  210. //如果没有自动播放先开始自动播放
  211. if (!_autoPlay)
  212. {
  213. _ui.m_btnAutoPlay.selected = true;
  214. OnClickBtnAutoPlay();
  215. }
  216. _speedAutoPlay = _speedAutoPlay * 2;
  217. if (_speedAutoPlay > GameConst.MAX_SPEED_AUTO_PLAY)
  218. {
  219. _speedAutoPlay = 1;
  220. }
  221. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  222. UpdateSpeedUpBtn();
  223. }
  224. private void OnClickBtnAutoPlay()
  225. {
  226. _autoPlay = _ui.m_btnAutoPlay.selected;
  227. if (_autoPlay)
  228. {
  229. ShowNextWords();
  230. }
  231. }
  232. private void InitStepListById(string dialogID)
  233. {
  234. var temp = StoryDialogCfgArray.Instance.GetCfgsByid(dialogID);
  235. _stepListToRead = new List<StoryDialogCfg>(temp);
  236. }
  237. private void ShowNextStep(string nextStepId)
  238. {
  239. if (nextStepId != null)
  240. {
  241. InitStepListById(nextStepId);
  242. }
  243. if (_stepListToRead != null && _stepListToRead.Count > 0)
  244. {
  245. StoryDialogCfg storyDialogCfg = (StoryDialogCfg)_stepListToRead[0];
  246. _stepListToRead.RemoveAt(0);
  247. Timers.inst.StartCoroutine(InitStepContent(storyDialogCfg));
  248. }
  249. else
  250. {
  251. Over();
  252. }
  253. }
  254. private void OnStepComplete(string nextStepId = null)
  255. {
  256. _nextStepId = nextStepId;
  257. _ui.m_dialogText.target.visible = false;
  258. _ui.m_dialogName.target.visible = false;
  259. _ui.m_dialogHead.target.visible = false;
  260. float delay = 0;
  261. //屏幕效果
  262. if (_currentStepCfg != null)
  263. {
  264. if (_currentStepCfg.blackScreenDur > 0)
  265. {
  266. delay = _currentStepCfg.blackScreenDur;
  267. ScreenBlackController.Instance.ShowBlack(delay, this.viewCom, 0);
  268. }
  269. else if (_currentStepCfg.blankScreenDur > 0)
  270. {
  271. delay = _currentStepCfg.blankScreenDur;
  272. UpdatePic("0");
  273. }
  274. }
  275. if (delay > 0)
  276. {
  277. //转换成秒
  278. delay = delay / 1000f;
  279. _onScreenEffectComplete = OnScreenEffectComplete;
  280. Timers.inst.Add(delay, 1, OnScreenEffectComplete);
  281. StoryDialogDataManager.Instance.dialogShowDelay = 0.6f;
  282. }
  283. else
  284. {
  285. OnScreenEffectComplete();
  286. }
  287. }
  288. private void OnScreenEffectComplete(object param = null)
  289. {
  290. _onScreenEffectComplete = null;
  291. if (_nextStepId == "0")
  292. {
  293. Over();
  294. }
  295. else
  296. {
  297. ShowNextStep(_nextStepId);
  298. }
  299. }
  300. private IEnumerator InitStepContent(StoryDialogCfg storyDialogCfg)
  301. {
  302. _canClickBtnNext = false;
  303. StoryDialogDataManager.Instance.waitPicFade = false;
  304. HideAllDialogUI();
  305. // Init resource
  306. _currentStepCfg = storyDialogCfg;
  307. UpdateMusic(storyDialogCfg.musicRes);
  308. UpdateBg(storyDialogCfg.bgRes);
  309. UpdatePic(storyDialogCfg.picRes);
  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. 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 void ShowDialog(StoryDialogCfg storyDialogCfg)
  360. {
  361. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  362. {
  363. if (_autoPlay)
  364. {
  365. _ui.m_btnAutoPlay.selected = false;
  366. OnClickBtnAutoPlay();
  367. }
  368. GameController.ShowCreateRole();
  369. }
  370. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  371. _ui.m_btnAutoPlay.enabled = true;
  372. _ui.m_list.visible = false;
  373. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  374. string words = content;
  375. string roleName = storyDialogCfg.name;
  376. string headRes = storyDialogCfg.head;
  377. string headAniRes = storyDialogCfg.headAni;
  378. if (roleName == "self")
  379. {
  380. roleName = RoleDataManager.roleName;
  381. }
  382. //回顾
  383. if (roleName != null)
  384. {
  385. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  386. }
  387. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  388. {
  389. //显示对话框半身像
  390. _ui.m_dialogHead.target.visible = true;
  391. _ui.m_dialogHead.m_txtName.text = roleName;
  392. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  393. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  394. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  395. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  396. {
  397. //独立动画
  398. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  399. _ui.m_dialogHead.m_comphead.target.visible = true;
  400. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  401. }
  402. else
  403. {
  404. //换装
  405. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  406. _ui.m_dialogHead.m_comphead.target.visible = false;
  407. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  408. if (storyDialogCfg.suitId > 0)
  409. {
  410. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  411. }
  412. else
  413. {
  414. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData);
  415. if (_dressUpObjUI.dressUpObj.actionId > 0)
  416. {
  417. _dressUpObjUI.dressUpObj.CancelAction(true);
  418. }
  419. _dressUpObjUI.dressUpObj.PutOnDressUpData(_dressUpObjUI.dressUpObj.DressUpDataClone(), new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  420. }
  421. if (headAniCfg != null && headAniCfg.faceId > 0)
  422. {
  423. //表情
  424. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, false);
  425. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  426. }
  427. }
  428. _wordTextField = _ui.m_dialogHead.m_txtContent;
  429. _arrow = _ui.m_dialogHead.m_iconNext;
  430. lastTextFieldType = "head";
  431. }
  432. else if (!string.IsNullOrEmpty(headRes))
  433. {
  434. _ui.m_dialogHead.target.visible = true;
  435. _ui.m_dialogHead.m_txtName.text = roleName;
  436. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  437. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  438. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  439. _wordTextField = _ui.m_dialogHead.m_txtContent;
  440. _arrow = _ui.m_dialogHead.m_iconNext;
  441. lastTextFieldType = "head";
  442. }
  443. else if (!string.IsNullOrEmpty(roleName))
  444. {
  445. _ui.m_dialogName.target.visible = true;
  446. _ui.m_dialogName.m_txtName.text = roleName;
  447. _wordTextField = _ui.m_dialogName.m_txtContent;
  448. _arrow = _ui.m_dialogName.m_iconNext;
  449. if (!lastTextFieldType.Equals("name"))
  450. {
  451. lastTextFieldType = "name";
  452. _ui.m_t0.Play();
  453. }
  454. }
  455. else
  456. {
  457. _ui.m_dialogText.target.visible = true;
  458. _wordTextField = _ui.m_dialogText.m_txtContent;
  459. _arrow = _ui.m_dialogText.m_iconNext;
  460. lastTextFieldType = "text";
  461. }
  462. _wordList = Regex.Split(words, "&&");
  463. _wordIndex = 0;
  464. _typingEffect = new TypingFadeEffect(_wordTextField);
  465. _typingEffect.typeFinishedAction = ShowCurrentWords;
  466. ShowNextDialog();
  467. }
  468. private void ShowNextDialog()
  469. {
  470. if (_wordList != null && _wordList.Length > _wordIndex)
  471. {
  472. string itemInfo = _wordList[_wordIndex];
  473. string[] itemInfoList = Regex.Split(itemInfo, "=");
  474. _currentWords = itemInfoList[0];
  475. if (itemInfoList.Length > 1)
  476. {
  477. _wordTextField.data = itemInfoList[1];
  478. }
  479. else
  480. {
  481. _wordTextField.data = null;
  482. }
  483. Timers.inst.StartCoroutine(StartShowLetters());
  484. }
  485. else
  486. {
  487. OnStepComplete();
  488. }
  489. }
  490. private void ShowCurrentWords()
  491. {
  492. _arrow.target.visible = true;
  493. //Timers.inst.Remove(UpdateLetters);
  494. StopTyping();
  495. _typingEffect?.Cancel();
  496. _wordTextField.text = _currentWords;
  497. _dialogListLookBack.Add(_currentWords);
  498. _isShowLetters = false;
  499. _wordIndex++;
  500. if (_autoPlay)
  501. {
  502. Timers.inst.Add(GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay, 1, ShowNextWords);
  503. }
  504. }
  505. private void ShowNextWords(object param = null)
  506. {
  507. if (_wordTextField != null)
  508. {
  509. if (_isShowLetters)
  510. {
  511. ShowCurrentWords();
  512. }
  513. else
  514. {
  515. string stepID = (string)_wordTextField.data;
  516. if (stepID != null)
  517. {
  518. OnStepComplete(stepID);
  519. }
  520. else
  521. {
  522. ShowNextDialog();
  523. }
  524. }
  525. }
  526. }
  527. private IEnumerator StartShowLetters()
  528. {
  529. _isShowLetters = true;
  530. _arrow.target.visible = false;
  531. _wordTextField.verticalAlign = VertAlignType.Top;
  532. _wordTextField.text = "";
  533. ArrayList letters = StoryUtil.GetLettersList(_currentWords);
  534. _canClickBtnNext = false;
  535. while (StoryDialogDataManager.Instance.waitPicFade)
  536. {
  537. yield return new WaitForEndOfFrame();
  538. }
  539. _canClickBtnNext = true;
  540. _wordTextField.text = _currentWords;
  541. StartTyping();
  542. }
  543. private void StartTyping()
  544. {
  545. _typingEffect.SetSpeed(GameConst.LETTERS_INTERVAL_MAX / _speedAutoPlay);
  546. _typingEffect.Start();
  547. }
  548. private void StopTyping()
  549. {
  550. _typingEffect.Cancel();
  551. }
  552. private void UpdateBg(string value)
  553. {
  554. if (value.Length > 0)
  555. {
  556. SceneController.UpdateDialogBg(value, _sceneObject);
  557. }
  558. }
  559. private void UpdatePic(string value)
  560. {
  561. if (value.Length > 0)
  562. {
  563. SceneController.UpdateDialogPic(value, _sceneObject);
  564. }
  565. }
  566. private void UpdateMusic(string value)
  567. {
  568. if (value.Length > 0)
  569. {
  570. if (value == "0")
  571. {
  572. MusicManager.Instance.Stop();
  573. }
  574. else
  575. {
  576. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(value, "mp3"));
  577. }
  578. }
  579. }
  580. private void PlayEffect(string[] infos)
  581. {
  582. }
  583. private void PlayShake(int[] shakeInfoArr)
  584. {
  585. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  586. {
  587. Vector3 position = _sceneObject.transform.position;
  588. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  589. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  590. _sceneObject.transform.position = position;
  591. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  592. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  593. float interval = (float)shakeInfoArr[4] / 1000;
  594. float duration = (float)shakeInfoArr[5] / 1000;
  595. int repeat = Mathf.RoundToInt(duration / interval);
  596. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  597. }
  598. }
  599. private void UpdateShake(object param)
  600. {
  601. float[] attenuations = param as float[];
  602. float attenuationX = attenuations[0];
  603. float attenuationY = attenuations[1];
  604. Vector3 position = _sceneObject.transform.position;
  605. bool done = false;
  606. bool doneX = false;
  607. float absX = Mathf.Abs(position.x);
  608. if (absX > attenuationX)
  609. {
  610. int dir = (int)(position.x / absX);
  611. position.x = Mathf.Abs(position.x) - attenuationX;
  612. position.x *= -1 * dir;
  613. }
  614. else
  615. {
  616. doneX = true;
  617. position.x = 0;
  618. }
  619. bool doneY = false;
  620. float absY = Mathf.Abs(position.y);
  621. if (absY > attenuationY)
  622. {
  623. int dir = (int)(position.y / absY);
  624. position.y = Mathf.Abs(position.y) - attenuationY;
  625. position.y *= -1 * dir;
  626. }
  627. else
  628. {
  629. doneY = true;
  630. position.y = 0;
  631. }
  632. done = doneX && doneY;
  633. _sceneObject.transform.position = position;
  634. if (done)
  635. {
  636. Timers.inst.Remove(UpdateShake);
  637. }
  638. }
  639. private void Over(bool isSkip = false)
  640. {
  641. if (_onCompleteStoryDialogCall != null)
  642. {
  643. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  644. }
  645. }
  646. private void UpdateSpeedUpBtn()
  647. {
  648. if (_speedAutoPlay > 1)
  649. {
  650. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  651. }
  652. else
  653. {
  654. _ui.m_btnSpeedUp.text = "";
  655. }
  656. _typingEffect?.SetSpeed(GameConst.LETTERS_INTERVAL_MAX / _speedAutoPlay);
  657. }
  658. private void StopAutoPlay()
  659. {
  660. _autoPlay = false;
  661. _ui.m_btnAutoPlay.selected = false;
  662. Timers.inst.Remove(ShowNextWords);
  663. }
  664. }
  665. }