StoryDialogView.cs 24 KB

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