StoryDialogView.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720
  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 bool _waitPic;
  37. private string _currentWords;
  38. private string _storyStartID;
  39. private string lastTextFieldType; // 上一段文本框的类型
  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. Timers.inst.Remove(UpdateLetters);
  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(UpdateLetters);
  143. Timers.inst.Remove(UpdateShake);
  144. Timers.inst.Remove(OnScreenEffectComplete);
  145. Timers.inst.Remove(ShowNextWords);
  146. ScreenBlackController.Instance.HideBlack();
  147. StopAutoPlay();
  148. if (_sceneObject != null)
  149. {
  150. GameObject.Destroy(_sceneObject);
  151. _sceneObject = null;
  152. }
  153. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(ConstMusicName.DEFAULT));
  154. _onCompleteStoryDialogCall = null;
  155. _onCompleteStoryDialogCallParam = null;
  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. 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. 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. }
  281. else
  282. {
  283. OnScreenEffectComplete();
  284. }
  285. }
  286. private void OnScreenEffectComplete(object param = null)
  287. {
  288. _onScreenEffectComplete = null;
  289. if (_nextStepId == "0")
  290. {
  291. Over();
  292. }
  293. else
  294. {
  295. ShowNextStep(_nextStepId);
  296. }
  297. }
  298. private void InitStepContent(StoryDialogCfg storyDialogCfg)
  299. {
  300. _canClickBtnNext = true;
  301. _waitPic = false;
  302. _currentStepCfg = storyDialogCfg;
  303. UpdateMusic(storyDialogCfg.musicRes);
  304. UpdateBg(storyDialogCfg.bgRes);
  305. UpdatePic(storyDialogCfg.picRes);
  306. PlayEffect(storyDialogCfg.effectInfoArr);
  307. PlayShake(storyDialogCfg.shakeInfoArr);
  308. string content = storyDialogCfg.content;
  309. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  310. if (content.IndexOf("//") >= 0)
  311. {
  312. showList(content);
  313. }
  314. else
  315. {
  316. ShowDialog(storyDialogCfg);
  317. }
  318. }
  319. private void showList(string content)
  320. {
  321. StopAutoPlay();
  322. _ui.m_btnAutoPlay.enabled = false;
  323. _wordTextField = null;
  324. _ui.m_dialogText.target.visible = false;
  325. _ui.m_dialogName.target.visible = false;
  326. _ui.m_dialogHead.target.visible = false;
  327. _ui.m_list.visible = true;
  328. _ui.m_list.RemoveChildrenToPool();
  329. string[] list = Regex.Split(content, "//");
  330. _ui.m_list.itemRenderer = (int index, GObject item) =>
  331. {
  332. string itemInfo = list[index];
  333. string[] itemInfoList = Regex.Split(itemInfo, "=");
  334. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  335. dialogItem.m_txtContent.text = itemInfoList[0];
  336. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  337. UI_ListDialogItem.ProxyEnd();
  338. };
  339. _ui.m_list.numItems = list.Length;
  340. }
  341. private void ShowDialog(StoryDialogCfg storyDialogCfg)
  342. {
  343. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  344. {
  345. if (_autoPlay)
  346. {
  347. _ui.m_btnAutoPlay.selected = false;
  348. OnClickBtnAutoPlay();
  349. }
  350. GameController.ShowCreateRole();
  351. }
  352. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  353. _ui.m_btnAutoPlay.enabled = true;
  354. _ui.m_list.visible = false;
  355. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  356. string words = content;
  357. string roleName = storyDialogCfg.name;
  358. string headRes = storyDialogCfg.head;
  359. string headAniRes = storyDialogCfg.headAni;
  360. if (roleName == "self")
  361. {
  362. roleName = RoleDataManager.roleName;
  363. }
  364. //回顾
  365. if (roleName != null)
  366. {
  367. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  368. }
  369. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  370. {
  371. //显示对话框半身像
  372. _ui.m_dialogText.target.visible = false;
  373. _ui.m_dialogName.target.visible = false;
  374. _ui.m_dialogHead.target.visible = true;
  375. _ui.m_dialogHead.m_txtName.text = roleName;
  376. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  377. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  378. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  379. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  380. {
  381. //独立动画
  382. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  383. _ui.m_dialogHead.m_comphead.target.visible = true;
  384. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  385. }
  386. else
  387. {
  388. //换装
  389. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  390. _ui.m_dialogHead.m_comphead.target.visible = false;
  391. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  392. if (storyDialogCfg.suitId > 0)
  393. {
  394. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  395. }
  396. else
  397. {
  398. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData);
  399. if (_dressUpObjUI.dressUpObj.actionId > 0)
  400. {
  401. _dressUpObjUI.dressUpObj.CancelAction(true);
  402. }
  403. _dressUpObjUI.dressUpObj.PutOnDressUpData(_dressUpObjUI.dressUpObj.DressUpDataClone(), new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  404. }
  405. if (headAniCfg != null && headAniCfg.faceId > 0)
  406. {
  407. //表情
  408. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, false);
  409. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  410. }
  411. }
  412. _wordTextField = _ui.m_dialogHead.m_txtContent;
  413. _arrow = _ui.m_dialogHead.m_iconNext;
  414. lastTextFieldType = "head";
  415. }
  416. else if (!string.IsNullOrEmpty(headRes))
  417. {
  418. _ui.m_dialogText.target.visible = false;
  419. _ui.m_dialogName.target.visible = false;
  420. _ui.m_dialogHead.target.visible = true;
  421. _ui.m_dialogHead.m_txtName.text = roleName;
  422. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  423. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  424. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  425. _wordTextField = _ui.m_dialogHead.m_txtContent;
  426. _arrow = _ui.m_dialogHead.m_iconNext;
  427. lastTextFieldType = "head";
  428. }
  429. else if (!string.IsNullOrEmpty(roleName))
  430. {
  431. _ui.m_dialogText.target.visible = false;
  432. _ui.m_dialogName.target.visible = true;
  433. _ui.m_dialogHead.target.visible = false;
  434. _ui.m_dialogName.m_txtName.text = roleName;
  435. _wordTextField = _ui.m_dialogName.m_txtContent;
  436. _arrow = _ui.m_dialogName.m_iconNext;
  437. if (!lastTextFieldType.Equals("name"))
  438. {
  439. lastTextFieldType = "name";
  440. _ui.m_t0.Play();
  441. // Wait pic's animation finished
  442. if(storyDialogCfg.picRes.Length > 0 && !storyDialogCfg.picRes.Equals("0"))
  443. {
  444. _waitPic = true;
  445. }
  446. }
  447. }
  448. else
  449. {
  450. _ui.m_dialogText.target.visible = true;
  451. _ui.m_dialogName.target.visible = false;
  452. _ui.m_dialogHead.target.visible = false;
  453. _wordTextField = _ui.m_dialogText.m_txtContent;
  454. _arrow = _ui.m_dialogText.m_iconNext;
  455. lastTextFieldType = "text";
  456. }
  457. _wordList = Regex.Split(words, "&&");
  458. _wordIndex = 0;
  459. ShowNextDialog();
  460. }
  461. private void ShowNextDialog()
  462. {
  463. if (_wordList != null && _wordList.Length > _wordIndex)
  464. {
  465. string itemInfo = _wordList[_wordIndex];
  466. string[] itemInfoList = Regex.Split(itemInfo, "=");
  467. _currentWords = itemInfoList[0];
  468. if (itemInfoList.Length > 1)
  469. {
  470. _wordTextField.data = itemInfoList[1];
  471. }
  472. else
  473. {
  474. _wordTextField.data = null;
  475. }
  476. Timers.inst.StartCoroutine(StartShowLetters());
  477. }
  478. else
  479. {
  480. OnStepComplete();
  481. }
  482. }
  483. private void ShowCurrentWords()
  484. {
  485. _arrow.target.visible = true;
  486. Timers.inst.Remove(UpdateLetters);
  487. _wordTextField.text = _currentWords;
  488. _dialogListLookBack.Add(_currentWords);
  489. _isShowLetters = false;
  490. _wordIndex++;
  491. if (_autoPlay)
  492. {
  493. Timers.inst.Add(GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay, 1, ShowNextWords);
  494. }
  495. }
  496. private void ShowNextWords(object param = null)
  497. {
  498. if (_wordTextField != null)
  499. {
  500. if (_isShowLetters)
  501. {
  502. ShowCurrentWords();
  503. }
  504. else
  505. {
  506. string stepID = (string)_wordTextField.data;
  507. if (stepID != null)
  508. {
  509. OnStepComplete(stepID);
  510. }
  511. else
  512. {
  513. ShowNextDialog();
  514. }
  515. }
  516. }
  517. }
  518. private IEnumerator StartShowLetters()
  519. {
  520. _isShowLetters = true;
  521. _arrow.target.visible = false;
  522. _wordTextField.verticalAlign = VertAlignType.Top;
  523. _wordTextField.text = "";
  524. ArrayList letters = StoryUtil.GetLettersList(_currentWords);
  525. if (_waitPic)
  526. {
  527. _waitPic = false;
  528. _canClickBtnNext = false;
  529. yield return new WaitForSeconds(0.5f);
  530. _canClickBtnNext = true;
  531. }
  532. Timers.inst.Add(GameConst.LETTERS_INTERVAL_MAX / _speedAutoPlay, 0, UpdateLetters, letters);
  533. }
  534. private void UpdateLetters(object param)
  535. {
  536. ArrayList letters = (ArrayList)param;
  537. if (letters == null || letters.Count <= 0)
  538. {
  539. ShowCurrentWords();
  540. }
  541. else
  542. {
  543. string letter = (string)letters[0];
  544. letters.RemoveAt(0);
  545. _wordTextField.text = _wordTextField.text + letter;
  546. }
  547. }
  548. private void UpdateBg(string value)
  549. {
  550. if (value.Length > 0)
  551. {
  552. SceneController.UpdateDialogBg(value, _sceneObject);
  553. }
  554. }
  555. private void UpdatePic(string value)
  556. {
  557. if (value.Length > 0)
  558. {
  559. SceneController.UpdateDialogPic(value, _sceneObject);
  560. }
  561. }
  562. private void UpdateMusic(string value)
  563. {
  564. if (value.Length > 0)
  565. {
  566. if (value == "0")
  567. {
  568. MusicManager.Instance.Stop();
  569. }
  570. else
  571. {
  572. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(value, "mp3"));
  573. }
  574. }
  575. }
  576. private void PlayEffect(string[] infos)
  577. {
  578. }
  579. private void PlayShake(int[] shakeInfoArr)
  580. {
  581. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  582. {
  583. Vector3 position = _sceneObject.transform.position;
  584. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  585. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  586. _sceneObject.transform.position = position;
  587. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  588. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  589. float interval = (float)shakeInfoArr[4] / 1000;
  590. float duration = (float)shakeInfoArr[5] / 1000;
  591. int repeat = Mathf.RoundToInt(duration / interval);
  592. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  593. }
  594. }
  595. private void UpdateShake(object param)
  596. {
  597. float[] attenuations = param as float[];
  598. float attenuationX = attenuations[0];
  599. float attenuationY = attenuations[1];
  600. Vector3 position = _sceneObject.transform.position;
  601. bool done = false;
  602. bool doneX = false;
  603. float absX = Mathf.Abs(position.x);
  604. if (absX > attenuationX)
  605. {
  606. int dir = (int)(position.x / absX);
  607. position.x = Mathf.Abs(position.x) - attenuationX;
  608. position.x *= -1 * dir;
  609. }
  610. else
  611. {
  612. doneX = true;
  613. position.x = 0;
  614. }
  615. bool doneY = false;
  616. float absY = Mathf.Abs(position.y);
  617. if (absY > attenuationY)
  618. {
  619. int dir = (int)(position.y / absY);
  620. position.y = Mathf.Abs(position.y) - attenuationY;
  621. position.y *= -1 * dir;
  622. }
  623. else
  624. {
  625. doneY = true;
  626. position.y = 0;
  627. }
  628. done = doneX && doneY;
  629. _sceneObject.transform.position = position;
  630. if (done)
  631. {
  632. Timers.inst.Remove(UpdateShake);
  633. }
  634. }
  635. private void Over(bool isSkip = false)
  636. {
  637. if (_onCompleteStoryDialogCall != null)
  638. {
  639. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  640. }
  641. }
  642. private void UpdateSpeedUpBtn()
  643. {
  644. if (_speedAutoPlay > 1)
  645. {
  646. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  647. }
  648. else
  649. {
  650. _ui.m_btnSpeedUp.text = "";
  651. }
  652. }
  653. private void StopAutoPlay()
  654. {
  655. _autoPlay = false;
  656. _ui.m_btnAutoPlay.selected = false;
  657. Timers.inst.Remove(ShowNextWords);
  658. }
  659. }
  660. }