StoryDialogView.cs 28 KB

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