StoryDialogView.cs 23 KB

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