StoryDialogView.cs 24 KB

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