StoryDialogView.cs 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727
  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. //屏幕效果中
  40. private Action<object> _onScreenEffectComplete;
  41. public override void Dispose()
  42. {
  43. base.Dispose();
  44. if (_sceneObject != null)
  45. {
  46. GameObject.Destroy(_sceneObject);
  47. _sceneObject = null;
  48. }
  49. _dressUpObjUI?.Dispose();
  50. _dressUpObjUI = null;
  51. _wordTextField = null;
  52. _arrow = null;
  53. _isShowLetters = false;
  54. EffectUIPool.Recycle(_effectUI1);
  55. _effectUI1 = null;
  56. _onScreenEffectComplete = null;
  57. Timers.inst.Remove(UpdateLetters);
  58. if (_ui != null)
  59. {
  60. _ui.Dispose();
  61. _ui = null;
  62. }
  63. }
  64. protected override void Init()
  65. {
  66. base.Init();
  67. packageName = UI_StoryDialogUI.PACKAGE_NAME;
  68. _ui = UI_StoryDialogUI.Create();
  69. viewCom = _ui.target;
  70. isfullScreen = true;
  71. _scenePrefab = GFGAsset.Load<GameObject>(ResPathUtil.GetPrefabPath("SceneStoryDialog"));
  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 = GameObject.Instantiate(_scenePrefab);
  97. }
  98. if (_dressUpObjUI == null)
  99. {
  100. _dressUpObjUI = new DressUpObjUI();
  101. }
  102. _speedAutoPlay = FightDataManager.Instance.dialogSpeed;
  103. _autoPlay = false;
  104. lastTextFieldType = "";
  105. UpdateSpeedUpBtn();
  106. _dialogListLookBack = new List<string>();
  107. object[] datas = viewData as object[];
  108. _storyStartID = (string)datas[0];
  109. bool skipable = (bool)datas[1];
  110. _onCompleteStoryDialogCall = (OnCompleteStoryDialogCall)datas[2];
  111. if (datas.Length > 3)
  112. {
  113. _onCompleteStoryDialogCallParam = datas[3];
  114. }
  115. if (LauncherConfig.netType == LauncherConfig.EnumNetType.TEMP && !InstanceZonesDataManager.CheckLevelPass(MainStoryDataManager.currentLevelCfgId))
  116. {
  117. // 临时设置都可以跳过对话
  118. skipable = false;
  119. }
  120. else
  121. {
  122. skipable = true;
  123. }
  124. _ui.m_btnSkip.visible = skipable;
  125. ShowNextStep(_storyStartID);
  126. _ui.m_c1.selectedIndex = 0;
  127. _ui.m_btnAutoPlay.selected = false;
  128. if (_storyStartID == MainStoryDataManager.priorId)
  129. {
  130. _ui.m_c1.selectedIndex = 1;
  131. // _ui.m_btnAutoPlay.selected = true;
  132. OnClickBtnAutoPlay();
  133. _speedAutoPlay = 1;
  134. FightDataManager.Instance.dialogSpeed = _speedAutoPlay;
  135. }
  136. _ui.m_btnBack.visible = InstanceZonesDataManager.CheckLevelPass(100001001);
  137. }
  138. protected override void OnHide()
  139. {
  140. base.OnHide();
  141. Timers.inst.Remove(UpdateLetters);
  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. }
  282. else
  283. {
  284. OnScreenEffectComplete();
  285. }
  286. }
  287. private void OnScreenEffectComplete(object param = null)
  288. {
  289. _onScreenEffectComplete = null;
  290. if (_nextStepId == "0")
  291. {
  292. Over();
  293. }
  294. else
  295. {
  296. ShowNextStep(_nextStepId);
  297. }
  298. }
  299. private IEnumerator InitStepContent(StoryDialogCfg storyDialogCfg)
  300. {
  301. _canClickBtnNext = false;
  302. StoryDialogDataManager.Instance.waitPicFade = false;
  303. HideAllDialogUI();
  304. // Init resource
  305. _currentStepCfg = storyDialogCfg;
  306. UpdateMusic(storyDialogCfg.musicRes);
  307. UpdateBg(storyDialogCfg.bgRes);
  308. UpdatePic(storyDialogCfg.picRes);
  309. PlayEffect(storyDialogCfg.effectInfoArr);
  310. PlayShake(storyDialogCfg.shakeInfoArr);
  311. string content = storyDialogCfg.content;
  312. content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  313. bool delay = StoryDialogDataManager.Instance.waitBgChange;
  314. while (StoryDialogDataManager.Instance.waitBgChange)
  315. {
  316. yield return new WaitForEndOfFrame();
  317. }
  318. if (delay)
  319. {
  320. yield return new WaitForSeconds(0.4f);
  321. }
  322. _canClickBtnNext = true;
  323. if (content.IndexOf("//") >= 0)
  324. {
  325. showList(content);
  326. }
  327. else
  328. {
  329. ShowDialog(storyDialogCfg);
  330. }
  331. }
  332. private void showList(string content)
  333. {
  334. StopAutoPlay();
  335. _ui.m_btnAutoPlay.enabled = false;
  336. _wordTextField = null;
  337. _ui.m_list.visible = true;
  338. _ui.m_list.RemoveChildrenToPool();
  339. string[] list = Regex.Split(content, "//");
  340. _ui.m_list.itemRenderer = (int index, GObject item) =>
  341. {
  342. string itemInfo = list[index];
  343. string[] itemInfoList = Regex.Split(itemInfo, "=");
  344. UI_ListDialogItem dialogItem = UI_ListDialogItem.Proxy(item);
  345. dialogItem.m_txtContent.text = itemInfoList[0];
  346. dialogItem.target.data = itemInfoList.Length > 1 ? itemInfoList[1] : null;
  347. UI_ListDialogItem.ProxyEnd();
  348. };
  349. _ui.m_list.numItems = list.Length;
  350. }
  351. private void HideAllDialogUI()
  352. {
  353. _ui.m_dialogText.target.visible = false;
  354. _ui.m_dialogName.target.visible = false;
  355. _ui.m_dialogHead.target.visible = false;
  356. _ui.m_list.visible = false;
  357. }
  358. private void ShowDialog(StoryDialogCfg storyDialogCfg)
  359. {
  360. if (storyDialogCfg.showChangeName == 1 && StorageDataManager.Instance.GetStorageValue(ConstStorageId.CHANGE_NAME) == 0)
  361. {
  362. if (_autoPlay)
  363. {
  364. _ui.m_btnAutoPlay.selected = false;
  365. OnClickBtnAutoPlay();
  366. }
  367. GameController.ShowCreateRole();
  368. }
  369. _ui.m_loaMask.url = ResPathUtil.GetBgImgPath(storyDialogCfg.maskRes);
  370. _ui.m_btnAutoPlay.enabled = true;
  371. _ui.m_list.visible = false;
  372. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  373. string words = content;
  374. string roleName = storyDialogCfg.name;
  375. string headRes = storyDialogCfg.head;
  376. string headAniRes = storyDialogCfg.headAni;
  377. if (roleName == "self")
  378. {
  379. roleName = RoleDataManager.roleName;
  380. }
  381. //回顾
  382. if (roleName != null)
  383. {
  384. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  385. }
  386. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  387. {
  388. //显示对话框半身像
  389. _ui.m_dialogHead.target.visible = true;
  390. _ui.m_dialogHead.m_txtName.text = roleName;
  391. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  392. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  393. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  394. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  395. {
  396. //独立动画
  397. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  398. _ui.m_dialogHead.m_comphead.target.visible = true;
  399. _effectUI1 = EffectUIPool.CreateEffectUI(_ui.m_dialogHead.m_comphead.m_holder, "ui_nzbq", headAniCfg.headAni);
  400. }
  401. else
  402. {
  403. //换装
  404. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  405. _ui.m_dialogHead.m_comphead.target.visible = false;
  406. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  407. if (storyDialogCfg.suitId > 0)
  408. {
  409. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.SHOU_CHI_WU }, false, false);
  410. }
  411. else
  412. {
  413. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData);
  414. if (_dressUpObjUI.dressUpObj.actionId > 0)
  415. {
  416. _dressUpObjUI.dressUpObj.CancelAction(true);
  417. }
  418. _dressUpObjUI.dressUpObj.PutOnDressUpData(_dressUpObjUI.dressUpObj.DressUpDataClone(), new int[] { ConstDressUpItemType.SHOU_CHI_WU });
  419. }
  420. if (headAniCfg != null && headAniCfg.faceId > 0)
  421. {
  422. //表情
  423. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, false);
  424. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  425. }
  426. }
  427. _wordTextField = _ui.m_dialogHead.m_txtContent;
  428. _arrow = _ui.m_dialogHead.m_iconNext;
  429. lastTextFieldType = "head";
  430. }
  431. else if (!string.IsNullOrEmpty(headRes))
  432. {
  433. _ui.m_dialogHead.target.visible = true;
  434. _ui.m_dialogHead.m_txtName.text = roleName;
  435. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  436. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  437. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  438. _wordTextField = _ui.m_dialogHead.m_txtContent;
  439. _arrow = _ui.m_dialogHead.m_iconNext;
  440. lastTextFieldType = "head";
  441. }
  442. else if (!string.IsNullOrEmpty(roleName))
  443. {
  444. _ui.m_dialogName.target.visible = true;
  445. _ui.m_dialogName.m_txtName.text = roleName;
  446. _wordTextField = _ui.m_dialogName.m_txtContent;
  447. _arrow = _ui.m_dialogName.m_iconNext;
  448. if (!lastTextFieldType.Equals("name"))
  449. {
  450. lastTextFieldType = "name";
  451. _ui.m_t0.Play();
  452. }
  453. }
  454. else
  455. {
  456. _ui.m_dialogText.target.visible = true;
  457. _wordTextField = _ui.m_dialogText.m_txtContent;
  458. _arrow = _ui.m_dialogText.m_iconNext;
  459. lastTextFieldType = "text";
  460. }
  461. _wordList = Regex.Split(words, "&&");
  462. _wordIndex = 0;
  463. ShowNextDialog();
  464. }
  465. private void ShowNextDialog()
  466. {
  467. if (_wordList != null && _wordList.Length > _wordIndex)
  468. {
  469. string itemInfo = _wordList[_wordIndex];
  470. string[] itemInfoList = Regex.Split(itemInfo, "=");
  471. _currentWords = itemInfoList[0];
  472. if (itemInfoList.Length > 1)
  473. {
  474. _wordTextField.data = itemInfoList[1];
  475. }
  476. else
  477. {
  478. _wordTextField.data = null;
  479. }
  480. Timers.inst.StartCoroutine(StartShowLetters());
  481. }
  482. else
  483. {
  484. OnStepComplete();
  485. }
  486. }
  487. private void ShowCurrentWords()
  488. {
  489. _arrow.target.visible = true;
  490. Timers.inst.Remove(UpdateLetters);
  491. _wordTextField.text = _currentWords;
  492. _dialogListLookBack.Add(_currentWords);
  493. _isShowLetters = false;
  494. _wordIndex++;
  495. if (_autoPlay)
  496. {
  497. Timers.inst.Add(GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay, 1, ShowNextWords);
  498. }
  499. }
  500. private void ShowNextWords(object param = null)
  501. {
  502. if (_wordTextField != null)
  503. {
  504. if (_isShowLetters)
  505. {
  506. ShowCurrentWords();
  507. }
  508. else
  509. {
  510. string stepID = (string)_wordTextField.data;
  511. if (stepID != null)
  512. {
  513. OnStepComplete(stepID);
  514. }
  515. else
  516. {
  517. ShowNextDialog();
  518. }
  519. }
  520. }
  521. }
  522. private IEnumerator StartShowLetters()
  523. {
  524. _isShowLetters = true;
  525. _arrow.target.visible = false;
  526. _wordTextField.verticalAlign = VertAlignType.Top;
  527. _wordTextField.text = "";
  528. ArrayList letters = StoryUtil.GetLettersList(_currentWords);
  529. if (StoryDialogDataManager.Instance.waitPicFade)
  530. {
  531. StoryDialogDataManager.Instance.waitPicFade = false;
  532. _canClickBtnNext = false;
  533. yield return new WaitForSeconds(0.4f);
  534. _canClickBtnNext = true;
  535. }
  536. Timers.inst.Add(GameConst.LETTERS_INTERVAL_MAX / _speedAutoPlay, 0, UpdateLetters, letters);
  537. }
  538. private void UpdateLetters(object param)
  539. {
  540. ArrayList letters = (ArrayList)param;
  541. if (letters == null || letters.Count <= 0)
  542. {
  543. ShowCurrentWords();
  544. }
  545. else
  546. {
  547. string letter = (string)letters[0];
  548. letters.RemoveAt(0);
  549. _wordTextField.text = _wordTextField.text + letter;
  550. }
  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. }
  657. private void StopAutoPlay()
  658. {
  659. _autoPlay = false;
  660. _ui.m_btnAutoPlay.selected = false;
  661. Timers.inst.Remove(ShowNextWords);
  662. }
  663. }
  664. }