StoryDialogView.cs 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677
  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_btnAutoPlay.enabled = true;
  339. _ui.m_list.visible = false;
  340. var content = storyDialogCfg.content.Replace("self", RoleDataManager.roleName);
  341. string words = content;
  342. string roleName = storyDialogCfg.name;
  343. string headRes = storyDialogCfg.head;
  344. string headAniRes = storyDialogCfg.headAni;
  345. if (roleName == "self")
  346. {
  347. roleName = RoleDataManager.roleName;
  348. }
  349. //回顾
  350. if (roleName != null)
  351. {
  352. _dialogListLookBack.Add("[color=#FDA2B1]" + roleName + "[/color]");
  353. }
  354. if (!string.IsNullOrEmpty(headAniRes) || storyDialogCfg.suitId > 0)
  355. {
  356. //显示对话框半身像
  357. _ui.m_dialogText.target.visible = false;
  358. _ui.m_dialogName.target.visible = false;
  359. _ui.m_dialogHead.target.visible = true;
  360. _ui.m_dialogHead.m_txtName.text = roleName;
  361. _ui.m_dialogHead.m_comphead.m_head.visible = false;
  362. _ui.m_dialogHead.m_comphead.m_holder.visible = true;
  363. var headAniCfg = HeadAniCfgArray.Instance.GetCfg(headAniRes);
  364. if (headAniCfg != null && !string.IsNullOrEmpty(headAniCfg.headAni))
  365. {
  366. //独立动画
  367. _ui.m_dialogHead.m_compDressUp.target.visible = false;
  368. _ui.m_dialogHead.m_comphead.target.visible = true;
  369. string resPath = ResPathUtil.GetViewEffectPath("ui_nzbq", headAniCfg.headAni);
  370. SceneController.AddObjectToView(null, _npcWrapper, _ui.m_dialogHead.m_comphead.m_holder, resPath, out _npcHead, out _npcWrapper);
  371. }
  372. else
  373. {
  374. //换装
  375. _ui.m_dialogHead.m_compDressUp.target.visible = true;
  376. _ui.m_dialogHead.m_comphead.target.visible = false;
  377. _dressUpObjUI.ResetSceneObj(80, true, false, null, false);
  378. if (storyDialogCfg.suitId > 0)
  379. {
  380. _dressUpObjUI.dressUpObj.PutOnSuitCfg(storyDialogCfg.suitId, false, new int[] { ConstDressUpItemType.BEI_JING }, false, false);
  381. }
  382. else
  383. {
  384. _dressUpObjUI.dressUpObj.PutOnDressUpData(CustomSuitDataManager.GetCurrentSuitData().dressUpData);
  385. if (_dressUpObjUI.dressUpObj.actionId > 0)
  386. {
  387. _dressUpObjUI.dressUpObj.CancelAction(true);
  388. }
  389. }
  390. if (headAniCfg != null && headAniCfg.faceId > 0)
  391. {
  392. //表情
  393. _dressUpObjUI.dressUpObj.AddOrRemove(headAniCfg.faceId, false);
  394. _dressUpObjUI.UpdateWrapper(_ui.m_dialogHead.m_compDressUp.m_holder);
  395. }
  396. }
  397. _wordTextField = _ui.m_dialogHead.m_txtContent;
  398. _arrow = _ui.m_dialogHead.m_iconNext;
  399. }
  400. else if (!string.IsNullOrEmpty(headRes))
  401. {
  402. _ui.m_dialogText.target.visible = false;
  403. _ui.m_dialogName.target.visible = false;
  404. _ui.m_dialogHead.target.visible = true;
  405. _ui.m_dialogHead.m_txtName.text = roleName;
  406. _ui.m_dialogHead.m_comphead.m_head.visible = true;
  407. _ui.m_dialogHead.m_comphead.m_holder.visible = false;
  408. _ui.m_dialogHead.m_comphead.m_head.url = ResPathUtil.GetNpcHeadPath(headRes);
  409. _wordTextField = _ui.m_dialogHead.m_txtContent;
  410. _arrow = _ui.m_dialogHead.m_iconNext;
  411. }
  412. else if (!string.IsNullOrEmpty(roleName))
  413. {
  414. _ui.m_dialogText.target.visible = false;
  415. _ui.m_dialogName.target.visible = true;
  416. _ui.m_dialogHead.target.visible = false;
  417. _ui.m_dialogName.m_txtName.text = roleName;
  418. _wordTextField = _ui.m_dialogName.m_txtContent;
  419. _arrow = _ui.m_dialogName.m_iconNext;
  420. }
  421. else
  422. {
  423. _ui.m_dialogText.target.visible = true;
  424. _ui.m_dialogName.target.visible = false;
  425. _ui.m_dialogHead.target.visible = false;
  426. _wordTextField = _ui.m_dialogText.m_txtContent;
  427. _arrow = _ui.m_dialogText.m_iconNext;
  428. }
  429. _wordList = Regex.Split(words, "&&");
  430. _wordIndex = 0;
  431. ShowNextDialog();
  432. }
  433. private void ShowNextDialog()
  434. {
  435. if (_wordList != null && _wordList.Length > _wordIndex)
  436. {
  437. string itemInfo = _wordList[_wordIndex];
  438. string[] itemInfoList = Regex.Split(itemInfo, "=");
  439. _currentWords = itemInfoList[0];
  440. if (itemInfoList.Length > 1)
  441. {
  442. _wordTextField.data = itemInfoList[1];
  443. }
  444. else
  445. {
  446. _wordTextField.data = null;
  447. }
  448. StartShowLetters();
  449. }
  450. else
  451. {
  452. OnStepComplete();
  453. }
  454. }
  455. private void ShowCurrentWords()
  456. {
  457. _arrow.target.visible = true;
  458. Timers.inst.Remove(UpdateLetters);
  459. _wordTextField.text = _currentWords;
  460. _dialogListLookBack.Add(_currentWords);
  461. _isShowLetters = false;
  462. _wordIndex++;
  463. if (_autoPlay)
  464. {
  465. Timers.inst.Add(GameConst.NEXT_WORDS_INTERVAL_MAX / _speedAutoPlay, 1, ShowNextWords);
  466. }
  467. }
  468. private void ShowNextWords(object param = null)
  469. {
  470. if (_wordTextField != null)
  471. {
  472. if (_isShowLetters)
  473. {
  474. ShowCurrentWords();
  475. }
  476. else
  477. {
  478. string stepID = (string)_wordTextField.data;
  479. if (stepID != null)
  480. {
  481. OnStepComplete(stepID);
  482. }
  483. else
  484. {
  485. ShowNextDialog();
  486. }
  487. }
  488. }
  489. }
  490. private void StartShowLetters()
  491. {
  492. _isShowLetters = true;
  493. _arrow.target.visible = false;
  494. _wordTextField.verticalAlign = VertAlignType.Top;
  495. _wordTextField.text = "";
  496. ArrayList letters = StoryUtil.GetLettersList(_currentWords);
  497. Timers.inst.Add(GameConst.LETTERS_INTERVAL_MAX / _speedAutoPlay, 0, UpdateLetters, letters);
  498. }
  499. private void UpdateLetters(object param)
  500. {
  501. ArrayList letters = (ArrayList)param;
  502. if (letters == null || letters.Count <= 0)
  503. {
  504. ShowCurrentWords();
  505. }
  506. else
  507. {
  508. string letter = (string)letters[0];
  509. letters.RemoveAt(0);
  510. _wordTextField.text = _wordTextField.text + letter;
  511. }
  512. }
  513. private void UpdateBg(string value)
  514. {
  515. if (value.Length > 0)
  516. {
  517. SceneController.UpdateDialogBg(value, _sceneObject);
  518. }
  519. }
  520. private void UpdatePic(string value)
  521. {
  522. if (value.Length > 0)
  523. {
  524. SceneController.UpdateDialogPic(value, _sceneObject);
  525. }
  526. }
  527. private void UpdateMusic(string value)
  528. {
  529. if (value.Length > 0)
  530. {
  531. if (value == "0")
  532. {
  533. MusicManager.Instance.Stop();
  534. }
  535. else
  536. {
  537. MusicManager.Instance.Play(ResPathUtil.GetMusicPath(value, "mp3"));
  538. }
  539. }
  540. }
  541. private void PlayEffect(string[] infos)
  542. {
  543. }
  544. private void PlayShake(int[] shakeInfoArr)
  545. {
  546. if (shakeInfoArr != null && shakeInfoArr.Length > 0)
  547. {
  548. Vector3 position = _sceneObject.transform.position;
  549. position.x = (float)shakeInfoArr[0] / GameConst.PIXELS_PER_UNITY_UNIT;
  550. position.y = (float)shakeInfoArr[1] / GameConst.PIXELS_PER_UNITY_UNIT;
  551. _sceneObject.transform.position = position;
  552. float attenuationX = (float)shakeInfoArr[2] / GameConst.PIXELS_PER_UNITY_UNIT;
  553. float attenuationY = (float)shakeInfoArr[3] / GameConst.PIXELS_PER_UNITY_UNIT;
  554. float interval = (float)shakeInfoArr[4] / 1000;
  555. float duration = (float)shakeInfoArr[5] / 1000;
  556. int repeat = Mathf.RoundToInt(duration / interval);
  557. Timers.inst.Add(interval, 0, UpdateShake, new float[] { attenuationX, attenuationY });
  558. }
  559. }
  560. private void UpdateShake(object param)
  561. {
  562. float[] attenuations = param as float[];
  563. float attenuationX = attenuations[0];
  564. float attenuationY = attenuations[1];
  565. Vector3 position = _sceneObject.transform.position;
  566. bool done = false;
  567. bool doneX = false;
  568. float absX = Mathf.Abs(position.x);
  569. if (absX > attenuationX)
  570. {
  571. int dir = (int)(position.x / absX);
  572. position.x = Mathf.Abs(position.x) - attenuationX;
  573. position.x *= -1 * dir;
  574. }
  575. else
  576. {
  577. doneX = true;
  578. position.x = 0;
  579. }
  580. bool doneY = false;
  581. float absY = Mathf.Abs(position.y);
  582. if (absY > attenuationY)
  583. {
  584. int dir = (int)(position.y / absY);
  585. position.y = Mathf.Abs(position.y) - attenuationY;
  586. position.y *= -1 * dir;
  587. }
  588. else
  589. {
  590. doneY = true;
  591. position.y = 0;
  592. }
  593. done = doneX && doneY;
  594. _sceneObject.transform.position = position;
  595. if (done)
  596. {
  597. Timers.inst.Remove(UpdateShake);
  598. }
  599. }
  600. private void Over(bool isSkip = false)
  601. {
  602. if (_onCompleteStoryDialogCall != null)
  603. {
  604. _onCompleteStoryDialogCall(isSkip, _onCompleteStoryDialogCallParam);
  605. }
  606. }
  607. private void UpdateSpeedUpBtn()
  608. {
  609. if (_speedAutoPlay > 1)
  610. {
  611. _ui.m_btnSpeedUp.text = "x" + _speedAutoPlay;
  612. }
  613. else
  614. {
  615. _ui.m_btnSpeedUp.text = "";
  616. }
  617. }
  618. private void StopAutoPlay()
  619. {
  620. _autoPlay = false;
  621. _ui.m_btnAutoPlay.selected = false;
  622. Timers.inst.Remove(ShowNextWords);
  623. }
  624. }
  625. }